folded salama-arm in

This commit is contained in:
Torsten Ruger
2016-12-14 13:43:13 +02:00
parent 56032c9b08
commit 456e9b1ec0
22 changed files with 1372 additions and 9 deletions

46
test/arm/helper.rb Normal file
View File

@@ -0,0 +1,46 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
if ENV['CODECLIMATE_REPO_TOKEN']
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
end
require "minitest/autorun"
require "minitest/unit"
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
require 'salama'
# 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
module ArmHelper
def setup
@machine = Arm::ArmMachine
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
def assert_code code , op , should
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 |
assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}"
index += 1
end
end
end