aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md7
-rwxr-xr-xsrc/tools/xref_selftest.sh22
-rw-r--r--tests/drivers/cli_help_test.py2
-rwxr-xr-xtests/runerr.sh27
4 files changed, 42 insertions, 16 deletions
diff --git a/TODO.md b/TODO.md
index fcb4e88..bba2ff7 100644
--- a/TODO.md
+++ b/TODO.md
@@ -431,9 +431,10 @@ of the open list.
store through a pointer (`*p = ...`), an array written by a callee
(`copy_w`, `memset`) and a global reached only through its `_initial` array
are not counted as writes. the baseline is not yet reviewed by a person;
- the 60 "no writer" globals still need checking against those limits. open:
- a self-test that adds a real write to a copy of src/compiler and runs
- `--compiler-dir`, and deciding whether ci runs it on every job or only
+ the 60 "no writer" globals still need checking against those limits. the self-test also
+ copies src/compiler to a scratch dir, adds a new function writing
+ `namecount`, and checks that `--compiler-dir ... --check` exits 1 naming it;
+ it rejects unknown options and is in cli_help_test.py. open: deciding whether ci runs it on every job or only
when `src/compiler/` changes.
### decisions
diff --git a/src/tools/xref_selftest.sh b/src/tools/xref_selftest.sh
index 36425e4..e8a888b 100755
--- a/src/tools/xref_selftest.sh
+++ b/src/tools/xref_selftest.sh
@@ -1,11 +1,17 @@
#!/bin/bash
-# self-test of src/tools/xref.sh --check: the checked-in baseline passes (exit 0), and a copy of it
-# with one writer removed from one line fails (exit 1). works in a scratch directory; the tree,
-# tests/xref.baseline and build/xref are not touched.
+# self-test of src/tools/xref.sh --check: the checked-in baseline passes (exit 0); a copy of it
+# with one writer removed from one line fails (exit 1); and a scratch copy of src/compiler with one
+# new write to a global (namecount) fails and names that global. works in a scratch directory; the
+# tree, src/compiler, tests/xref.baseline and build/xref are not touched.
# usage: src/tools/xref_selftest.sh [SERVER] (default build/bin/zclsp)
set -u
cd "$(dirname "$0")/../.."
-case "${1:-}" in -h|--help) echo "usage: src/tools/xref_selftest.sh [SERVER]"; exit 0;; esac
+usage="usage: src/tools/xref_selftest.sh [SERVER] (default build/bin/zclsp)"
+case "${1:-}" in
+ -h|--help) echo "$usage"; exit 0;;
+ -*) echo "xref_selftest: unknown option $1; $usage" >&2; exit 2;;
+esac
+[ $# -le 1 ] || { echo "xref_selftest: too many arguments; $usage" >&2; exit 2; }
server=${1:-build/bin/zclsp}
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
fail=0
@@ -18,4 +24,12 @@ sed "${line}s/ [^ ]*\$//" tests/xref.baseline > "$tmp/baseline"
bash src/tools/xref.sh --server "$server" --out "$tmp/out" --baseline "$tmp/baseline" --check > "$tmp/bad.log" 2>&1; r=$?
if [ $r = 1 ] && grep -q 'is now written by' "$tmp/bad.log"; then echo "ok xref --check fails when the baseline misses a writer"
else echo "FAIL xref --check with a writer removed from the baseline: exit $r (want 1)"; cat "$tmp/bad.log"; fail=1; fi
+# a real new write in a copy of the compiler: a new function that assigns namecount
+g=namecount
+mkdir "$tmp/compiler"; cp src/compiler/* "$tmp/compiler/"
+last=$(tr -d '\r' < "$tmp/compiler/parts" | tail -1)
+printf '\nint xref_selftest_probe() { %s = %s + 1; return 0; }\n' "$g" "$g" >> "$tmp/compiler/$last"
+bash src/tools/xref.sh --server "$server" --out "$tmp/out" --compiler-dir "$tmp/compiler" --check > "$tmp/src.log" 2>&1; r=$?
+if [ $r = 1 ] && grep -q "^ $g is now written by xref_selftest_probe" "$tmp/src.log"; then echo "ok xref --check fails and names $g when a copy of the compiler writes it in a new function"
+else echo "FAIL xref --check with a new write to $g in a copy of the compiler: exit $r (want 1 naming $g)"; cat "$tmp/src.log"; fail=1; fi
exit $fail
diff --git a/tests/drivers/cli_help_test.py b/tests/drivers/cli_help_test.py
index af3df2e..481d9c0 100644
--- a/tests/drivers/cli_help_test.py
+++ b/tests/drivers/cli_help_test.py
@@ -14,7 +14,7 @@ commands = []
if args.group in ('binaries', 'all'):
commands += [[str(Path(args.bin_dir) / name)] for name in ['zy', 'zym', 'zclsp', 'zc0', 'mkgenome', 'genmap']]
if args.group in ('scripts', 'all'):
- commands += [['bash', name] for name in ['tinyvm.sh', 'src/tools/zcc', 'src/tools/automap.sh', 'src/tools/findcc.sh', 'src/tools/bootstrap-check.sh', 'src/tools/parity.sh', 'src/tools/xref.sh', 'src/tools/mklsp.sh', 'src/tools/mklspwasm.sh', 'src/tools/mkvsix.sh', 'src/web/build.sh', 'src/baremetal/run.sh']]
+ commands += [['bash', name] for name in ['tinyvm.sh', 'src/tools/zcc', 'src/tools/automap.sh', 'src/tools/findcc.sh', 'src/tools/bootstrap-check.sh', 'src/tools/parity.sh', 'src/tools/xref.sh', 'src/tools/xref_selftest.sh', 'src/tools/mklsp.sh', 'src/tools/mklspwasm.sh', 'src/tools/mkvsix.sh', 'src/web/build.sh', 'src/baremetal/run.sh']]
if args.group in ('js', 'all'):
commands += [['node', name] for name in [str(Path(args.js_dir) / 'tinyvm.js'), 'src/js/mklayout.js', 'src/js/extract_lsp.js']]
diff --git a/tests/runerr.sh b/tests/runerr.sh
index f7e668c..b3767ae 100755
--- a/tests/runerr.sh
+++ b/tests/runerr.sh
@@ -1,10 +1,21 @@
#!/bin/bash
-# runs every .zc in a folder (tests/errors by default) and checks the compiler
-# rejects it with the message on its first `// expect: ...` line
-vm=${1:-zy}; dir=${2:-$(dirname "$0")/errors}; pass=0; fail=0
-for f in "$dir"/*.zc; do
- want=$(grep -m1 '^// expect: ' "$f" | sed 's#^// expect: ##')
- got=$($vm < "$f" 2>&1 | head -1)
- if [[ "$got" == *"$want"* ]]; then pass=$((pass+1)); else fail=$((fail+1)); echo "FAIL $(basename $f): got [$got]"; fi
+# runs every .zc in one or more folders (tests/errors by default) and checks the
+# compiler rejects it with the message on its first `// expect: ...` line.
+# usage: tests/runerr.sh [VM] [DIR...]. with several folders each gets its own line
+# and the last line is the total; exits 1 when any file fails.
+vm=${1:-zy}; shift
+[ $# -gt 0 ] || set -- "$(dirname "$0")/errors"
+tpass=0; tfail=0
+for dir in "$@"; do
+ pass=0; fail=0
+ if [ ! -d "$dir" ]; then echo "FAIL $dir: no such folder"; tfail=$((tfail+1)); continue; fi
+ for f in "$dir"/*.zc; do
+ want=$(grep -m1 '^// expect: ' "$f" | sed 's#^// expect: ##')
+ got=$($vm < "$f" 2>&1 | head -1)
+ if [[ "$got" == *"$want"* ]]; then pass=$((pass+1)); else fail=$((fail+1)); echo "FAIL $(basename $f): got [$got]"; fi
+ done
+ [ $# -gt 1 ] && echo "rejected in $dir: $pass passed, $fail failed"
+ tpass=$((tpass+pass)); tfail=$((tfail+fail))
done
-echo "rejected: $pass passed, $fail failed"
+echo "rejected: $tpass passed, $tfail failed"
+[ $tfail = 0 ]