From 6019fb5d797cf8f446b733f12d250c22244c17cc Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 20 Apr 2014 18:59:21 +0300 Subject: [PATCH] minimal test of generating a whole programm (that can be linked and run,yeah) --- test/helper.rb | 1 + test/small_program_test.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/small_program_test.rb diff --git a/test/helper.rb b/test/helper.rb index d1184495..8da54f85 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -29,3 +29,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test')) require 'crystal' +require 'asm/object_writer' diff --git a/test/small_program_test.rb b/test/small_program_test.rb new file mode 100644 index 00000000..cb9aac67 --- /dev/null +++ b/test/small_program_test.rb @@ -0,0 +1,32 @@ +require_relative 'helper' +require "asm/arm/code_generator" + +# try to test that the generation of basic instructions works +# one instruction at a time, reverse testing from objdump --demangle -Sfghxp +# tests are named as per assembler code, ie test_mov testing mov instruction +# adc add and bic eor orr rsb rsc sbc sub mov mvn cmn cmp teq tst b bl bx swi strb + +class TestSmallProg < MiniTest::Test + # need a code generator, for arm + def setup + @generator = Asm::Arm::CodeGenerator.new + end + + def test_generate_small + @generator.instance_eval { + mov r0, 5 #1 + loop_start = label + loop_start.set! + subs r0, r0, 1 #2 + bne loop_start #3 + mov r7, 1 #4 + swi 0 #5 5 instruction x 4 == 20 + } + + writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM) + assembly = @generator.assemble + assert_equal 20 , assembly.length + writer.set_text assembly + writer.save('small_test.o') + end +end