positioning wip
This commit is contained in:
@ -3,32 +3,35 @@ require_relative "helper"
|
||||
module Risc
|
||||
module Position
|
||||
# tests that require a boot and test propagation
|
||||
class TestPositionBasic < MiniTest::Test
|
||||
class TestInstructionPosition < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
Position.set(@binary , 0 , Parfait.object_space.get_main)
|
||||
#Position.set(@binary , 0 , Parfait.object_space.get_main)
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
def test_set_instr
|
||||
def test_init
|
||||
assert InstructionPosition.init(@label , nil)
|
||||
end
|
||||
def pest_set_instr
|
||||
pos = Position.set( @label , 8 , @binary)
|
||||
assert_equal InstructionPosition , pos.class
|
||||
end
|
||||
def test_label_set_int
|
||||
def pest_label_set_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , @label.address.value
|
||||
end
|
||||
def test_label_reset_int
|
||||
def pest_label_reset_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
Position.set( @label , 18 , @binary)
|
||||
assert_equal 18 , @label.address.value
|
||||
end
|
||||
def test_ins_propagates
|
||||
def pest_ins_propagates
|
||||
@label.set_next Arm::ArmMachine.b( @label)
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , Position.get(@label.next).at
|
||||
end
|
||||
def test_ins_propagates_again
|
||||
def pest_ins_propagates_again
|
||||
second = Arm::ArmMachine.b( @label)
|
||||
@label.set_next(second)
|
||||
Position.set( @label , 8 , @binary)
|
||||
@ -36,7 +39,7 @@ module Risc
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , Position.get(@label.next).at
|
||||
end
|
||||
def test_label_at
|
||||
def pest_label_at
|
||||
branch = Branch.new("b" , @label)
|
||||
Position.set(@label , 8 , @binary)
|
||||
Position.set(branch , 8 , @binary)
|
||||
@ -44,7 +47,7 @@ module Risc
|
||||
assert_equal InstructionPosition , at_4.class
|
||||
assert_equal Branch , at_4.instruction.class
|
||||
end
|
||||
def test_label_at_reverse
|
||||
def pest_label_at_reverse
|
||||
branch = Branch.new("b" , @label)
|
||||
Position.set(branch , 8 , @binary)
|
||||
Position.set(@label , 8 , @binary)
|
||||
@ -52,7 +55,7 @@ module Risc
|
||||
assert_equal InstructionPosition , at_4.class
|
||||
assert_equal Branch , at_4.instruction.class
|
||||
end
|
||||
def test_reset_false_type
|
||||
def pest_reset_false_type
|
||||
assert_raises {Position.set(@label , 0 , @binary)}
|
||||
end
|
||||
end
|
||||
|
@ -5,44 +5,47 @@ module Risc
|
||||
# tests that do no require a boot and only test basic positioning
|
||||
class TestPositionBasic < MiniTest::Test
|
||||
|
||||
def test_creation_ok
|
||||
def test_init
|
||||
assert_equal ObjectPosition.init(self)
|
||||
end
|
||||
def pest_creation_ok
|
||||
assert ObjectPosition.new(self,0)
|
||||
end
|
||||
def test_creation_fail
|
||||
def pest_creation_fail
|
||||
assert_raises {Position.new("0")}
|
||||
end
|
||||
def test_add
|
||||
def pest_add
|
||||
res = ObjectPosition.new(self,0) + 5
|
||||
assert_equal 5 , res
|
||||
end
|
||||
def test_sub
|
||||
def pest_sub
|
||||
res = ObjectPosition.new(self,0) - 1
|
||||
assert_equal -1 , res
|
||||
end
|
||||
def test_sub_pos
|
||||
def pest_sub_pos
|
||||
res = ObjectPosition.new(self,0) - ObjectPosition.new(self,0)
|
||||
assert_equal 0 , res
|
||||
end
|
||||
def test_set
|
||||
def pest_set
|
||||
pos = Position.set(self , 5)
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
def tet_tos
|
||||
assert_equal "0x10" , Position.set(self).to_s
|
||||
end
|
||||
def test_reset_ok
|
||||
def pest_reset_ok
|
||||
pos = Position.set(self , 5)
|
||||
pos = Position.set(self , 10)
|
||||
assert_equal 10 , pos.at
|
||||
end
|
||||
def test_reset_fail
|
||||
def pest_reset_fail
|
||||
Position.set(self , 5)
|
||||
assert_raises{Position.set(self , 10000)}
|
||||
end
|
||||
def test_raises_set_nil
|
||||
def pest_raises_set_nil
|
||||
assert_raises { Position.set(self,nil)}
|
||||
end
|
||||
def test_at
|
||||
def pest_at
|
||||
pos = Position.set(self , 5)
|
||||
pos = Position.at(5)
|
||||
assert_equal 5 , pos.at
|
||||
@ -50,21 +53,21 @@ module Risc
|
||||
end
|
||||
class TestPositionEvents < MiniTest::Test
|
||||
def setup
|
||||
@position = ObjectPosition.new(self,0)
|
||||
@position = ObjectPosition.new(self)
|
||||
end
|
||||
def test_has_register
|
||||
def pest_has_register
|
||||
assert @position.register_event(:position_changed , self)
|
||||
end
|
||||
def test_can_unregister
|
||||
def pest_can_unregister
|
||||
assert @position.register_event(:position_changed ,self)
|
||||
assert @position.unregister_event(:position_changed ,self)
|
||||
end
|
||||
def test_fires
|
||||
def pest_fires
|
||||
@position.register_event(:position_changed ,self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
assert_equal @position , @trigger
|
||||
end
|
||||
def test_no_fire_after_unregister
|
||||
def pest_no_fire_after_unregister
|
||||
assert @position.register_event(:position_changed ,self)
|
||||
assert @position.unregister_event(:position_changed ,self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
|
@ -5,25 +5,25 @@ module Risc
|
||||
def setup
|
||||
@machine = Risc.machine.boot
|
||||
end
|
||||
def test_cpu_init
|
||||
def pest_cpu_init
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get @machine.cpu_init
|
||||
end
|
||||
def test_cpu_label
|
||||
def pest_cpu_label
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.label )
|
||||
end
|
||||
def test_cpu_first_arm
|
||||
def pest_cpu_first_arm
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.first )
|
||||
end
|
||||
def test_has_arm_pos
|
||||
def pest_has_arm_pos
|
||||
has_positions(:arm)
|
||||
end
|
||||
def test_has_int_pos
|
||||
def pest_has_int_pos
|
||||
has_positions(:interpreter)
|
||||
end
|
||||
def has_positions(platform)
|
||||
@ -33,10 +33,10 @@ module Risc
|
||||
assert Position.get(obj)
|
||||
end
|
||||
end
|
||||
def test_has_arm_meth
|
||||
def pest_has_arm_meth
|
||||
meth_positions(:arm)
|
||||
end
|
||||
def test_has_int_meth
|
||||
def pest_has_int_meth
|
||||
meth_positions(:interpreter)
|
||||
end
|
||||
def meth_positions(platform)
|
||||
|
Reference in New Issue
Block a user