split some tests, create more and especially big move

This commit is contained in:
Torsten Ruger 2014-09-18 17:06:30 +03:00
parent 457b40a7de
commit e0c479f778
5 changed files with 46 additions and 14 deletions

View File

@ -17,9 +17,9 @@ module ArmHelper
def assert_code code , op , should def assert_code code , op , should
assert_equal op , code.opcode assert_equal op , code.opcode
io = StringIO.new io = StringIO.new
code.assemble(io,nil) code.assemble(io)
binary = io.string binary = io.string
assert_equal 4 , binary.length , "code length wrong for #{code.inspect}" assert_equal should.length , binary.length , "code length wrong for #{code.inspect}"
index = 0 index = 0
binary.each_byte do |byte | binary.each_byte do |byte |
assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}" assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}"

30
test/arm/test_add.rb Normal file
View File

@ -0,0 +1,30 @@
require_relative 'arm-helper'
class TestAdd < MiniTest::Test
include ArmHelper
def test_adc
code = @machine.adc :r1, :r3, :r5
assert_code code , :adc , [0x05,0x10,0xa3,0xe0] #e0 a3 10 05
end
def test_add
code = @machine.add :r1 , :r1, :r3
assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03
end
def test_add_const
code = @machine.add :r1 , :r1, 0x22
assert_code code , :add , [0x22,0x10,0x81,0xe2] #e2 81 10 22
end
def test_add_const_shift_lst
code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8)
assert_code code , :add , [0x22,0x14,0x81,0xe2] #e2 81 14 23
end
def test_add_lst
code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8)
assert_code code , :add , [0x23,0x14,0x82,0xe0] #e0 82 14 23
end
def test_big_add
code = @machine.add :r1 , :r1, 0x220
assert_code code , :add , [0x20,0x12,0x81,0xe2] #e2 81 12 20
end
end

View File

@ -1,6 +1,7 @@
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

@ -3,18 +3,6 @@ require_relative 'arm-helper'
class TestLogic < MiniTest::Test class TestLogic < MiniTest::Test
include ArmHelper include ArmHelper
def test_adc
code = @machine.adc :r1, :r3, :r5
assert_code code , :adc , [0x05,0x10,0xa3,0xe0] #e0 a3 10 05
end
def test_add
code = @machine.add :r1 , :r1, :r3
assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03
end
def test_add_lst
code = @machine.add( :r1 , :r2 , :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 def test_and # inst eval doesn't really work with and
code = @machine.and( :r1 , :r2 , :r3) code = @machine.and( :r1 , :r2 , :r3)
assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03 assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03

View File

@ -7,6 +7,19 @@ class TestMoves < MiniTest::Test
code = @machine.mov :r0, 5 code = @machine.mov :r0, 5
assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05 assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05
end end
def test_mov_pc
code = @machine.mov :pc, 6
assert_code code , :mov , [0x06,0xf0,0xa0,0xe3] #e3 a0 f0 06
end
def test_mov_big
code = @machine.mov :r0, 0x222
code.set_position(0)
begin #TODO use compiler to confirm codes here: this is just what passes
assert_code code , :mov , [ 0x02,0x00,0xa0,0xe3 , 0xff,0x04,0x80,0xe2]
rescue Register::LinkException
retry
end
end
def test_mvn def test_mvn
code = @machine.mvn :r1, 5 code = @machine.mvn :r1, 5
assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05 assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05