2018-05-17 19:13:33 +02:00
|
|
|
require_relative "helper"
|
2016-12-30 19:48:14 +01:00
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2018-07-04 07:28:29 +02:00
|
|
|
class TestLinkerObjects < MiniTest::Test
|
2019-09-13 13:07:12 +02:00
|
|
|
include ScopeHelper
|
2016-12-30 19:48:14 +01:00
|
|
|
def setup
|
2019-09-13 13:07:12 +02:00
|
|
|
compiler = compiler_with_main()
|
|
|
|
@linker = compiler.to_target( :arm)
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
2018-03-27 17:47:39 +02:00
|
|
|
def test_objects
|
2018-07-01 20:51:48 +02:00
|
|
|
objects = @linker.object_positions
|
2018-03-27 17:47:39 +02:00
|
|
|
assert_equal Hash , objects.class
|
2018-03-27 18:06:16 +02:00
|
|
|
assert 350 < objects.length
|
2018-03-27 17:47:39 +02:00
|
|
|
end
|
2018-03-31 12:25:59 +02:00
|
|
|
def test_constant_fail
|
|
|
|
assert_raises {@machine.add_constant( 1 )}
|
|
|
|
end
|
2018-03-28 10:37:17 +02:00
|
|
|
end
|
2018-07-04 07:28:29 +02:00
|
|
|
class TestLinkerInit < MiniTest::Test
|
2018-04-30 12:28:55 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
@linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary("class Space;def main;return 1;end;end",:arm)
|
2018-03-27 19:47:41 +02:00
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
def test_pos_cpu
|
2018-07-02 15:19:01 +02:00
|
|
|
assert_equal 0 , Position.get(@linker.cpu_init).at
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_cpu_at
|
2019-09-21 17:50:33 +02:00
|
|
|
assert_equal "0x941c" , Position.get(@linker.cpu_init.first).to_s
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_cpu_label
|
2018-07-02 15:19:01 +02:00
|
|
|
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-05-28 10:45:04 +02:00
|
|
|
def test_first_binary_jump
|
2019-09-15 11:58:43 +02:00
|
|
|
bin = Parfait.object_space.get_method!(:Object,:__init__).binary
|
2019-08-23 18:25:02 +02:00
|
|
|
assert_equal 116 , bin.total_byte_length
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
|
|
|
def test_second_binary_first
|
2019-09-15 11:58:43 +02:00
|
|
|
bin = Parfait.object_space.get_method!(:Object,:__init__).binary
|
2018-05-28 10:45:04 +02:00
|
|
|
assert 0 != bin.get_word(0) , "index 0 is 0 #{bin.inspect}"
|
|
|
|
end
|
2018-06-09 21:13:43 +02:00
|
|
|
def test_positions_set
|
2018-07-02 15:19:01 +02:00
|
|
|
@linker.object_positions.each do |obj,position|
|
2018-07-04 08:18:55 +02:00
|
|
|
assert position.valid? , "#{position} #{position.object.class}, #{obj.object_id.to_s(16)}"
|
2018-06-09 21:13:43 +02:00
|
|
|
end
|
|
|
|
end
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
|
|
|
end
|