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-03-28 10:37:17 +02:00
|
|
|
class TestMachineObjects < MiniTest::Test
|
2016-12-30 19:48:14 +01:00
|
|
|
|
|
|
|
def setup
|
2017-01-19 08:02:29 +01:00
|
|
|
@machine = Risc.machine.boot
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
2018-03-27 17:47:39 +02:00
|
|
|
def test_objects
|
2018-06-15 08:18:39 +02:00
|
|
|
objects = @machine.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
|
|
|
|
def test_constant
|
|
|
|
assert @machine.add_constant( Parfait::Integer.new(5) )
|
|
|
|
end
|
2018-05-30 22:49:01 +02:00
|
|
|
def test_address_get
|
|
|
|
assert_equal Parfait::ReturnAddress , @machine.get_address.class
|
|
|
|
end
|
|
|
|
def test_address_is_constant
|
|
|
|
addr = @machine.get_address
|
|
|
|
assert @machine.constants.include?(addr)
|
|
|
|
end
|
|
|
|
def test_address_count
|
|
|
|
addr = @machine.get_address
|
|
|
|
count = 0
|
|
|
|
while(addr)
|
|
|
|
count += 1
|
|
|
|
addr = addr.next_integer
|
|
|
|
end
|
2018-06-02 22:02:59 +02:00
|
|
|
assert_equal 5, count
|
2018-05-30 22:49:01 +02:00
|
|
|
end
|
2018-03-28 10:37:17 +02:00
|
|
|
end
|
2018-06-09 21:13:43 +02:00
|
|
|
class TestMachinePos < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
|
|
|
@machine.translate(:arm)
|
|
|
|
@machine.position_all
|
|
|
|
end
|
|
|
|
def test_positions_set
|
2018-06-15 20:54:21 +02:00
|
|
|
@machine.object_positions.each do |obj , position|
|
2018-06-09 21:13:43 +02:00
|
|
|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-30 12:28:55 +02:00
|
|
|
class TestMachineInit < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
2018-05-16 20:00:14 +02:00
|
|
|
@machine.translate(:arm)
|
2018-04-30 12:28:55 +02:00
|
|
|
@machine.position_all
|
2018-03-28 12:04:25 +02:00
|
|
|
@machine.create_binary
|
2018-03-27 19:47:41 +02:00
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
def test_pos_cpu
|
2018-05-12 17:36:59 +02:00
|
|
|
assert_equal 0 , Position.get(@machine.cpu_init).at
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_cpu_at
|
2018-06-29 20:03:06 +02:00
|
|
|
assert_equal "0x6034" , Position.get(@machine.cpu_init.first).to_s
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_cpu_label
|
2018-06-02 22:02:59 +02:00
|
|
|
assert_equal Position , Position.get(@machine.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
|
|
|
|
bin = Parfait.object_space.get_init.binary
|
2018-05-28 14:09:59 +02:00
|
|
|
assert 0 != bin.get_word(Parfait::BinaryCode.data_length) , "index 0 is 0 #{bin.inspect}"
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
|
|
|
def test_second_binary_first
|
|
|
|
bin = Parfait.object_space.get_init.binary.next
|
|
|
|
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-06-15 20:54:21 +02:00
|
|
|
@machine.object_positions.each do |obj,position|
|
|
|
|
assert position.valid? , "#{position} , #{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
|