aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-gdb_test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-11-03 09:08:33 -0400
committerGopher Robot <gobot@golang.org>2022-11-04 16:48:32 +0000
commit0758a7d82da03d38fff8619a245f5fcb05721cf9 (patch)
tree895e7cb2e54d09880b6ec34c025a9c7b0f9cb404 /src/runtime/runtime-gdb_test.go
parentedfe07834905809d687b30632ccb849b84ebd4f2 (diff)
downloadgo-0758a7d82da03d38fff8619a245f5fcb05721cf9.tar.xz
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>
Diffstat (limited to 'src/runtime/runtime-gdb_test.go')
-rw-r--r--src/runtime/runtime-gdb_test.go41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go
index d3a30870c1..4e7c22762a 100644
--- a/src/runtime/runtime-gdb_test.go
+++ b/src/runtime/runtime-gdb_test.go
@@ -6,7 +6,7 @@ package runtime_test
import (
"bytes"
- "context"
+ "flag"
"fmt"
"internal/testenv"
"os"
@@ -400,6 +400,15 @@ func TestGdbBacktrace(t *testing.T) {
if runtime.GOOS == "netbsd" {
testenv.SkipFlaky(t, 15603)
}
+ if flag.Lookup("test.parallel").Value.(flag.Getter).Get().(int) < 2 {
+ // It is possible that this test will hang for a long time due to an
+ // apparent GDB bug reported in https://go.dev/issue/37405.
+ // If test parallelism is high enough, that might be ok: the other parallel
+ // tests will finish, and then this test will finish right before it would
+ // time out. However, if test are running sequentially, a hang in this test
+ // would likely cause the remaining tests to run out of time.
+ testenv.SkipFlaky(t, 37405)
+ }
checkGdbEnvironment(t)
t.Parallel()
@@ -421,6 +430,7 @@ func TestGdbBacktrace(t *testing.T) {
}
// Execute gdb commands.
+ start := time.Now()
args := []string{"-nx", "-batch",
"-iex", "add-auto-load-safe-path " + filepath.Join(testenv.GOROOT(t), "src", "runtime"),
"-ex", "set startup-with-shell off",
@@ -430,9 +440,32 @@ func TestGdbBacktrace(t *testing.T) {
"-ex", "continue",
filepath.Join(dir, "a.exe"),
}
- ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
- defer cancel()
- got, err := testenv.CommandContext(t, ctx, "gdb", args...).CombinedOutput()
+ cmd = testenv.Command(t, "gdb", args...)
+
+ // Work around the GDB hang reported in https://go.dev/issue/37405.
+ // Sometimes (rarely), the GDB process hangs completely when the Go program
+ // exits, and we suspect that the bug is on the GDB side.
+ //
+ // The default Cancel function added by testenv.Command will mark the test as
+ // failed if it is in danger of timing out, but we want to instead mark it as
+ // skipped. Change the Cancel function to kill the process and merely log
+ // instead of failing the test.
+ //
+ // (This approach does not scale: if the test parallelism is less than or
+ // equal to the number of tests that run right up to the deadline, then the
+ // remaining parallel tests are likely to time out. But as long as it's just
+ // this one flaky test, it's probably fine..?)
+ //
+ // If there is no deadline set on the test at all, relying on the timeout set
+ // by testenv.Command will cause the test to hang indefinitely, but that's
+ // what “no deadline” means, after all — and it's probably the right behavior
+ // anyway if someone is trying to investigate and fix the GDB bug.
+ cmd.Cancel = func() error {
+ t.Logf("GDB command timed out after %v: %v", time.Since(start), cmd)
+ return cmd.Process.Kill()
+ }
+
+ got, err := cmd.CombinedOutput()
t.Logf("gdb output:\n%s", got)
if err != nil {
if bytes.Contains(got, []byte("internal-error: wait returned unexpected status 0x0")) {