From b3bf881c4911d785d95947fd38062c993588ff41 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 14 Dec 2016 19:06:32 +0200 Subject: [PATCH] streamline arm test names and get guard to pick up right tests --- Guardfile | 3 ++ test/arm/test_add.rb | 45 ---------------------- test/arm/test_all.rb | 1 - test/arm/{test_control.rb => test_call.rb} | 13 +++++-- test/arm/test_logic.rb | 40 +++++++++++++++++++ 5 files changed, 52 insertions(+), 50 deletions(-) delete mode 100644 test/arm/test_add.rb rename test/arm/{test_control.rb => test_call.rb} (65%) diff --git a/Guardfile b/Guardfile index 78a1aa21..1bb86116 100644 --- a/Guardfile +++ b/Guardfile @@ -7,6 +7,9 @@ guard :minitest do watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } watch(%r{^test/test_helper\.rb$}) { 'test' } + #Arm instructions + watch(%r{^lib/arm/instructions/(.+)_instruction.rb}) { |m| "test/arm/test_#{m[1]}.rb" } + # with Minitest::Spec # watch(%r{^spec/(.*)_spec\.rb$}) # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } diff --git a/test/arm/test_add.rb b/test/arm/test_add.rb deleted file mode 100644 index 08bdcc64..00000000 --- a/test/arm/test_add.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative 'helper' - -class TestAdd < MiniTest::Test - include ArmHelper - - 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.new("some" , "Label") - l.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 -end diff --git a/test/arm/test_all.rb b/test/arm/test_all.rb index 8321fda1..31a27379 100644 --- a/test/arm/test_all.rb +++ b/test/arm/test_all.rb @@ -1,7 +1,6 @@ require_relative "test_stack" require_relative "test_control" require_relative "test_logic" -require_relative "test_add" require_relative "test_move" require_relative "test_memory" require_relative "test_compare" diff --git a/test/arm/test_control.rb b/test/arm/test_call.rb similarity index 65% rename from test/arm/test_control.rb rename to test/arm/test_call.rb index ab8472a8..2c14a22e 100644 --- a/test/arm/test_control.rb +++ b/test/arm/test_call.rb @@ -4,18 +4,23 @@ class TestControl < MiniTest::Test include ArmHelper def test_b - # the address is what an assembler calculates (a signed number for the amount of instructions), + # 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 + 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 + 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 + 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 diff --git a/test/arm/test_logic.rb b/test/arm/test_logic.rb index 2a1f9036..981e45ef 100644 --- a/test/arm/test_logic.rb +++ b/test/arm/test_logic.rb @@ -51,4 +51,44 @@ class TestLogic < MiniTest::Test 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.new("some" , "Label") + l.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 + end