fix last tests that required faked returns

This commit is contained in:
Torsten 2020-03-28 19:46:07 +02:00
parent a3effe29f6
commit e8111c259b
8 changed files with 53 additions and 92 deletions

View File

@ -256,6 +256,7 @@ module Risc
false
end
# execute the given system call, only putstring and exit really
def execute_Syscall
name = @instruction.name
ret_value = 0
@ -274,8 +275,12 @@ module Risc
true
end
# get the return after system exit. exit_sequence expects the last return to
# be an int and reduces that, so that is returned
# the value is reduced to 8 bits, because that is what linux does
def get_sys_return
val = get_register( std_reg(:syscall_1) ) # syscalls return into syscall_1
val & 0xFF
end
def run_all

View File

@ -2,34 +2,45 @@
Test methods by their output and exit codes (return, since it is the main).
There are only two tests here (plus one, see below), one for interpreter, one for arm.
Both run the same tests. The actual ruby code that is run is in the source dir.
Test methods are generated, one for each source file.
Every test here is tested first as an Interpreter test, and then as binary (arm).
## Files
File names follow [order,name,stdout,exitcode] joined by _ pattern.
Stdout may be left blank, but exit code must be supplied.
## Setup and assert
The order number is some number giving the difficulty of the test, higher is more.
The first digit represents how many external methods the code relies on, the second
is some general indicator, ie recursive is more difficult than not, syscalls more than
normal calls, if or while more than nothing etc.
The setup require the @input variable to hold the code. This is usually renerated with
as_main or similar helper.
## Arm
The @preload may be set to load any of the Macros, so one can actually use methods.
Otherwise the only methods are the ones you code
Obviously the arm tests need an arm platform. This may be defined by ARM_HOST,
eg for simulated ARM_HOST=localhost
The assert_result takes the exit code and std out. It runs both interpreter and arm,
in that order.
Also port and user may be specified with ARM_PORT and ARM_USER , they default to
2222 and pi if left blank.
SSH keys must be set up so no passwords are required (and the users private key may
not be password protected)
### Interpreter
## Developing
The interpreter is for the most part like another platform. Everything up to the
creation of binaries is the same. The Linker object get's passed to the
Interpreter which runs the code to the end, and returns return code and stdout.
Since the Framework always runs all tests, it is a little cumbersome for developing
a single new test. Since all get run and it is slow.
If this passes, arm is run.
To develop the next test, one can edit test_new.rb . Once it runs on the interpreter,
move the changes to a source file and revert test_new changes.
### Arm
Arm is actually only run if:
- you set TEST_ALL (as is done in test/test_all)
- you set TEST_ARM
AND it requires that you have qemu set up correctly. But given all that, it:
- creates a binary from the code (mains.o), which is linked to a.out
- runs the binary
- captures return code and stdout and returns
Obviously Interpreter AND Arm need to return same codes, the one the assert specifies.
## Status
I have moved most of the risc/interpreter code here, which means we now have over 50
binary tests.
Next i will recreate the file based tests in a better way to integrate with the
current style.

View File

@ -18,7 +18,7 @@ module Mains
def test_minus_neg
@preload = "Integer.minus"
run_main_return "5 - 15"
# assert_result( -10 , "")
assert_result( 246 , "")
end
def test_rshift
@preload = "Integer.rs"
@ -28,7 +28,7 @@ module Mains
def test_lshift
@preload = "Integer.ls"
run_main_return "#{2**8} << 3"
# assert_result 2**11 , ""
assert_result 0 , ""
end
def test_div10
@preload = "Integer.div10"

View File

@ -18,7 +18,7 @@ module Mains
def test_while_simple
@input = as_main 'a = true; while( a ); a = false;end;return a'
# assert_result 4 , ""
assert_result 0 , ""
end
end

View File

@ -1,5 +0,0 @@
# Builtin Testing
Basically test builtin methods by their output.
Currently through Interpreter only

View File

@ -1,61 +0,0 @@
require_relative "../helper"
module Risc
module Macro
class IntCmp < Minitest::Test
include Ticker
def setup
@preload = [:le,:ge,:gt,:lt].collect{|op| "Integer.#{op}"}.join(";")
end
def test_smaller_true
run_main_return "4 < 5"
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_smaller_false
run_main_return "6 < 5"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_false_same
run_main_return "5 < 5"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_true
run_main_return "5 > 4"
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_false
run_main_return "5 > 6"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_false_same
run_main_return "5 > 5"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_or_true
run_main_return "4 <= 5"
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_smaller_or_false
run_main_return "6 <= 5"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_or_same
run_main_return "5 <= 5"
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_or_true
run_main_return "5 >= 4"
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_or_false
run_main_return "5 >= 6"
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_or_same
run_main_return "5 >= 5"
assert_equal Parfait::TrueClass , get_message_return.class
end
end
end
end

View File

@ -18,7 +18,7 @@ module Risc
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #25
Transfer, SlotToReg, SlotToReg, Transfer, Syscall, #30
NilClass,] #35
assert_kind_of Parfait::NilClass , get_return
assert_equal 0 , get_return
end
def test_load_false_const
load = main_ticks(1)

View File

@ -43,6 +43,17 @@ module Risc
assert_equal 5 , @interpreter.get_sys_return
end
end
class TestInterpreterRetBig < MiniTest::Test
include Ticker
def setup
@string_input = as_main("return 257")
super
end
def test_return_value
@interpreter.run_all
assert_equal 1 , @interpreter.get_sys_return
end
end
class TestInterpreterTicks < MiniTest::Test
include Ticker
def setup