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