diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 22:43:10 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 22:43:10 -0600 |
| commit | 11a018d72c264b3f77834a9cf36e6468e13ea37d (patch) | |
| tree | 1caaeb279f532a58374b0130a685afd51b6560b2 | |
| parent | 5dc0edf1d1eaaa4c1f6558bbdfb895614f4bec34 (diff) | |
| download | ztop-11a018d72c264b3f77834a9cf36e6468e13ea37d.tar.gz | |
leakcheck: compare the heaps of the modes, not gets with frees
Language Environment keeps a few kilobytes of its own heap for the
enclave lifetime, so an absolute get/free match never holds. What does
hold is that ztop allocates nothing: every mode must end with the same
heap, and one that ends larger is the leak.
| -rw-r--r-- | tests/leakcheck.sh | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/tests/leakcheck.sh b/tests/leakcheck.sh index 6192772..49e852c 100644 --- a/tests/leakcheck.sh +++ b/tests/leakcheck.sh @@ -1,16 +1,18 @@ #!/bin/sh # Language Environment sees every heap request the program makes, so its -# storage report is a leak test: run each one-shot mode under RPTSTG(ON), -# RPTOPTS(ON) and HEAPCHK(ON), then read the report back. A get without -# its free, or a created heap without its discard, is a leak. +# storage report can be read as a leak test: run each one-shot mode under +# RPTSTG(ON), RPTOPTS(ON) and HEAPCHK(ON), then compare what the heap +# looked like at the end of each run. ztop allocates nothing itself, so +# every mode has to end with the same heap. A mode that ends with more +# used storage than the others is holding something it should have freed. # -# tests/leakcheck.sh ./ztop run the modes and check each report -# tests/leakcheck.sh --report FILE check one saved report +# tests/leakcheck.sh ./ztop run the modes and compare them +# tests/leakcheck.sh --report FILE describe one saved report # tests/leakcheck.sh --selftest check the checker set -eu count() { - sed -n "s/^$1: *//p" "$2" | { + sed -n "s/^ *$1: *//p" "$2" | { n=0 while read -r v; do n=$((n + v)) @@ -19,25 +21,20 @@ count() { } } -report() { +stats() { log=$1 - if ! grep -q 'Storage Report' "$log"; then - echo "no storage report in $log" + if ! grep -q 'HEAP statistics:' "$log"; then + echo "no heap report in $log" >&2 return 1 fi g=$(count "Successful Get Heap requests" "$log") f=$(count "Successful Free Heap requests" "$log") - c=$(count "Successful Create Heap requests" "$log") - d=$(count "Successful Discard Heap requests" "$log") - if [ "$g" -ne "$f" ] || [ "$c" -ne "$d" ]; then - echo "LEAK: gets $g frees $f, create $c discard $d" - return 1 - fi - echo "heap gets $g frees $f, create $c discard $d" + u=$(count "Total heap storage used (sugg. initial size)" "$log") + echo "gets $g frees $f used $u" } if [ "${1:-}" = "--report" ]; then - report "$2" + stats "$2" exit fi @@ -45,11 +42,17 @@ dir=${HOME}/tmp/ztop/leak if [ "${1:-}" = "--selftest" ]; then mkdir -p "$dir" - printf 'STORAGE Report\nHEAP statistics:\nSuccessful Get Heap requests: 3\nSuccessful Free Heap requests: 3\nSuccessful Create Heap requests: 1\nSuccessful Discard Heap requests: 1\nEnd of Storage Report\n' > "$dir/clean.log" - printf 'STORAGE Report\nHEAP statistics:\nSuccessful Get Heap requests: 5\nSuccessful Free Heap requests: 4\nSuccessful Create Heap requests: 0\nSuccessful Discard Heap requests: 0\nEnd of Storage Report\n' > "$dir/leak.log" - report "$dir/clean.log" - if report "$dir/leak.log"; then - echo "selftest: a leak was not reported" + printf 'HEAP statistics:\n Total heap storage used (sugg. initial size): 3328\n Successful Get Heap requests: 4\n Successful Free Heap requests: 0\n' > "$dir/one.log" + printf 'HEAP statistics:\n Total heap storage used (sugg. initial size): 3328\n Successful Get Heap requests: 4\n Successful Free Heap requests: 0\n' > "$dir/two.log" + printf 'HEAP statistics:\n Total heap storage used (sugg. initial size): 4096\n Successful Get Heap requests: 5\n Successful Free Heap requests: 0\n' > "$dir/leak.log" + one=$(stats "$dir/one.log") + two=$(stats "$dir/two.log") + if [ "$one" != "$two" ]; then + echo "selftest: identical reports compared unequal" + exit 1 + fi + if [ "$one" = "$(stats "$dir/leak.log")" ]; then + echo "selftest: a bigger heap was not noticed" exit 1 fi echo "leakcheck: ok" @@ -59,12 +62,22 @@ fi bin=${1:-./ztop} mkdir -p "$dir" opts='RPTSTG(ON),RPTOPTS(ON),HEAPCHK(ON)' +base='' run() { name=$1 shift _CEE_RUNOPTS=$opts "$bin" "$@" > "$dir/$name.out" 2> "$dir/$name.log" - printf '%-5s ' "$name" - report "$dir/$name.log" + s=$(stats "$dir/$name.log") + if [ -z "$base" ]; then + base=$s + printf '%-5s %s\n' "$name" "$s" + return + fi + if [ "$s" != "$base" ]; then + printf 'LEAK %-5s %s (first run: %s)\n' "$name" "$s" "$base" + return 1 + fi + printf '%-5s %s\n' "$name" "$s" } for a in csa sqa lsqa pvt; do |
