Tests for return instructions
This commit is contained in:
parent
a256cf1e01
commit
f7f981dca4
@ -7,6 +7,15 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Most MomInstructionTests test the risc instructions of the mom instruction
|
||||||
|
# quite carefully, ie every instruction, every register.
|
||||||
|
#
|
||||||
|
# This is done with the assert methods in risc_assert
|
||||||
|
#
|
||||||
|
# Most tests go through instructions from top to bottom.
|
||||||
|
# For working code, one can get a list of those instructions by using the all_str as message
|
||||||
|
# Most tests will test for length and give the all_str as message to see where it went wrong
|
||||||
|
# like: assert_equal 8 , all.length , all_str
|
||||||
class MomInstructionTest < MiniTest::Test
|
class MomInstructionTest < MiniTest::Test
|
||||||
include Output
|
include Output
|
||||||
def setup
|
def setup
|
||||||
|
@ -14,9 +14,9 @@ module Mom
|
|||||||
def test_2_slot
|
def test_2_slot
|
||||||
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
|
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
|
||||||
end
|
end
|
||||||
end
|
def test_3_reg
|
||||||
def test_3_reg
|
assert_reg_to_slot risc(3) , :r1 , :r2 , 7
|
||||||
assert_reg_to_slot risc(3) , :r1 , :r2 , 4
|
end
|
||||||
end
|
end
|
||||||
class TestMessageSetupCache < MomInstructionTest
|
class TestMessageSetupCache < MomInstructionTest
|
||||||
include Parfait::MethodHelper
|
include Parfait::MethodHelper
|
||||||
|
15
test/mom/instruction/test_return_jump.rb
Normal file
15
test/mom/instruction/test_return_jump.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Mom
|
||||||
|
class TestReturnJump < MomInstructionTest
|
||||||
|
def instruction
|
||||||
|
ReturnJump.new("source",Label.new("ok" , "return"))
|
||||||
|
end
|
||||||
|
def test_len
|
||||||
|
assert_equal 2 , all.length , all_str
|
||||||
|
end
|
||||||
|
def test_2_branch
|
||||||
|
assert_branch risc(1) ,"return"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
34
test/mom/instruction/test_return_sequence.rb
Normal file
34
test/mom/instruction/test_return_sequence.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Mom
|
||||||
|
class TestReturnSequence < MomInstructionTest
|
||||||
|
def instruction
|
||||||
|
ReturnSequence.new("source")
|
||||||
|
end
|
||||||
|
def test_len
|
||||||
|
assert_equal 8 , all.length , all_str
|
||||||
|
end
|
||||||
|
def test_1_load_return_value
|
||||||
|
assert_slot_to_reg risc(1) ,:r0 , 5 , :r1
|
||||||
|
end
|
||||||
|
def test_2_load_caller
|
||||||
|
assert_slot_to_reg risc(2) ,:r0 , 6 , :r2
|
||||||
|
end
|
||||||
|
def test_3_store_return_in_caller
|
||||||
|
assert_reg_to_slot risc(3) , :r1 , :r2 , 5
|
||||||
|
end
|
||||||
|
def test_4_load_return_address
|
||||||
|
assert_slot_to_reg risc(4) ,:r0 , 4 , :r3
|
||||||
|
end
|
||||||
|
def test_5_get_int_for_address
|
||||||
|
assert_slot_to_reg risc(5) ,:r3 , 2 , :r3
|
||||||
|
end
|
||||||
|
def test_6_swap_messages
|
||||||
|
assert_slot_to_reg risc(6) ,:r0 , 6 , :r0
|
||||||
|
end
|
||||||
|
def test_7_do_return
|
||||||
|
assert_equal Risc::FunctionReturn , risc(7).class
|
||||||
|
assert_equal :r3 , risc(7).register.symbol
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user