diff --git a/test/run_tests.sh b/test/run_tests.sh new file mode 100755 index 0000000..dc22ea3 --- /dev/null +++ b/test/run_tests.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +BASEFOLDER=$(dirname "$PWD") +INPUT_FILES=$(find "$BASEFOLDER" -type f -name "*.c0") + +"$BASEFOLDER"/build.sh +echo "$INPUT_FILES" + +echo +echo TESTING +echo + +for f in $INPUT_FILES; do + out_file=$f.s + expected_file=$f.expected + echo -n Testing "$(basename \""$f")" "$(basename \""$out_file")" + "$BASEFOLDER"/run.sh "$f" "$out_file" &> /dev/null + if test $? -ne 0; then + echo " FAILED " + continue + fi + diff -q "$out_file" "$expected_file" > /dev/null + if test $? -eq 0; then + echo " PASSED" + rm "$out_file" + else + echo " FAILED " + diff "$out_file" "$expected_file" + fi +done diff --git a/test/simple_return.c0 b/test/simple_return.c0 new file mode 100644 index 0000000..01a481a --- /dev/null +++ b/test/simple_return.c0 @@ -0,0 +1,3 @@ +int main () { + return 0; +} \ No newline at end of file diff --git a/test/simple_return.c0.expected b/test/simple_return.c0.expected new file mode 100644 index 0000000..645899c --- /dev/null +++ b/test/simple_return.c0.expected @@ -0,0 +1,14 @@ +.global main +.global _main +.text +main: +call _main +# move the return value into the first argument for the syscall +movq %rax, %rdi +# move the exit syscall number into rax +movq $0x3C, %rax +syscall +_main: +# your generated code here + mov $0,%0 + ret