From 6d31b27150cfbd38849d376549b7c05f83c18a85 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 1 Sep 2023 12:52:48 -0700 Subject: [release-branch.go1.21] runtime: don't let the tests leave core files behind Also add a check that we didn't leave any core files behind. For #65476. Fixes #65478. Change-Id: I30444ef43ad1a8cc1cacd3b75280f2128e104939 Reviewed-on: https://go-review.googlesource.com/c/go/+/525175 Reviewed-by: Ian Lance Taylor Reviewed-by: Keith Randall Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall (cherry picked from commit cffdfe8d2cabbe874bceaeed1eba92cc567be6db) Reviewed-on: https://go-review.googlesource.com/c/go/+/560896 --- src/runtime/crash_test.go | 11 +++++++++++ src/runtime/crash_unix_test.go | 2 ++ src/runtime/testdata/testprogcgo/threadprof.go | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 8f11333b462..53f7028882d 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -24,10 +24,21 @@ import ( var toRemove []string func TestMain(m *testing.M) { + _, coreErrBefore := os.Stat("core") + status := m.Run() for _, file := range toRemove { os.RemoveAll(file) } + + _, coreErrAfter := os.Stat("core") + if coreErrBefore != nil && coreErrAfter == nil { + fmt.Fprintln(os.Stderr, "runtime.test: some test left a core file behind") + if status == 0 { + status = 1 + } + } + os.Exit(status) } diff --git a/src/runtime/crash_unix_test.go b/src/runtime/crash_unix_test.go index 8d205e1de53..cc60bfb7dd0 100644 --- a/src/runtime/crash_unix_test.go +++ b/src/runtime/crash_unix_test.go @@ -91,6 +91,7 @@ func TestCrashDumpsAllThreads(t *testing.T) { cmd := testenv.Command(t, exe, "CrashDumpsAllThreads") cmd = testenv.CleanCmdEnv(cmd) + cmd.Dir = t.TempDir() // put any core file in tempdir cmd.Env = append(cmd.Env, "GOTRACEBACK=crash", // Set GOGC=off. Because of golang.org/issue/10958, the tight @@ -164,6 +165,7 @@ func TestPanicSystemstack(t *testing.T) { t.Parallel() cmd := exec.Command(os.Args[0], "testPanicSystemstackInternal") cmd = testenv.CleanCmdEnv(cmd) + cmd.Dir = t.TempDir() // put any core file in tempdir cmd.Env = append(cmd.Env, "GOTRACEBACK=crash") pr, pw, err := os.Pipe() if err != nil { diff --git a/src/runtime/testdata/testprogcgo/threadprof.go b/src/runtime/testdata/testprogcgo/threadprof.go index d62d4b4be83..00b511d23be 100644 --- a/src/runtime/testdata/testprogcgo/threadprof.go +++ b/src/runtime/testdata/testprogcgo/threadprof.go @@ -92,7 +92,9 @@ func CgoExternalThreadSignal() { return } - out, err := exec.Command(os.Args[0], "CgoExternalThreadSignal", "crash").CombinedOutput() + cmd := exec.Command(os.Args[0], "CgoExternalThreadSignal", "crash") + cmd.Dir = os.TempDir() // put any core file in tempdir + out, err := cmd.CombinedOutput() if err == nil { fmt.Println("C signal did not crash as expected") fmt.Printf("\n%s\n", out) -- cgit v1.2.3-54-g00ecf