dried up the test code
This commit is contained in:
parent
36bde218f6
commit
f4315804c1
@ -2,37 +2,37 @@ require_relative 'helper'
|
|||||||
require "asm/arm/code_generator"
|
require "asm/arm/code_generator"
|
||||||
|
|
||||||
# try to test that the generation of basic instructions works
|
# try to test that the generation of basic instructions works
|
||||||
class TestAsm < MiniTest::Test
|
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
||||||
|
# tests are named as per assembler code, ie test_mov testing mov instruction
|
||||||
|
|
||||||
|
class TestArmAsm < MiniTest::Test
|
||||||
|
# need a code generator, for arm
|
||||||
def setup
|
def setup
|
||||||
@generator = Asm::Arm::CodeGenerator.new
|
@generator = Asm::Arm::CodeGenerator.new
|
||||||
end
|
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
|
||||||
|
# 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
|
||||||
|
binary = @generator.assemble
|
||||||
|
assert_equal 4 , binary.length
|
||||||
|
index = 0
|
||||||
|
binary.each_byte do |byte |
|
||||||
|
assert_equal should[index] , byte
|
||||||
|
index += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
def test_mov
|
def test_mov
|
||||||
m = @generator.instance_eval { mov r0, 5 }.first
|
code = @generator.instance_eval { mov r0, 5 }.first
|
||||||
assert_equal :mov , m.opcode
|
assert_code code , :mov , [0x05,0x00,0xa0,0xe3]
|
||||||
assert ! m.affect_status #no s at the end, silly for mov anyway
|
assert ! code.affect_status #no s at the end, silly for mov anyway
|
||||||
binary = @generator.assemble
|
|
||||||
assert_equal 4 , binary.length
|
|
||||||
should = [0x05,0x00,0xa0,0xe3]
|
|
||||||
index = 0
|
|
||||||
binary.each_byte do |byte |
|
|
||||||
assert_equal should[index] , byte
|
|
||||||
index += 1
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_sub
|
def test_sub
|
||||||
m = @generator.instance_eval { subs r2, r0, 1 }.first
|
code = @generator.instance_eval { subs r2, r0, 1 }.first
|
||||||
assert_equal :sub , m.opcode
|
assert_code code, :sub , [0x01,0x20,0x50,0xe2]
|
||||||
assert m.affect_status #the s at the end
|
assert code.affect_status #the s at the end
|
||||||
binary = @generator.assemble
|
|
||||||
assert_equal 4 , binary.length
|
|
||||||
should = [0x01,0x20,0x50,0xe2]
|
|
||||||
index = 0
|
|
||||||
binary.each_byte do |byte |
|
|
||||||
assert_equal should[index] , byte
|
|
||||||
index += 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def saved_other
|
def saved_other
|
||||||
|
Loading…
Reference in New Issue
Block a user