test: a failed real-process test keeps its daemons' whole logs

The harness printed only the last 16 KB of each daemon's log, so a
decision made at bring-up was cut off. With SWBLOCK_TEST_LOG_DIR set (the
layout gate sets it per entry to an evidence folder it collects), a
failed test also writes each daemon's whole log there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 16:49:28 -08:00
1 parent b58b04e6db
commit 5d54bd326b
2 files changed
+25 -1

No files matched your search

@@ -555,6 +555,7 @@ func (h *plannedHandoffHarness) start(t *testing.T, name, binary string, args ..
}
_ = log.Close()
if t.Failed() {
keepFullLog(t, d)
data, _ := os.ReadFile(d.log)
if len(data) > 16000 {
data = data[len(data)-16000:]
@@ -571,6 +572,28 @@ func (h *plannedHandoffHarness) start(t *testing.T, name, binary string, args ..
return d
}
// keepFullLog copies a failed test's daemon log, whole, into
// $SWBLOCK_TEST_LOG_DIR when that is set (a gate run collects it): the
// test's own output keeps only the log's tail, and a bring-up decision is
// at its head.
func keepFullLog(t *testing.T, d *daemon) {
dir := os.Getenv("SWBLOCK_TEST_LOG_DIR")
if dir == "" {
return
}
data, err := os.ReadFile(d.log)
if err == nil {
err = os.MkdirAll(dir, 0o755)
}
if err == nil {
name := strings.NewReplacer("/", "_", " ", "_").Replace(t.Name()) + "-" + d.name + ".log"
err = os.WriteFile(filepath.Join(dir, name), data, 0o644)
}
if err != nil {
t.Logf("%s: full log not kept: %v", d.name, err)
}
}
// wait waits up to timeout for the child to exit by itself and returns its
// exit error (nil: status 0).
func (d *daemon) wait(timeout time.Duration) error {
@@ -194,7 +194,8 @@ phases:
*) echo "unknown entry: $t" >&2; exit 2 ;;
esac
log="$d/evidence/$t.log"
(cd "$d/source/$pkg" && env $extra "$d/bin/$bin" -test.run "^$name\$" -test.v -test.count 1 -test.timeout "$to") > "$log" 2>&1
# A failed test keeps its daemons' whole logs here (collected).
(cd "$d/source/$pkg" && env $extra SWBLOCK_TEST_LOG_DIR="$d/evidence/$t-daemons" "$d/bin/$bin" -test.run "^$name\$" -test.v -test.count 1 -test.timeout "$to") > "$log" 2>&1
rc=$?
if [ "$rc" -eq 0 ] && grep -qE "^--- PASS: $name \(" "$log"; then
echo "PASS $t $name" >> "$d/evidence/verdicts.txt"