compiler/
lib/
scripts/
seed/
sublime/
test/
support/
tests/
command
5.2 KiB
driver
3.3 KiB
package-golden
1.6 KiB
run
3.1 KiB
runner.rad
10.5 KiB
vim/
.gitignore
336 B
.gitsigners
112 B
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
5.4 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
662 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 `//! session-support` appears, the IL check uses the fixture allocator |
| 12 | # package required by session allocation. |
| 13 | # - If `//! returns: N` appears in the file, the test is compiled to |
| 14 | # a binary and executed; the exit code must match N. |
| 15 | # - If `//! rw-data-size: N` appears in the file, the emitted image header's |
| 16 | # rwdata size must match N bytes. |
| 17 | |
| 18 | RUNNER="test/runner.rv64" |
| 19 | TEST_DIR="test/tests" |
| 20 | EMU="${RAD_EMULATOR:-emulator} -stack-size=1024 -run" |
| 21 | EMU_RUN="${RAD_EMULATOR:-emulator} -no-jit -run" |
| 22 | |
| 23 | if [ ! -f "$RUNNER" ]; then |
| 24 | echo "error: runner binary not found: $RUNNER" >&2 |
| 25 | echo "hint: run 'make test' first" >&2 |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | # Disable core dumps for tests. |
| 30 | ulimit -c 0 |
| 31 | |
| 32 | # Collect tests. |
| 33 | if [ $# -eq 0 ]; then |
| 34 | tests=$(find "$TEST_DIR" \( -name '*.rad' -o -name '*.ras' \) | sort) |
| 35 | else |
| 36 | tests="$*" |
| 37 | fi |
| 38 | |
| 39 | if [ -z "$tests" ]; then |
| 40 | echo "error: no tests found" >&2 |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | passed=0 |
| 45 | failed=0 |
| 46 | |
| 47 | for test in $tests; do |
| 48 | case "$test" in |
| 49 | *.rad) base="${test%.rad}" ;; |
| 50 | *.ras) base="${test%.ras}" ;; |
| 51 | *) base="$test" ;; |
| 52 | esac |
| 53 | |
| 54 | ril="${base}.ril" |
| 55 | bin="${base}.rv64" |
| 56 | # IL check: run the runner if a .ril file exists. |
| 57 | if [ -f "$ril" ]; then |
| 58 | if grep -q '^//! session-support$' "$test"; then |
| 59 | echo -n "test $test ... " |
| 60 | if test/package-golden "$test"; then |
| 61 | echo "ok" |
| 62 | passed=$((passed + 1)) |
| 63 | else |
| 64 | echo "FAILED" |
| 65 | failed=$((failed + 1)) |
| 66 | fi |
| 67 | elif $EMU "$RUNNER" -- "$test"; then |
| 68 | passed=$((passed + 1)) |
| 69 | else |
| 70 | failed=$((failed + 1)) |
| 71 | fi |
| 72 | fi |
| 73 | |
| 74 | # Execution check: run the binary if //! returns: is present. |
| 75 | returns=$(grep -m1 '^//! returns:' "$test" | sed 's/^\/\/! returns: *//') |
| 76 | if [ -n "$returns" ]; then |
| 77 | echo -n "test $test ... " |
| 78 | |
| 79 | if [ ! -f "$bin" ]; then |
| 80 | echo "FAILED (binary not found: $bin)" |
| 81 | failed=$((failed + 1)) |
| 82 | continue |
| 83 | fi |
| 84 | |
| 85 | $EMU_RUN "$bin" >/dev/null 2>&1 |
| 86 | ret=$? |
| 87 | |
| 88 | if [ "$ret" -eq "$returns" ]; then |
| 89 | echo "ok" |
| 90 | passed=$((passed + 1)) |
| 91 | else |
| 92 | echo "FAILED (expected: $returns, got: $ret)" |
| 93 | failed=$((failed + 1)) |
| 94 | fi |
| 95 | fi |
| 96 | |
| 97 | rw_data_size=$(grep -m1 '^//! rw-data-size:' "$test" | sed 's/^\/\/! rw-data-size: *//') |
| 98 | if [ -n "$rw_data_size" ]; then |
| 99 | echo -n "test $test rw.data ... " |
| 100 | |
| 101 | if [ ! -f "$bin" ]; then |
| 102 | echo "FAILED (binary not found: $bin)" |
| 103 | failed=$((failed + 1)) |
| 104 | continue |
| 105 | fi |
| 106 | |
| 107 | actual_rw_data_size=$(od -An -tu4 -j16 -N4 "$bin" | tr -d ' ') |
| 108 | |
| 109 | if [ "$actual_rw_data_size" -eq "$rw_data_size" ]; then |
| 110 | echo "ok" |
| 111 | passed=$((passed + 1)) |
| 112 | else |
| 113 | echo "FAILED (expected: $rw_data_size, got: $actual_rw_data_size)" |
| 114 | failed=$((failed + 1)) |
| 115 | fi |
| 116 | fi |
| 117 | done |
| 118 | echo |
| 119 | |
| 120 | if [ "$failed" -eq 0 ]; then |
| 121 | echo "test result: ok. $passed passed; $failed failed" |
| 122 | exit 0 |
| 123 | else |
| 124 | echo "test result: FAILED. $passed passed; $failed failed" |
| 125 | exit 1 |
| 126 | fi |