From b903b535d3ef82fab12a9cc0fa50fccc396ced55 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Wed, 9 Jul 2025 14:08:52 -0400 Subject: [PATCH] acme: capture pebble test subprocess stdout/stderr When spawning the pebble and pebble-challtestserv processes redirect stdout/stderr to bytes.Buffer instances and print their content at test end as appropriate. The stdout/stderr content for each process is printed if the test failed, or if testing is being done in verbose mode. Otherwise the output is swallowed. This makes debugging test failures much easier as output from the subprocesses from independent tests isn't intermingled. Updates golang/go#74437 Cq-Include-Trybots: luci.golang.try:x_crypto-gotip-linux-amd64-longtest Change-Id: Ia79a3609ce3522ef6248442de247554c39367162 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/686935 Auto-Submit: Daniel McCarney Reviewed-by: Roland Shoemaker Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI --- acme/pebble_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/acme/pebble_test.go b/acme/pebble_test.go index 63e6cc5..af7aee6 100644 --- a/acme/pebble_test.go +++ b/acme/pebble_test.go @@ -776,14 +776,28 @@ func prepareBinaries(t *testing.T, pebbleDir string) string { func spawnServerProcess(t *testing.T, dir string, cmd string, args ...string) { t.Helper() + var stdout, stderr bytes.Buffer + cmdInstance := exec.Command("./"+cmd, args...) cmdInstance.Dir = dir - cmdInstance.Stdout = os.Stdout - cmdInstance.Stderr = os.Stderr + cmdInstance.Stdout = &stdout + cmdInstance.Stderr = &stderr + if err := cmdInstance.Start(); err != nil { t.Fatalf("failed to start %s: %v", cmd, err) } + t.Cleanup(func() { cmdInstance.Process.Kill() + + if t.Failed() || testing.Verbose() { + t.Logf("=== %s output ===", cmd) + if stdout.Len() > 0 { + t.Logf("stdout:\n%s", strings.TrimSpace(stdout.String())) + } + if stderr.Len() > 0 { + t.Logf("stderr:\n%s", strings.TrimSpace(stderr.String())) + } + } }) }