Skip to content

Commit 0758a7d

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
runtime: eliminate arbitrary timeouts in runBuiltTestProg and TestGdbBacktrace
This may fix the TestEINTR failures that have been frequent on the riscv64 builders since CL 445597. Updates #37405. Updates #39043. Change-Id: Iaf1403ff5ce2ff0203d5d0059908097d32d0b217 Reviewed-on: https://go-review.googlesource.com/c/go/+/447495 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
1 parent edfe078 commit 0758a7d

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/runtime/crash_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package runtime_test
66

77
import (
88
"bytes"
9-
"context"
109
"errors"
1110
"flag"
1211
"fmt"
@@ -66,15 +65,17 @@ func runBuiltTestProg(t *testing.T, exe, name string, env ...string) string {
6665
t.Skip("-quick")
6766
}
6867

69-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
70-
defer cancel()
71-
cmd := testenv.CleanCmdEnv(testenv.CommandContext(t, ctx, exe, name))
68+
start := time.Now()
69+
70+
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, name))
7271
cmd.Env = append(cmd.Env, env...)
7372
if testing.Short() {
7473
cmd.Env = append(cmd.Env, "RUNTIME_TEST_SHORT=1")
7574
}
7675
out, err := cmd.CombinedOutput()
77-
if err != nil {
76+
if err == nil {
77+
t.Logf("%v (%v): ok", cmd, time.Since(start))
78+
} else {
7879
if _, ok := err.(*exec.ExitError); ok {
7980
t.Logf("%v: %v", cmd, err)
8081
} else if errors.Is(err, exec.ErrWaitDelay) {

src/runtime/runtime-gdb_test.go

+37-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package runtime_test
66

77
import (
88
"bytes"
9-
"context"
9+
"flag"
1010
"fmt"
1111
"internal/testenv"
1212
"os"
@@ -400,6 +400,15 @@ func TestGdbBacktrace(t *testing.T) {
400400
if runtime.GOOS == "netbsd" {
401401
testenv.SkipFlaky(t, 15603)
402402
}
403+
if flag.Lookup("test.parallel").Value.(flag.Getter).Get().(int) < 2 {
404+
// It is possible that this test will hang for a long time due to an
405+
// apparent GDB bug reported in https://go.dev/issue/37405.
406+
// If test parallelism is high enough, that might be ok: the other parallel
407+
// tests will finish, and then this test will finish right before it would
408+
// time out. However, if test are running sequentially, a hang in this test
409+
// would likely cause the remaining tests to run out of time.
410+
testenv.SkipFlaky(t, 37405)
411+
}
403412

404413
checkGdbEnvironment(t)
405414
t.Parallel()
@@ -421,6 +430,7 @@ func TestGdbBacktrace(t *testing.T) {
421430
}
422431

423432
// Execute gdb commands.
433+
start := time.Now()
424434
args := []string{"-nx", "-batch",
425435
"-iex", "add-auto-load-safe-path " + filepath.Join(testenv.GOROOT(t), "src", "runtime"),
426436
"-ex", "set startup-with-shell off",
@@ -430,9 +440,32 @@ func TestGdbBacktrace(t *testing.T) {
430440
"-ex", "continue",
431441
filepath.Join(dir, "a.exe"),
432442
}
433-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
434-
defer cancel()
435-
got, err := testenv.CommandContext(t, ctx, "gdb", args...).CombinedOutput()
443+
cmd = testenv.Command(t, "gdb", args...)
444+
445+
// Work around the GDB hang reported in https://go.dev/issue/37405.
446+
// Sometimes (rarely), the GDB process hangs completely when the Go program
447+
// exits, and we suspect that the bug is on the GDB side.
448+
//
449+
// The default Cancel function added by testenv.Command will mark the test as
450+
// failed if it is in danger of timing out, but we want to instead mark it as
451+
// skipped. Change the Cancel function to kill the process and merely log
452+
// instead of failing the test.
453+
//
454+
// (This approach does not scale: if the test parallelism is less than or
455+
// equal to the number of tests that run right up to the deadline, then the
456+
// remaining parallel tests are likely to time out. But as long as it's just
457+
// this one flaky test, it's probably fine..?)
458+
//
459+
// If there is no deadline set on the test at all, relying on the timeout set
460+
// by testenv.Command will cause the test to hang indefinitely, but that's
461+
// what “no deadline” means, after all — and it's probably the right behavior
462+
// anyway if someone is trying to investigate and fix the GDB bug.
463+
cmd.Cancel = func() error {
464+
t.Logf("GDB command timed out after %v: %v", time.Since(start), cmd)
465+
return cmd.Process.Kill()
466+
}
467+
468+
got, err := cmd.CombinedOutput()
436469
t.Logf("gdb output:\n%s", got)
437470
if err != nil {
438471
if bytes.Contains(got, []byte("internal-error: wait returned unexpected status 0x0")) {

0 commit comments

Comments
 (0)