diff options
author | Than McIntosh <thanm@google.com> | 2020-03-13 11:09:05 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2020-04-09 16:15:34 +0000 |
commit | 7c0ee1127bf41bf274b08170de3e42b171a903c0 (patch) | |
tree | bbbedf722a631bac5e7360f6bd978dc4dc527008 | |
parent | b191c6095ececd77881be0644b333fc44e35774c (diff) | |
download | go-7c0ee1127bf41bf274b08170de3e42b171a903c0.tar.gz go-7c0ee1127bf41bf274b08170de3e42b171a903c0.zip |
test: deflaking measures for runtime gdb test
Tweak the runtime's GDB python test to try to reduce flake failures.
Background: the intent of the testpoint in question is to make sure
that python-supported commands like "info goroutines" or "goroutine 1
backtrace" work properly. The Go code being run under the debugger as
part of the test is single-threaded, but the test is written assuming
that in addition to the primary goroutine there will be other
background goroutines available (owned by the runtime). The flakiness
seems to crop up the most when requesting a backtrace for one of these
background goroutines; the speculation is that if we catch a
runtime-owned goroutine in an odd state, this could interfere with the
test.
The change in this patch is to explicitly start an additional
goroutine from the main thread, so that when the debugger stops the
main thread we can be sure that there is some other non-main goroutine
in a known state.
This change authored by Josh Bleecher Snyder <josharian@gmail.com>.
Updates #24616.
Change-Id: I45682323d5898e5187c0adada7c5d117e92f403b
Reviewed-on: https://go-review.googlesource.com/c/go/+/226558
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
-rw-r--r-- | src/runtime/runtime-gdb_test.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index 4639e2fcb8..58f410cc59 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -108,6 +108,7 @@ import "fmt" import "runtime" var gslice []string func main() { + go func() { select{} }() // ensure a second goroutine is running mapvar := make(map[string]string, 13) mapvar["abc"] = "def" mapvar["ghi"] = "jkl" @@ -117,7 +118,7 @@ func main() { slicevar = append(slicevar, mapvar["abc"]) fmt.Println("hi") runtime.KeepAlive(ptrvar) - _ = ptrvar + _ = ptrvar // set breakpoint here gslice = slicevar runtime.KeepAlive(mapvar) } // END_OF_PROGRAM @@ -169,6 +170,16 @@ func testGdbPython(t *testing.T, cgo bool) { src := buf.Bytes() + // Locate breakpoint line + var bp int + lines := bytes.Split(src, []byte("\n")) + for i, line := range lines { + if bytes.Contains(line, []byte("breakpoint")) { + bp = i + break + } + } + err = ioutil.WriteFile(filepath.Join(dir, "main.go"), src, 0644) if err != nil { t.Fatalf("failed to create file: %v", err) @@ -203,7 +214,7 @@ func testGdbPython(t *testing.T, cgo bool) { } args = append(args, "-ex", "set python print-stack full", - "-ex", "br main.go:15", + "-ex", fmt.Sprintf("br main.go:%d", bp), "-ex", "run", "-ex", "echo BEGIN info goroutines\n", "-ex", "info goroutines", |