]> Cypherpunks repositories - gostls13.git/commitdiff
test: deflaking measures for runtime gdb test
authorThan McIntosh <thanm@google.com>
Fri, 13 Mar 2020 15:09:05 +0000 (11:09 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 9 Apr 2020 16:15:34 +0000 (16:15 +0000)
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>
src/runtime/runtime-gdb_test.go

index 4639e2fcb8d878195ec61d4790b46a20a3e4f7b6..58f410cc59b8227edcd0f2bb96cad52e4dabcdf7 100644 (file)
@@ -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",