compiler/
lib/
scripts/
seed/
sublime/
test/
tests/
run
2.9 KiB
runner.rad
10.3 KiB
vim/
.gitignore
366 B
.gitsigners
112 B
LICENSE
1.1 KiB
Makefile
3.6 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.2 KiB
std.lib.test
347 B
test/run
raw
| 1 | #!/bin/sh |
| 2 | # Run binary tests. |
| 3 | # Usage: test/run [<test.rad|test.ras>...] |
| 4 | # |
| 5 | # If no arguments are provided, runs all `.rad` and `.ras` tests in |
| 6 | # `test/tests/`. |
| 7 | # |
| 8 | # For each test: |
| 9 | # - If a `.ril` file exists alongside it, the IL output is checked |
| 10 | # against it via the runner binary. |
| 11 | # - If `//! returns: N` appears in the file, the test is compiled to |
| 12 | # a binary and executed; the exit code must match N. |
| 13 | # - If `//! rw-data-size: N` appears in the file, the emitted `.rw.data` |
| 14 | # sidecar size must match N bytes. Missing sidecars count as zero bytes. |
| 15 | |
| 16 | RUNNER="test/runner.rv64" |
| 17 | TEST_DIR="test/tests" |
| 18 | EMU="${RAD_EMULATOR:-emulator} -stack-size=1024 -run" |
| 19 | EMU_RUN="${RAD_EMULATOR:-emulator} -no-jit -run" |
| 20 | |
| 21 | if [ ! -f "$RUNNER" ]; then |
| 22 | echo "error: runner binary not found: $RUNNER" >&2 |
| 23 | echo "hint: run 'make test' first" >&2 |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | # Disable core dumps for tests. |
| 28 | ulimit -c 0 |
| 29 | |
| 30 | # Collect tests. |
| 31 | if [ $# -eq 0 ]; then |
| 32 | tests=$(find "$TEST_DIR" \( -name '*.rad' -o -name '*.ras' \) | sort) |
| 33 | else |
| 34 | tests="$*" |
| 35 | fi |
| 36 | |
| 37 | if [ -z "$tests" ]; then |
| 38 | echo "error: no tests found" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | passed=0 |
| 43 | failed=0 |
| 44 | |
| 45 | for test in $tests; do |
| 46 | case "$test" in |
| 47 | *.rad) base="${test%.rad}" ;; |
| 48 | *.ras) base="${test%.ras}" ;; |
| 49 | *) base="$test" ;; |
| 50 | esac |
| 51 | |
| 52 | ril="${base}.ril" |
| 53 | bin="${base}.rv64" |
| 54 | rw_data="${bin}.rw.data" |
| 55 | |
| 56 | # IL check: run the runner if a .ril file exists. |
| 57 | if [ -f "$ril" ]; then |
| 58 | if $EMU "$RUNNER" -- "$test"; then |
| 59 | passed=$((passed + 1)) |
| 60 | else |
| 61 | failed=$((failed + 1)) |
| 62 | fi |
| 63 | fi |
| 64 | |
| 65 | # Execution check: run the binary if //! returns: is present. |
| 66 | returns=$(grep -m1 '^//! returns:' "$test" | sed 's/^\/\/! returns: *//') |
| 67 | if [ -n "$returns" ]; then |
| 68 | echo -n "test $test ... " |
| 69 | |
| 70 | if [ ! -f "$bin" ]; then |
| 71 | echo "FAILED (binary not found: $bin)" |
| 72 | failed=$((failed + 1)) |
| 73 | continue |
| 74 | fi |
| 75 | |
| 76 | $EMU_RUN "$bin" >/dev/null 2>&1 |
| 77 | ret=$? |
| 78 | |
| 79 | if [ "$ret" -eq "$returns" ]; then |
| 80 | echo "ok" |
| 81 | passed=$((passed + 1)) |
| 82 | else |
| 83 | echo "FAILED (expected: $returns, got: $ret)" |
| 84 | failed=$((failed + 1)) |
| 85 | fi |
| 86 | fi |
| 87 | |
| 88 | rw_data_size=$(grep -m1 '^//! rw-data-size:' "$test" | sed 's/^\/\/! rw-data-size: *//') |
| 89 | if [ -n "$rw_data_size" ]; then |
| 90 | echo -n "test $test rw.data ... " |
| 91 | |
| 92 | if [ ! -f "$bin" ]; then |
| 93 | echo "FAILED (binary not found: $bin)" |
| 94 | failed=$((failed + 1)) |
| 95 | continue |
| 96 | fi |
| 97 | |
| 98 | if [ -f "$rw_data" ]; then |
| 99 | actual_rw_data_size=$(wc -c < "$rw_data" | tr -d ' ') |
| 100 | else |
| 101 | actual_rw_data_size=0 |
| 102 | fi |
| 103 | |
| 104 | if [ "$actual_rw_data_size" -eq "$rw_data_size" ]; then |
| 105 | echo "ok" |
| 106 | passed=$((passed + 1)) |
| 107 | else |
| 108 | echo "FAILED (expected: $rw_data_size, got: $actual_rw_data_size)" |
| 109 | failed=$((failed + 1)) |
| 110 | fi |
| 111 | fi |
| 112 | done |
| 113 | echo |
| 114 | |
| 115 | if [ "$failed" -eq 0 ]; then |
| 116 | echo "test result: ok. $passed passed; $failed failed" |
| 117 | exit 0 |
| 118 | else |
| 119 | echo "test result: FAILED. $passed passed; $failed failed" |
| 120 | exit 1 |
| 121 | fi |