Tests for return instructions

This commit is contained in:
Torsten Rüger 2019-09-17 13:52:20 +03:00
parent a256cf1e01
commit f7f981dca4
4 changed files with 61 additions and 3 deletions

View File

@ -7,6 +7,15 @@ module Mom
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
include Output
def setup

View File

@ -14,9 +14,9 @@ module Mom
def test_2_slot
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
end
end
def test_3_reg
assert_reg_to_slot risc(3) , :r1 , :r2 , 4
def test_3_reg
assert_reg_to_slot risc(3) , :r1 , :r2 , 7
end
end
class TestMessageSetupCache < MomInstructionTest
include Parfait::MethodHelper

View 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

View 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