test/run 1.9 KiB raw
1
#!/bin/sh
2
# Run binary tests.
3
# Usage: test/run [<test.rad>...]
4
#
5
# If no arguments are provided, runs all tests in `test/tests/`.
6
#
7
# For each test:
8
#   - If a `.ril` file exists alongside it, the IL output is checked
9
#     against it via the runner binary.
10
#   - If `//! returns: N` appears in the file, the test is compiled to
11
#     a binary and executed; the exit code must match N.
12
13
RUNNER="test/runner.rv64"
14
TEST_DIR="test/tests"
15
EMU="${RAD_EMULATOR:-emulator} -stack-size=1024 -run"
16
EMU_RUN="${RAD_EMULATOR:-emulator} -run"
17
18
if [ ! -f "$RUNNER" ]; then
19
  echo "error: runner binary not found: $RUNNER" >&2
20
  echo "hint: run 'make test' first" >&2
21
  exit 1
22
fi
23
24
# Disable core dumps for tests.
25
ulimit -c 0
26
27
# Collect tests.
28
if [ $# -eq 0 ]; then
29
  tests=$(find "$TEST_DIR" -name '*.rad' | sort)
30
else
31
  tests="$*"
32
fi
33
34
if [ -z "$tests" ]; then
35
  echo "error: no tests found" >&2
36
  exit 1
37
fi
38
39
passed=0
40
failed=0
41
42
for test in $tests; do
43
  ril="${test%.rad}.ril"
44
  bin="${test%.rad}.rv64"
45
46
  # IL check: run the runner if a .ril file exists.
47
  if [ -f "$ril" ]; then
48
    if $EMU "$RUNNER" -- "$test"; then
49
      passed=$((passed + 1))
50
    else
51
      failed=$((failed + 1))
52
    fi
53
  fi
54
55
  # Execution check: run the binary if //! returns: is present.
56
  returns=$(grep -m1 '^//! returns:' "$test" | sed 's/^\/\/! returns: *//')
57
  if [ -n "$returns" ]; then
58
    echo -n "test $test ... "
59
60
    if [ ! -f "$bin" ]; then
61
      echo "FAILED (binary not found: $bin)"
62
      failed=$((failed + 1))
63
      continue
64
    fi
65
66
    $EMU_RUN "$bin" >/dev/null 2>&1
67
    ret=$?
68
69
    if [ "$ret" -eq "$returns" ]; then
70
      echo "ok"
71
      passed=$((passed + 1))
72
    else
73
      echo "FAILED (expected: $returns, got: $ret)"
74
      failed=$((failed + 1))
75
    fi
76
  fi
77
done
78
echo
79
80
if [ "$failed" -eq 0 ]; then
81
  echo "test result: ok. $passed passed; $failed failed"
82
  exit 0
83
else
84
  echo "test result: FAILED. $passed passed; $failed failed"
85
  exit 1
86
fi