From da58ce30e35ca40ffb8c51465d691ba2d678777e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 3 Jan 2017 22:37:55 +0200 Subject: [PATCH] put arm tests in arm module --- test/arm/helper.rb | 34 ++++---- test/arm/test_call.rb | 42 +++++----- test/arm/test_compare.rb | 52 ++++++------ test/arm/test_logic.rb | 176 ++++++++++++++++++++------------------- test/arm/test_memory.rb | 132 ++++++++++++++--------------- test/arm/test_move.rb | 110 ++++++++++++------------ test/arm/test_stack.rb | 54 ++++++------ 7 files changed, 307 insertions(+), 293 deletions(-) diff --git a/test/arm/helper.rb b/test/arm/helper.rb index 1a5d9551..4fca2099 100644 --- a/test/arm/helper.rb +++ b/test/arm/helper.rb @@ -4,23 +4,25 @@ require_relative "../helper" # one instruction at a time, reverse testing from objdump --demangle -Sfghxp # tests are named as per assembler code, ie test_mov testing mov instruction -module ArmHelper - def setup - @machine = Arm::ArmMachine - end +module Arm + module ArmHelper + def setup + @machine = Arm::ArmMachine + end - # 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 - def assert_code code , op , should - assert_equal op , code.opcode - io = StringIO.new - code.assemble(io) - binary = io.string - assert_equal should.length , 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 + # 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 + def assert_code code , op , should + assert_equal op , code.opcode + io = StringIO.new + code.assemble(io) + binary = io.string + assert_equal should.length , 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 end end diff --git a/test/arm/test_call.rb b/test/arm/test_call.rb index 2c14a22e..1136407c 100644 --- a/test/arm/test_call.rb +++ b/test/arm/test_call.rb @@ -1,26 +1,28 @@ require_relative 'helper' -class TestControl < MiniTest::Test - include ArmHelper +module Arm + class TestControl < MiniTest::Test + include ArmHelper - 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 - # so the cpu adds the value*4 and starts loading that (load, decode, execute) - code = @machine.b( -4 ) #this jumps to the next instruction - assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe - end - def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here) - code = @machine.call( -4 ,{} )#this jumps to the next instruction - assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe - end - def test_swi - code = @machine.swi( 0x05 ) - assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 - end - def test_swi_neg - assert_raises(RuntimeError) do - assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef] + 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 + # so the cpu adds the value*4 and starts loading that (load, decode, execute) + code = @machine.b( -4 ) #this jumps to the next instruction + assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe + end + def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here) + code = @machine.call( -4 ,{} )#this jumps to the next instruction + assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe + end + def test_swi + code = @machine.swi( 0x05 ) + assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 + end + def test_swi_neg + assert_raises(RuntimeError) do + assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef] + end end end end diff --git a/test/arm/test_compare.rb b/test/arm/test_compare.rb index 09a51f73..221dd9b0 100644 --- a/test/arm/test_compare.rb +++ b/test/arm/test_compare.rb @@ -1,30 +1,32 @@ require_relative 'helper' -class TestArmAsm < MiniTest::Test - include ArmHelper +module Arm + class TestArmAsm < MiniTest::Test + include ArmHelper - def test_cmn - code = @machine.cmn :r1 , :r2 - assert_code code , :cmn , [0x02,0x00,0x71,0xe1] #e1 71 00 02 - end - def test_cmp - code = @machine.cmp :r1 , :r2 - assert_code code , :cmp , [0x02,0x00,0x51,0xe1] #e1 51 00 02 - end - def test_teq - code = @machine.teq :r1 , :r2 - assert_code code , :teq , [0x02,0x00,0x31,0xe1] #e1 31 00 02 - end - def test_tst - code = @machine.tst :r1 , :r2 - assert_code code , :tst , [0x02,0x00,0x11,0xe1] #e1 11 00 02 - end - def test_tst2 - code = @machine.tst :r1 , :r1 - assert_code code , :tst , [0x01,0x00,0x11,0xe1] #e1 11 00 01 - end - def test_tst3 - code = @machine.tst :r2 , :r2 - assert_code code , :tst , [0x02,0x00,0x12,0xe1] #e1 12 00 02 + def test_cmn + code = @machine.cmn :r1 , :r2 + assert_code code , :cmn , [0x02,0x00,0x71,0xe1] #e1 71 00 02 + end + def test_cmp + code = @machine.cmp :r1 , :r2 + assert_code code , :cmp , [0x02,0x00,0x51,0xe1] #e1 51 00 02 + end + def test_teq + code = @machine.teq :r1 , :r2 + assert_code code , :teq , [0x02,0x00,0x31,0xe1] #e1 31 00 02 + end + def test_tst + code = @machine.tst :r1 , :r2 + assert_code code , :tst , [0x02,0x00,0x11,0xe1] #e1 11 00 02 + end + def test_tst2 + code = @machine.tst :r1 , :r1 + assert_code code , :tst , [0x01,0x00,0x11,0xe1] #e1 11 00 01 + end + def test_tst3 + code = @machine.tst :r2 , :r2 + assert_code code , :tst , [0x02,0x00,0x12,0xe1] #e1 12 00 02 + end end end diff --git a/test/arm/test_logic.rb b/test/arm/test_logic.rb index 8b49ccc2..acdefce3 100644 --- a/test/arm/test_logic.rb +++ b/test/arm/test_logic.rb @@ -1,94 +1,96 @@ require_relative 'helper' -class TestLogic < MiniTest::Test - include ArmHelper +module Arm + class TestLogic < MiniTest::Test + include ArmHelper - def test_mul1 - code = @machine.mul( :r0 , :r1 , :r2) - assert_code code , :mul , [0x91,0x02,0x10,0xe0] #e0 10 02 91 - end - def test_mul2 - code = @machine.mul( :r1 , :r2 , :r3) - assert_code code , :mul , [0x92,0x03,0x11,0xe0] #e0 11 03 92 - end - def test_mul3 - code = @machine.mul( :r2 , :r3 , :r4) - assert_code code , :mul , [0x93,0x04,0x12,0xe0] #e0 12 04 93 - end - def test_and - code = @machine.and( :r1 , :r2 , :r3) - assert_code code , :and , [0x03,0x10,0x12,0xe0] #e0 12 10 03 - end - def test_bic - code = @machine.bic :r2 , :r2 , :r3 - assert_code code , :bic , [0x03,0x20,0xd2,0xe1] #e3 d2 20 44 - end - def test_eor - code = @machine.eor :r2 , :r2 , :r3 - assert_code code , :eor , [0x03,0x20,0x32,0xe0] #e0 32 20 03 - end - def test_rsb - code = @machine.rsb :r1 , :r2 , :r3 - assert_code code , :rsb , [0x03,0x10,0x72,0xe0]#e0 72 10 03 - end - def test_rsc - code = @machine.rsc :r2 , :r3 , :r4 - assert_code code , :rsc , [0x04,0x20,0xf3,0xe0]#e0 f3 20 04 - end - def test_sbc - code = @machine.sbc :r3, :r4 , :r5 - assert_code code , :sbc , [0x05,0x30,0xd4,0xe0]#e0 d4 30 05 - end - def test_sub - code = @machine.sub :r2, :r0, 1 - assert_code code, :sub , [0x01,0x20,0x50,0xe2] #e2 50 20 01 - end - def test_subs - code = @machine.sub :r2, :r2, 1 , update_status: 1 - assert_code code, :sub , [0x01,0x20,0x52,0xe2] #e2 52 20 01 - end - def test_orr - code = @machine.orr :r2 , :r2 , :r3 - assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03 - end - def test_adc - code = @machine.adc :r1, :r3, :r5 - assert_code code , :adc , [0x05,0x10,0xb3,0xe0] #e0 b3 10 05 - end - def test_add - code = @machine.add :r1 , :r1, :r3 - assert_code code , :add , [0x03,0x10,0x91,0xe0] #e0 91 10 03 - end - def test_add_const - code = @machine.add :r1 , :r1, 0x22 - assert_code code , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22 - end - def test_add_const_pc - code = @machine.add :r1 , :pc, 0x22 - assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 - end - def test_add_const_shift - code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8) - assert_code code , :add , [0x22,0x14,0x91,0xe2] #e2 91 14 23 - end - def test_add_lst - code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8) - assert_code code , :add , [0x23,0x14,0x92,0xe0] #e0 92 14 23 - end - def test_big_add - code = @machine.add :r1 , :r1, 0x220 - assert_code code , :add , [0x22,0x1e,0x91,0xe2] #e2 91 1e 22 - end + def test_mul1 + code = @machine.mul( :r0 , :r1 , :r2) + assert_code code , :mul , [0x91,0x02,0x10,0xe0] #e0 10 02 91 + end + def test_mul2 + code = @machine.mul( :r1 , :r2 , :r3) + assert_code code , :mul , [0x92,0x03,0x11,0xe0] #e0 11 03 92 + end + def test_mul3 + code = @machine.mul( :r2 , :r3 , :r4) + assert_code code , :mul , [0x93,0x04,0x12,0xe0] #e0 12 04 93 + end + def test_and + code = @machine.and( :r1 , :r2 , :r3) + assert_code code , :and , [0x03,0x10,0x12,0xe0] #e0 12 10 03 + end + def test_bic + code = @machine.bic :r2 , :r2 , :r3 + assert_code code , :bic , [0x03,0x20,0xd2,0xe1] #e3 d2 20 44 + end + def test_eor + code = @machine.eor :r2 , :r2 , :r3 + assert_code code , :eor , [0x03,0x20,0x32,0xe0] #e0 32 20 03 + end + def test_rsb + code = @machine.rsb :r1 , :r2 , :r3 + assert_code code , :rsb , [0x03,0x10,0x72,0xe0]#e0 72 10 03 + end + def test_rsc + code = @machine.rsc :r2 , :r3 , :r4 + assert_code code , :rsc , [0x04,0x20,0xf3,0xe0]#e0 f3 20 04 + end + def test_sbc + code = @machine.sbc :r3, :r4 , :r5 + assert_code code , :sbc , [0x05,0x30,0xd4,0xe0]#e0 d4 30 05 + end + def test_sub + code = @machine.sub :r2, :r0, 1 + assert_code code, :sub , [0x01,0x20,0x50,0xe2] #e2 50 20 01 + end + def test_subs + code = @machine.sub :r2, :r2, 1 , update_status: 1 + assert_code code, :sub , [0x01,0x20,0x52,0xe2] #e2 52 20 01 + end + def test_orr + code = @machine.orr :r2 , :r2 , :r3 + assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03 + end + def test_adc + code = @machine.adc :r1, :r3, :r5 + assert_code code , :adc , [0x05,0x10,0xb3,0xe0] #e0 b3 10 05 + end + def test_add + code = @machine.add :r1 , :r1, :r3 + assert_code code , :add , [0x03,0x10,0x91,0xe0] #e0 91 10 03 + end + def test_add_const + code = @machine.add :r1 , :r1, 0x22 + assert_code code , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22 + end + def test_add_const_pc + code = @machine.add :r1 , :pc, 0x22 + assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 + end + def test_add_const_shift + code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8) + assert_code code , :add , [0x22,0x14,0x91,0xe2] #e2 91 14 23 + end + def test_add_lst + code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8) + assert_code code , :add , [0x23,0x14,0x92,0xe0] #e0 92 14 23 + end + def test_big_add + code = @machine.add :r1 , :r1, 0x220 + assert_code code , :add , [0x22,0x1e,0x91,0xe2] #e2 91 1e 22 + end - def label pos = 0x22 - l = Register.label("some" , "Label") - l.set_position pos - l - end + def label pos = 0x22 + l = Register.label("some" , "Label") + l.set_position pos + l + end - def pest_move_object - code = @machine.add( :r1 , label) - assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 - end + def pest_move_object + code = @machine.add( :r1 , label) + assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 + end + end end diff --git a/test/arm/test_memory.rb b/test/arm/test_memory.rb index 1840a684..2145bcdc 100644 --- a/test/arm/test_memory.rb +++ b/test/arm/test_memory.rb @@ -1,74 +1,76 @@ require_relative 'helper' -class TestMemory < MiniTest::Test - include ArmHelper +module Arm + class TestMemory < MiniTest::Test + include ArmHelper - def test_ldr - code = @machine.ldr :r0, :r0 - assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00 - end - def test_ldr_const_offset - code = @machine.ldr :r0, :r0 , 4 - assert_code code, :ldr , [0x04,0x00,0x90,0xe5] #e5 90 00 04 - end - def test_ldr_reg_offset - code = @machine.ldr :r3, :r4 , :r5 - assert_code code, :ldr , [0x05,0x30,0x94,0xe7] #e7 94 30 05 - end - def test_ldr_reg_shift2 - code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 2 - assert_code code, :ldr , [0x05,0x31,0x94,0xe7] #e7 94 31 05 - end - def test_ldr_reg_shift3 - code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 3 - assert_code code, :ldr , [0x85,0x31,0x94,0xe7] #e7 94 31 85 - end - def test_ldrb - code = @machine.ldrb :r0, :r0 - assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00 - end - def test_ldrb_const - code = @machine.ldrb :r0, :r0 , 12 - assert_code code, :ldrb , [0x0c,0x00,0xd0,0xe5] #e5 d0 00 0c - end - def test_ldrb_reg_offset - code = @machine.ldrb :r0, :r1 , :r2 - assert_code code, :ldrb , [0x02,0x00,0xd1,0xe7] #e7 d1 00 02 - end + def test_ldr + code = @machine.ldr :r0, :r0 + assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00 + end + def test_ldr_const_offset + code = @machine.ldr :r0, :r0 , 4 + assert_code code, :ldr , [0x04,0x00,0x90,0xe5] #e5 90 00 04 + end + def test_ldr_reg_offset + code = @machine.ldr :r3, :r4 , :r5 + assert_code code, :ldr , [0x05,0x30,0x94,0xe7] #e7 94 30 05 + end + def test_ldr_reg_shift2 + code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 2 + assert_code code, :ldr , [0x05,0x31,0x94,0xe7] #e7 94 31 05 + end + def test_ldr_reg_shift3 + code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 3 + assert_code code, :ldr , [0x85,0x31,0x94,0xe7] #e7 94 31 85 + end + def test_ldrb + code = @machine.ldrb :r0, :r0 + assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00 + end + def test_ldrb_const + code = @machine.ldrb :r0, :r0 , 12 + assert_code code, :ldrb , [0x0c,0x00,0xd0,0xe5] #e5 d0 00 0c + end + def test_ldrb_reg_offset + code = @machine.ldrb :r0, :r1 , :r2 + assert_code code, :ldrb , [0x02,0x00,0xd1,0xe7] #e7 d1 00 02 + end - def test_str - code = @machine.str :r0, :r1 - assert_code code, :str , [0x00,0x00,0x81,0xe5] #e5 81 00 00 - end - def test_str_const_offset - code = @machine.str :r1, :r2 , 4 - assert_code code, :str , [0x04,0x10,0x82,0xe5] #e5 82 10 04 - end - def test_str_reg_offset - code = @machine.str :r3, :r4 , :r5 - assert_code code, :str , [0x05,0x30,0x84,0xe7] #e7 84 30 05 - end - def test_str_reg_shift - code = @machine.str :r3, :r4 , :r5 , :shift_lsl => 2 - assert_code code, :str , [0x05,0x31,0x84,0xe7] #e7 84 31 05 - end + def test_str + code = @machine.str :r0, :r1 + assert_code code, :str , [0x00,0x00,0x81,0xe5] #e5 81 00 00 + end + def test_str_const_offset + code = @machine.str :r1, :r2 , 4 + assert_code code, :str , [0x04,0x10,0x82,0xe5] #e5 82 10 04 + end + def test_str_reg_offset + code = @machine.str :r3, :r4 , :r5 + assert_code code, :str , [0x05,0x30,0x84,0xe7] #e7 84 30 05 + end + def test_str_reg_shift + code = @machine.str :r3, :r4 , :r5 , :shift_lsl => 2 + assert_code code, :str , [0x05,0x31,0x84,0xe7] #e7 84 31 05 + end - def test_strb_inc #THIS IS BROKEN, but so is gnu as, as it produces same output for ! or not - code = @machine.strb :r0, :r2 , 1 , pre_post_index: 1 # pre_post_index is autoinc (r2 here) - assert_code code, :strb , [0x01,0x00,0xc2,0xe5] #e5 e2 00 01 - end + def test_strb_inc #THIS IS BROKEN, but so is gnu as, as it produces same output for ! or not + code = @machine.strb :r0, :r2 , 1 , pre_post_index: 1 # pre_post_index is autoinc (r2 here) + assert_code code, :strb , [0x01,0x00,0xc2,0xe5] #e5 e2 00 01 + end - def test_strb - code = @machine.strb :r0, :r0 - assert_code code, :strb , [0x00,0x00,0xc0,0xe5] #e5 c0 00 00 - end + def test_strb + code = @machine.strb :r0, :r0 + assert_code code, :strb , [0x00,0x00,0xc0,0xe5] #e5 c0 00 00 + end - def test_strb_const - code = @machine.strb :r1, :r2 , 4 - assert_code code, :strb , [0x04,0x10,0xc2,0xe5] #e5 c2 10 04 - end - def test_strb_reg_offset - code = @machine.strb :r1, :r2 , :r3 - assert_code code, :strb , [0x03,0x10,0xc2,0xe7] #e7 c2 10 03 + def test_strb_const + code = @machine.strb :r1, :r2 , 4 + assert_code code, :strb , [0x04,0x10,0xc2,0xe5] #e5 c2 10 04 + end + def test_strb_reg_offset + code = @machine.strb :r1, :r2 , :r3 + assert_code code, :strb , [0x03,0x10,0xc2,0xe7] #e7 c2 10 03 + end end end diff --git a/test/arm/test_move.rb b/test/arm/test_move.rb index adbbe99a..47f95c0a 100644 --- a/test/arm/test_move.rb +++ b/test/arm/test_move.rb @@ -1,62 +1,64 @@ require_relative 'helper' -class TestMoves < MiniTest::Test - include ArmHelper +module Arm + class TestMoves < MiniTest::Test + include ArmHelper - def test_mov - code = @machine.mov :r1, 5 - assert_code code , :mov , [0x05,0x10,0xb0,0xe3] #e3 b0 10 05 - end - def test_mov_pc - code = @machine.mov :pc, 5 - assert_code code , :mov , [0x05,0xf0,0xb0,0xe3] #e3 b0 f0 06 - end - def test_mov_max_128 - code = @machine.mov :r1, 128 - assert_code code , :mov , [0x80,0x10,0xb0,0xe3] #e3 b0 10 80 - end - def test_mov_256 - code = @machine.mov :r1, 256 - assert_code code , :mov , [0x01,0x1c,0xb0,0xe3] #e3 b0 1c 01 - end - def test_mov_big - code = @machine.mov :r0, 0x222 # is not 8 bit and can't be rotated by the arm system in one instruction - code.set_position(0) - begin # mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22 - assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3 , 0x22,0x00,0x90,0xe2] - rescue Register::LinkException - retry + def test_mov + code = @machine.mov :r1, 5 + assert_code code , :mov , [0x05,0x10,0xb0,0xe3] #e3 b0 10 05 + end + def test_mov_pc + code = @machine.mov :pc, 5 + assert_code code , :mov , [0x05,0xf0,0xb0,0xe3] #e3 b0 f0 06 + end + def test_mov_max_128 + code = @machine.mov :r1, 128 + assert_code code , :mov , [0x80,0x10,0xb0,0xe3] #e3 b0 10 80 + end + def test_mov_256 + code = @machine.mov :r1, 256 + assert_code code , :mov , [0x01,0x1c,0xb0,0xe3] #e3 b0 1c 01 + end + def test_mov_big + code = @machine.mov :r0, 0x222 # is not 8 bit and can't be rotated by the arm system in one instruction + code.set_position(0) + begin # mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22 + assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3 , 0x22,0x00,0x90,0xe2] + rescue Register::LinkException + retry + end + end + def test_mvn + code = @machine.mvn :r1, 5 + assert_code code , :mvn , [0x05,0x10,0xf0,0xe3] #e3 f0 10 05 end - end - def test_mvn - code = @machine.mvn :r1, 5 - assert_code code , :mvn , [0x05,0x10,0xf0,0xe3] #e3 f0 10 05 - end - def test_shiftr1 - code = @machine.mov :r1, :r2 , :shift_asr => Register::RegisterValue.new(:r3 , :Integer) - assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52 - end - def test_shiftr2 - code = @machine.mov :r2, :r3 , :shift_asr => Register::RegisterValue.new(:r4 , :Integer) - assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53 - end - def test_shiftr3 - code = @machine.mov :r3, :r4 , :shift_asr => Register::RegisterValue.new(:r5 , :Integer) - assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54 - end + def test_shiftr1 + code = @machine.mov :r1, :r2 , :shift_asr => Register::RegisterValue.new(:r3 , :Integer) + assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52 + end + def test_shiftr2 + code = @machine.mov :r2, :r3 , :shift_asr => Register::RegisterValue.new(:r4 , :Integer) + assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53 + end + def test_shiftr3 + code = @machine.mov :r3, :r4 , :shift_asr => Register::RegisterValue.new(:r5 , :Integer) + assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54 + end - def test_shiftl1 - code = @machine.mov :r1, :r2 , :shift_lsr => Register::RegisterValue.new(:r3 , :Integer) - assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32 - end - def test_shiftl2 - code = @machine.mov :r2, :r3 , :shift_lsr => Register::RegisterValue.new(:r4 , :Integer) - assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33 - end - def test_shiftl3 - code = @machine.mov :r3, :r4 , :shift_lsr => Register::RegisterValue.new(:r5 , :Integer) - assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34 - end + def test_shiftl1 + code = @machine.mov :r1, :r2 , :shift_lsr => Register::RegisterValue.new(:r3 , :Integer) + assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32 + end + def test_shiftl2 + code = @machine.mov :r2, :r3 , :shift_lsr => Register::RegisterValue.new(:r4 , :Integer) + assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33 + end + def test_shiftl3 + code = @machine.mov :r3, :r4 , :shift_lsr => Register::RegisterValue.new(:r5 , :Integer) + assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34 + end + end end diff --git a/test/arm/test_stack.rb b/test/arm/test_stack.rb index 515c1a9c..6c1948d9 100644 --- a/test/arm/test_stack.rb +++ b/test/arm/test_stack.rb @@ -1,31 +1,33 @@ require_relative 'helper' -class TestStack < MiniTest::Test - include ArmHelper +module Arm + class TestStack < MiniTest::Test + include ArmHelper + + def test_push + code = @machine.push [:lr] + assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00 + end + def test_push_three + code = @machine.push [:r0,:r1,:lr] + assert_code code , :push , [0x03,0x40,0x2d,0xe9] #e9 2d 40 03 + end + def test_push_no_link + code = @machine.push [:r0,:r1,:r2 ,:r3,:r4,:r5] + assert_code code , :push , [0x3f,0x00,0x2d,0xe9] #e9 2d 00 3f + end + def test_pop + code = @machine.pop [:pc] + assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00 + end + def test_pop_three + code = @machine.pop [:r0,:r1,:pc] + assert_code code , :pop , [0x03,0x80,0xbd,0xe8] #e8 bd 80 03 + end + def test_pop_no_pc + code = @machine.pop [:r0,:r1,:r2 ,:r3,:r4,:r5] + assert_code code , :pop , [0x3f,0x00,0xbd,0xe8] #e8 bd 00 3f + end - def test_push - code = @machine.push [:lr] - assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00 end - def test_push_three - code = @machine.push [:r0,:r1,:lr] - assert_code code , :push , [0x03,0x40,0x2d,0xe9] #e9 2d 40 03 - end - def test_push_no_link - code = @machine.push [:r0,:r1,:r2 ,:r3,:r4,:r5] - assert_code code , :push , [0x3f,0x00,0x2d,0xe9] #e9 2d 00 3f - end - def test_pop - code = @machine.pop [:pc] - assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00 - end - def test_pop_three - code = @machine.pop [:r0,:r1,:pc] - assert_code code , :pop , [0x03,0x80,0xbd,0xe8] #e8 bd 80 03 - end - def test_pop_no_pc - code = @machine.pop [:r0,:r1,:r2 ,:r3,:r4,:r5] - assert_code code , :pop , [0x3f,0x00,0xbd,0xe8] #e8 bd 00 3f - end - end