Skip to content

Commit cffdfe8

Browse files
ianlancetaylorgopherbot
authored andcommitted
runtime: don't let the tests leave core files behind
Also add a check that we didn't leave any core files behind. Change-Id: I30444ef43ad1a8cc1cacd3b75280f2128e104939 Reviewed-on: https://go-review.googlesource.com/c/go/+/525175 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent a819178 commit cffdfe8

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/runtime/crash_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ import (
2424
var toRemove []string
2525

2626
func TestMain(m *testing.M) {
27+
_, coreErrBefore := os.Stat("core")
28+
2729
status := m.Run()
2830
for _, file := range toRemove {
2931
os.RemoveAll(file)
3032
}
33+
34+
_, coreErrAfter := os.Stat("core")
35+
if coreErrBefore != nil && coreErrAfter == nil {
36+
fmt.Fprintln(os.Stderr, "runtime.test: some test left a core file behind")
37+
if status == 0 {
38+
status = 1
39+
}
40+
}
41+
3142
os.Exit(status)
3243
}
3344

src/runtime/crash_unix_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func TestCrashDumpsAllThreads(t *testing.T) {
9191

9292
cmd := testenv.Command(t, exe, "CrashDumpsAllThreads")
9393
cmd = testenv.CleanCmdEnv(cmd)
94+
cmd.Dir = t.TempDir() // put any core file in tempdir
9495
cmd.Env = append(cmd.Env,
9596
"GOTRACEBACK=crash",
9697
// Set GOGC=off. Because of golang.org/issue/10958, the tight
@@ -164,6 +165,7 @@ func TestPanicSystemstack(t *testing.T) {
164165
t.Parallel()
165166
cmd := exec.Command(os.Args[0], "testPanicSystemstackInternal")
166167
cmd = testenv.CleanCmdEnv(cmd)
168+
cmd.Dir = t.TempDir() // put any core file in tempdir
167169
cmd.Env = append(cmd.Env, "GOTRACEBACK=crash")
168170
pr, pw, err := os.Pipe()
169171
if err != nil {

src/runtime/testdata/testprogcgo/threadprof.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func CgoExternalThreadSignal() {
9292
return
9393
}
9494

95-
out, err := exec.Command(os.Args[0], "CgoExternalThreadSignal", "crash").CombinedOutput()
95+
cmd := exec.Command(os.Args[0], "CgoExternalThreadSignal", "crash")
96+
cmd.Dir = os.TempDir() // put any core file in tempdir
97+
out, err := cmd.CombinedOutput()
9698
if err == nil {
9799
fmt.Println("C signal did not crash as expected")
98100
fmt.Printf("\n%s\n", out)

0 commit comments

Comments
 (0)