mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: don't run TestCrashDumpsAllThreads in parallel
It sometimes seems to time out on slow systems, perhaps due to being run at the same time as a lot of other work. Also move the code to testdata/testprog, so that we don't have to build it separately. I hope that this Fixes #35356 Change-Id: I875b858fa23836513ae14d3116461e22fffd5352 Reviewed-on: https://go-review.googlesource.com/c/go/+/312510 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
7bedd47798
commit
02a8e83661
2 changed files with 55 additions and 61 deletions
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -78,27 +77,14 @@ func TestCrashDumpsAllThreads(t *testing.T) {
|
||||||
t.Skip("skipping; SIGQUIT is blocked, see golang.org/issue/19196")
|
t.Skip("skipping; SIGQUIT is blocked, see golang.org/issue/19196")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't use executeTest because we need to kill the
|
|
||||||
// program while it is running.
|
|
||||||
|
|
||||||
testenv.MustHaveGoBuild(t)
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
t.Parallel()
|
exe, err := buildTestProg(t, "testprog")
|
||||||
|
|
||||||
dir := t.TempDir()
|
|
||||||
|
|
||||||
if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte(crashDumpsAllThreadsSource), 0666); err != nil {
|
|
||||||
t.Fatalf("failed to create Go file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "a.exe", "main.go")
|
|
||||||
cmd.Dir = dir
|
|
||||||
out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("building source: %v\n%s", err, out)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command(filepath.Join(dir, "a.exe"))
|
cmd := exec.Command(exe, "CrashDumpsAllThreads")
|
||||||
cmd = testenv.CleanCmdEnv(cmd)
|
cmd = testenv.CleanCmdEnv(cmd)
|
||||||
cmd.Env = append(cmd.Env,
|
cmd.Env = append(cmd.Env,
|
||||||
"GOTRACEBACK=crash",
|
"GOTRACEBACK=crash",
|
||||||
|
|
@ -120,9 +106,12 @@ func TestCrashDumpsAllThreads(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer rp.Close()
|
||||||
|
|
||||||
cmd.ExtraFiles = []*os.File{wp}
|
cmd.ExtraFiles = []*os.File{wp}
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
|
wp.Close()
|
||||||
t.Fatalf("starting program: %v", err)
|
t.Fatalf("starting program: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,56 +133,14 @@ func TestCrashDumpsAllThreads(t *testing.T) {
|
||||||
// We want to see a stack trace for each thread.
|
// We want to see a stack trace for each thread.
|
||||||
// Before https://golang.org/cl/2811 running threads would say
|
// Before https://golang.org/cl/2811 running threads would say
|
||||||
// "goroutine running on other thread; stack unavailable".
|
// "goroutine running on other thread; stack unavailable".
|
||||||
out = outbuf.Bytes()
|
out := outbuf.Bytes()
|
||||||
n := bytes.Count(out, []byte("main.loop("))
|
n := bytes.Count(out, []byte("main.crashDumpsAllThreadsLoop("))
|
||||||
if n != 4 {
|
if n != 4 {
|
||||||
t.Errorf("found %d instances of main.loop; expected 4", n)
|
t.Errorf("found %d instances of main.loop; expected 4", n)
|
||||||
t.Logf("%s", out)
|
t.Logf("%s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const crashDumpsAllThreadsSource = `
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
const count = 4
|
|
||||||
runtime.GOMAXPROCS(count + 1)
|
|
||||||
|
|
||||||
chans := make([]chan bool, count)
|
|
||||||
for i := range chans {
|
|
||||||
chans[i] = make(chan bool)
|
|
||||||
go loop(i, chans[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for all the goroutines to start executing.
|
|
||||||
for _, c := range chans {
|
|
||||||
<-c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell our parent that all the goroutines are executing.
|
|
||||||
if _, err := os.NewFile(3, "pipe").WriteString("x"); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "write to pipe failed: %v\n", err)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
select {}
|
|
||||||
}
|
|
||||||
|
|
||||||
func loop(i int, c chan bool) {
|
|
||||||
close(c)
|
|
||||||
for {
|
|
||||||
for j := 0; j < 0x7fffffff; j++ {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
func TestPanicSystemstack(t *testing.T) {
|
func TestPanicSystemstack(t *testing.T) {
|
||||||
// Test that GOTRACEBACK=crash prints both the system and user
|
// Test that GOTRACEBACK=crash prints both the system and user
|
||||||
// stack of other threads.
|
// stack of other threads.
|
||||||
|
|
|
||||||
47
src/runtime/testdata/testprog/crashdump.go
vendored
Normal file
47
src/runtime/testdata/testprog/crashdump.go
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
register("CrashDumpsAllThreads", CrashDumpsAllThreads)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CrashDumpsAllThreads() {
|
||||||
|
const count = 4
|
||||||
|
runtime.GOMAXPROCS(count + 1)
|
||||||
|
|
||||||
|
chans := make([]chan bool, count)
|
||||||
|
for i := range chans {
|
||||||
|
chans[i] = make(chan bool)
|
||||||
|
go crashDumpsAllThreadsLoop(i, chans[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all the goroutines to start executing.
|
||||||
|
for _, c := range chans {
|
||||||
|
<-c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell our parent that all the goroutines are executing.
|
||||||
|
if _, err := os.NewFile(3, "pipe").WriteString("x"); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "write to pipe failed: %v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|
||||||
|
func crashDumpsAllThreadsLoop(i int, c chan bool) {
|
||||||
|
close(c)
|
||||||
|
for {
|
||||||
|
for j := 0; j < 0x7fffffff; j++ {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue