Skip to content

Commit

Permalink
test: deflaking measures for runtime gdb test
Browse files Browse the repository at this point in the history
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 <[email protected]>.

Updates #24616.

Change-Id: I45682323d5898e5187c0adada7c5d117e92f403b
Reviewed-on: https://go-review.googlesource.com/c/go/+/226558
Run-TryBot: Than McIntosh <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Josh Bleecher Snyder <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
thanm committed Apr 9, 2020
1 parent b191c60 commit 7c0ee11
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/runtime/runtime-gdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7c0ee11

Please sign in to comment.