From 3d497ca62266a017e0d8b3072c226ef63cf977a9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 16 May 2014 17:30:26 +0300 Subject: [PATCH] some tests --- test/arm/test_arm.rb | 33 +-------------------------------- test/arm/test_logic.rb | 6 +++++- test/arm/test_move.rb | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 test/arm/test_move.rb diff --git a/test/arm/test_arm.rb b/test/arm/test_arm.rb index 53e54817..e3520c3a 100644 --- a/test/arm/test_arm.rb +++ b/test/arm/test_arm.rb @@ -1,31 +1,8 @@ require_relative 'helper' -# 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 call bx swi strb - class TestArmAsm < MiniTest::Test - # need Assembler and a block (see those classes) - def setup - @machine = Arm::ArmMachine.new - end + include ArmHelper - # code is what the generator spits out, at least one instruction worth (.first) - # the op code is wat was witten as assembler in the first place and the binary result - # is reversed and in 4 bytes as ruby can only do 31 bits and so we can't test with just one int (?) - def assert_code code , op , should - assert_equal op , code.opcode - io = StringIO.new - code.assemble(io) - binary = io.string - assert_equal 4 , binary.length , "code length wrong for #{code.inspect}" - index = 0 - binary.each_byte do |byte | - assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}" - index += 1 - end - end def test_b # the address is what an assembler calculates (a signed number for the amount of instructions), # ie the relative (to pc) address -8 (pipeline) /4 so save space @@ -101,12 +78,4 @@ class TestArmAsm < MiniTest::Test code = @machine.tst :r1 , right: :r2 assert_code code , :tst , [0x02,0x00,0x11,0xe1] #e1 11 00 02 end - def test_mov - code = @machine.mov :r0, right: 5 - assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05 - end - def test_mvn - code = @machine.mvn :r1, right: 5 - assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05 - end end diff --git a/test/arm/test_logic.rb b/test/arm/test_logic.rb index e65f443c..b6d12763 100644 --- a/test/arm/test_logic.rb +++ b/test/arm/test_logic.rb @@ -1,6 +1,6 @@ require_relative 'helper' -class TestArmAsm < MiniTest::Test +class TestLogic < MiniTest::Test include ArmHelper def test_adc @@ -11,6 +11,10 @@ class TestArmAsm < MiniTest::Test code = @machine.add :r1 , left: :r1, right: :r3 assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03 end + def test_add_lst + code = @machine.add( :r1 , left: :r2 , right: :r3 , shift_lsr: 8) + assert_code code , :add , [0x23,0x14,0x82,0xe0] #e0 82 14 23 + end def test_and # inst eval doesn't really work with and code = @machine.and( :r1 , left: :r2 , right: :r3) assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03 diff --git a/test/arm/test_move.rb b/test/arm/test_move.rb new file mode 100644 index 00000000..8fd9dd77 --- /dev/null +++ b/test/arm/test_move.rb @@ -0,0 +1,14 @@ +require_relative 'helper' + +class TestMoves < MiniTest::Test + include ArmHelper + + def test_mov + code = @machine.mov :r0, right: 5 + assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05 + end + def test_mvn + code = @machine.mvn :r1, right: 5 + assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05 + end +end