memwatch: quiet bounded test summary off a terminal; bounded analyze wrapper
run.sh now records flutter's JSON results beside the log and prints a summary from tool/memwatch/summary.dart: one verdict line (pass/fail/skip counts, peak MB, duration, exit status), only failing tests with their error and app stack frames (framework frames dropped, per-test and total caps, tail of printed output), the tests still running when killed, and the log and JSON paths. Quiet is the default when stdout is not a terminal; MEMWATCH_OUTPUT=full also prints the whole log. The watchdog loop and exit status are unchanged. tool/analyze.sh bounds flutter analyze to a verdict line and the first 40 issues. Tests: test/tool/memwatch/summary_test.dart and the end-to-end tool/memwatch/quiet_test.sh over fixture suites.
This commit is contained in:
@@ -6,22 +6,31 @@
|
||||
# CONC flutter test --concurrency (default 1)
|
||||
# CAP_KB total RSS cap for this run's own test processes (default 3 GB)
|
||||
# MEMWATCH_DIR per-invocation output directory (default /tmp/memwatch)
|
||||
# FLUTTER flutter executable
|
||||
# FLUTTER flutter executable; DART the dart beside it (runs summary.dart)
|
||||
# MEMWATCH_OUTPUT quiet or full. Default: quiet when stdout is not a terminal
|
||||
# (agents, pipelines, pipes), full on a terminal. full prints the whole
|
||||
# flutter log before the summary; quiet prints only the summary.
|
||||
#
|
||||
# Runs flutter test in the background and polls the RSS of ITS OWN descendant
|
||||
# processes only; above CAP_KB it kills them (never another run's flutter_tester).
|
||||
# Prints the peak and the suite's last line, and exits with flutter's status
|
||||
# (137 when killed). A runaway test once grew to ~30 GB per process and crashed
|
||||
# the Mac twice, so never run `flutter test` outside this watchdog.
|
||||
# Then summary.dart prints a bounded report from flutter's JSON results: one
|
||||
# verdict line (pass/fail/skip counts, peak MB, duration, exit status), only
|
||||
# the failing tests with their error and app stack frames, and the paths of
|
||||
# the full log and JSON. Exits with flutter's status (137 when killed). A
|
||||
# runaway test once grew to ~30 GB per process and crashed the Mac twice, so
|
||||
# never run `flutter test` outside this watchdog.
|
||||
CONC=${CONC:-1}; CAP_KB=${CAP_KB:-3000000}
|
||||
MEMWATCH_DIR=${MEMWATCH_DIR:-/tmp/memwatch}
|
||||
FLUTTER=${FLUTTER:-/Users/alan/development/flutter/bin/flutter}
|
||||
DART=${DART:-$(dirname "$FLUTTER")/dart}
|
||||
here=$(cd "$(dirname "$0")" && pwd) || exit 1
|
||||
# Called from elsewhere (for example the repo root): run in this script's app/.
|
||||
[ -f pubspec.yaml ] || cd "$(dirname "$0")/../.." || exit 1
|
||||
[ -f pubspec.yaml ] || cd "$here/../.." || exit 1
|
||||
mkdir -p "$MEMWATCH_DIR" || exit 1
|
||||
out=$(mktemp "$MEMWATCH_DIR/out.XXXXXX")
|
||||
start=$SECONDS
|
||||
# $1 is deliberately unquoted: it carries the test path plus extra arguments.
|
||||
"$FLUTTER" test --concurrency="$CONC" $1 > "$out" 2>&1 &
|
||||
"$FLUTTER" test --concurrency="$CONC" --file-reporter "json:$out.json" $1 > "$out" 2>&1 &
|
||||
pid=$!
|
||||
descendants() { local p; for p in $(pgrep -P "$1"); do echo "$p"; descendants "$p"; done; }
|
||||
peak=0; killed=0
|
||||
@@ -38,6 +47,12 @@ while kill -0 $pid 2>/dev/null; do
|
||||
done
|
||||
wait $pid 2>/dev/null; status=$?
|
||||
[ $killed = 1 ] && status=137
|
||||
echo "peak $((peak/1024)) MB: $1 :: $(tail -1 "$out")"
|
||||
echo "full output: $out"
|
||||
mode=${MEMWATCH_OUTPUT:-}
|
||||
if [ -z "$mode" ]; then if [ -t 1 ]; then mode=full; else mode=quiet; fi; fi
|
||||
[ "$mode" = full ] && cat "$out"
|
||||
# The summary never changes the exit status; if it cannot run, keep the old lines.
|
||||
if ! "$DART" "$here/summary.dart" "$status" "$((peak/1024))" "$((SECONDS-start))" "$1" "$out" "$out.json" 2>/dev/null; then
|
||||
echo "peak $((peak/1024)) MB: $1 :: $(tail -1 "$out")"
|
||||
echo "full output: $out"
|
||||
fi
|
||||
exit $status
|
||||
|
||||
Reference in New Issue
Block a user