From f7f981dca48e838953e6cffad9ad31b6f9020fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Tue, 17 Sep 2019 13:52:20 +0300 Subject: [PATCH] Tests for return instructions --- test/mom/instruction/helper.rb | 9 ++++++ test/mom/instruction/test_message_setup.rb | 6 ++-- test/mom/instruction/test_return_jump.rb | 15 +++++++++ test/mom/instruction/test_return_sequence.rb | 34 ++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/mom/instruction/test_return_jump.rb create mode 100644 test/mom/instruction/test_return_sequence.rb diff --git a/test/mom/instruction/helper.rb b/test/mom/instruction/helper.rb index c3fb815c..7b5b8b81 100644 --- a/test/mom/instruction/helper.rb +++ b/test/mom/instruction/helper.rb @@ -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 diff --git a/test/mom/instruction/test_message_setup.rb b/test/mom/instruction/test_message_setup.rb index ef709c9d..9f67d3af 100644 --- a/test/mom/instruction/test_message_setup.rb +++ b/test/mom/instruction/test_message_setup.rb @@ -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 diff --git a/test/mom/instruction/test_return_jump.rb b/test/mom/instruction/test_return_jump.rb new file mode 100644 index 00000000..2ac7ef03 --- /dev/null +++ b/test/mom/instruction/test_return_jump.rb @@ -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 diff --git a/test/mom/instruction/test_return_sequence.rb b/test/mom/instruction/test_return_sequence.rb new file mode 100644 index 00000000..0209a954 --- /dev/null +++ b/test/mom/instruction/test_return_sequence.rb @@ -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