diff options
author | Ian Lance Taylor <iant@golang.org> | 2023-09-01 12:52:48 -0700 |
---|---|---|
committer | Carlos Amedee <carlos@golang.org> | 2024-02-27 21:42:04 +0000 |
commit | 6d31b27150cfbd38849d376549b7c05f83c18a85 (patch) | |
tree | b53f37ff56ae1a38d19b01acecc59a4786ffcf0e | |
parent | f38fca30a7ea1346c6a7eefeb3253f2eefe8075b (diff) | |
download | go-6d31b27150cfbd38849d376549b7c05f83c18a85.tar.gz go-6d31b27150cfbd38849d376549b7c05f83c18a85.zip |
[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 <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
(cherry picked from commit cffdfe8d2cabbe874bceaeed1eba92cc567be6db)
Reviewed-on: https://go-review.googlesource.com/c/go/+/560896
-rw-r--r-- | src/runtime/crash_test.go | 11 | ||||
-rw-r--r-- | src/runtime/crash_unix_test.go | 2 | ||||
-rw-r--r-- | src/runtime/testdata/testprogcgo/threadprof.go | 4 |
3 files changed, 16 insertions, 1 deletions
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) |