2016-12-30 11:59:38 +02:00
|
|
|
require_relative "../helper"
|
2016-12-14 13:43:13 +02:00
|
|
|
|
|
|
|
# try to test that the generation of basic instructions works
|
|
|
|
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
|
|
|
# tests are named as per assembler code, ie test_mov testing mov instruction
|
|
|
|
|
2017-01-03 22:37:55 +02:00
|
|
|
module Arm
|
2018-05-11 18:36:45 +03:00
|
|
|
class FakeBin
|
|
|
|
def byte_length
|
|
|
|
4
|
|
|
|
end
|
2018-05-24 21:20:56 +03:00
|
|
|
def is_a?(_)
|
|
|
|
true
|
|
|
|
end
|
2018-05-11 18:36:45 +03:00
|
|
|
end
|
2017-01-03 22:37:55 +02:00
|
|
|
module ArmHelper
|
|
|
|
def setup
|
2019-02-08 23:03:23 +02:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2017-01-03 22:37:55 +02:00
|
|
|
@machine = Arm::ArmMachine
|
2018-05-11 18:36:45 +03:00
|
|
|
@binary = FakeBin.new
|
2018-05-24 21:20:56 +03:00
|
|
|
Risc::Position.clear_positions
|
2018-06-15 22:00:49 +03:00
|
|
|
Risc::Position.create(@binary).set(0)
|
2017-01-03 22:37:55 +02:00
|
|
|
end
|
2016-12-14 13:43:13 +02:00
|
|
|
|
2017-01-03 22:37:55 +02:00
|
|
|
# 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
|
2018-04-03 14:46:07 +03:00
|
|
|
def assert_code( code , op , should )
|
2017-01-03 22:37:55 +02:00
|
|
|
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 |
|
2018-05-31 14:03:25 +03:00
|
|
|
msg = "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)} | "
|
|
|
|
msg += "#{should[index].to_s(2)} != #{byte.to_s(2)}"
|
|
|
|
assert_equal should[index] , byte , msg
|
2017-01-03 22:37:55 +02:00
|
|
|
index += 1
|
|
|
|
end
|
2016-12-14 13:43:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|