streamline arm test names and get guard to pick up right tests

This commit is contained in:
Torsten Ruger 2016-12-14 19:06:32 +02:00
parent 0a0f9154e1
commit b3bf881c49
5 changed files with 52 additions and 50 deletions

View File

@ -7,6 +7,9 @@ guard :minitest do
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' } 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 # with Minitest::Spec
# watch(%r{^spec/(.*)_spec\.rb$}) # watch(%r{^spec/(.*)_spec\.rb$})
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }

View File

@ -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

View File

@ -1,7 +1,6 @@
require_relative "test_stack" require_relative "test_stack"
require_relative "test_control" require_relative "test_control"
require_relative "test_logic" require_relative "test_logic"
require_relative "test_add"
require_relative "test_move" require_relative "test_move"
require_relative "test_memory" require_relative "test_memory"
require_relative "test_compare" require_relative "test_compare"

View File

@ -7,15 +7,20 @@ class TestControl < MiniTest::Test
# 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 # 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) # 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 assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
end end
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here) 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 assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
end end
def test_swi def test_swi
code = @machine.swi 0x05 code = @machine.swi( 0x05 )
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05
end end
def test_swi_neg
assert_raises(RuntimeError) do
assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef]
end
end
end end

View File

@ -51,4 +51,44 @@ class TestLogic < MiniTest::Test
code = @machine.orr :r2 , :r2 , :r3 code = @machine.orr :r2 , :r2 , :r3
assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03 assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03
end 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 end