2018-05-10 19:56:12 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
module Position
|
|
|
|
# tests that require a boot and test propagation
|
|
|
|
class TestPositionBasic < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
Risc.machine.boot
|
|
|
|
@binary = Parfait::BinaryCode.new(1)
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.set(@binary , 0 , Parfait.object_space.get_main)
|
2018-05-10 19:56:12 +02:00
|
|
|
@label = Label.new("hi","ho")
|
|
|
|
end
|
|
|
|
def test_set_instr
|
2018-05-23 20:34:49 +02:00
|
|
|
pos = Position.set( @label , 8 , @binary)
|
2018-05-10 19:56:12 +02:00
|
|
|
assert_equal InstructionPosition , pos.class
|
|
|
|
end
|
|
|
|
def test_ins_propagates
|
|
|
|
@label.set_next Arm::ArmMachine.b( @label)
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.set( @label , 8 , @binary)
|
|
|
|
assert_equal 8 , Position.get(@label.next).at
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_ins_propagates_again
|
|
|
|
second = Arm::ArmMachine.b( @label)
|
|
|
|
@label.set_next(second)
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.set( @label , 8 , @binary)
|
2018-05-24 13:27:53 +02:00
|
|
|
Position.set(second , 12 , @binary)
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.set( @label , 8 , @binary)
|
|
|
|
assert_equal 8 , Position.get(@label.next).at
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-05-17 19:13:33 +02:00
|
|
|
def test_label_at
|
|
|
|
branch = Branch.new("b" , @label)
|
2018-05-24 13:27:53 +02:00
|
|
|
Position.set(@label , 8 , @binary)
|
|
|
|
Position.set(branch , 8 , @binary)
|
|
|
|
at_4 = Position.at(8)
|
2018-05-17 19:13:33 +02:00
|
|
|
assert_equal InstructionPosition , at_4.class
|
|
|
|
assert_equal Branch , at_4.instruction.class
|
|
|
|
end
|
2018-05-24 15:26:56 +02:00
|
|
|
def test_label_at_reverse
|
|
|
|
branch = Branch.new("b" , @label)
|
|
|
|
Position.set(branch , 8 , @binary)
|
|
|
|
Position.set(@label , 8 , @binary)
|
|
|
|
at_4 = Position.at(8)
|
|
|
|
assert_equal InstructionPosition , at_4.class
|
|
|
|
assert_equal Branch , at_4.instruction.class
|
|
|
|
end
|
2018-05-23 20:34:49 +02:00
|
|
|
def test_reset_false_type
|
|
|
|
assert_raises {Position.set(@label , 0 , @binary)}
|
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|