compiler/
kernel/
lib/
scripts/
seed/
sublime/
test/
acceptance/
boot/
bootstrap/
cycles/
dispatch/
loader/
mmio/
modules/
native/
packages/
pages/
runtime/
scheduling/
shared/
slots/
smp/
sync/
termination/
tests/
trap/
run
2.7 KiB
runner.rad
10.3 KiB
vim/
.gitignore
336 B
.gitsigners
112 B
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
10.2 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
551 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 image header's |
| 14 | # rwdata size must match N 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 | # IL check: run the runner if a .ril file exists. |
| 55 | if [ -f "$ril" ]; then |
| 56 | if $EMU "$RUNNER" -- "$test"; then |
| 57 | passed=$((passed + 1)) |
| 58 | else |
| 59 | failed=$((failed + 1)) |
| 60 | fi |
| 61 | fi |
| 62 | |
| 63 | # Execution check: run the binary if //! returns: is present. |
| 64 | returns=$(grep -m1 '^//! returns:' "$test" | sed 's/^\/\/! returns: *//') |
| 65 | if [ -n "$returns" ]; then |
| 66 | echo -n "test $test ... " |
| 67 | |
| 68 | if [ ! -f "$bin" ]; then |
| 69 | echo "FAILED (binary not found: $bin)" |
| 70 | failed=$((failed + 1)) |
| 71 | continue |
| 72 | fi |
| 73 | |
| 74 | $EMU_RUN "$bin" >/dev/null 2>&1 |
| 75 | ret=$? |
| 76 | |
| 77 | if [ "$ret" -eq "$returns" ]; then |
| 78 | echo "ok" |
| 79 | passed=$((passed + 1)) |
| 80 | else |
| 81 | echo "FAILED (expected: $returns, got: $ret)" |
| 82 | failed=$((failed + 1)) |
| 83 | fi |
| 84 | fi |
| 85 | |
| 86 | rw_data_size=$(grep -m1 '^//! rw-data-size:' "$test" | sed 's/^\/\/! rw-data-size: *//') |
| 87 | if [ -n "$rw_data_size" ]; then |
| 88 | echo -n "test $test rw.data ... " |
| 89 | |
| 90 | if [ ! -f "$bin" ]; then |
| 91 | echo "FAILED (binary not found: $bin)" |
| 92 | failed=$((failed + 1)) |
| 93 | continue |
| 94 | fi |
| 95 | |
| 96 | actual_rw_data_size=$(od -An -tu4 -j16 -N4 "$bin" | tr -d ' ') |
| 97 | |
| 98 | if [ "$actual_rw_data_size" -eq "$rw_data_size" ]; then |
| 99 | echo "ok" |
| 100 | passed=$((passed + 1)) |
| 101 | else |
| 102 | echo "FAILED (expected: $rw_data_size, got: $actual_rw_data_size)" |
| 103 | failed=$((failed + 1)) |
| 104 | fi |
| 105 | fi |
| 106 | done |
| 107 | echo |
| 108 | |
| 109 | if [ "$failed" -eq 0 ]; then |
| 110 | echo "test result: ok. $passed passed; $failed failed" |
| 111 | exit 0 |
| 112 | else |
| 113 | echo "test result: FAILED. $passed passed; $failed failed" |
| 114 | exit 1 |
| 115 | fi |