mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
b191c6095e
commit
7c0ee1127b
1 changed files with 13 additions and 2 deletions
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue