From 2d6c68b2ed33b73c85d8dcafba437308c7f99b50 Mon Sep 17 00:00:00 2001 From: Laborratte5 Date: Mon, 12 May 2025 18:30:22 +0200 Subject: [PATCH] test: Add simple e2e test runner --- test/run_tests.sh | 30 ++++++++++++++++++++++++++++++ test/simple_return.c0 | 3 +++ test/simple_return.c0.expected | 14 ++++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 test/run_tests.sh create mode 100644 test/simple_return.c0 create mode 100644 test/simple_return.c0.expected 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