diff options
| author | Ian Lance Taylor <iant@golang.org> | 2023-09-01 12:52:48 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-09-05 22:43:54 +0000 |
| commit | cffdfe8d2cabbe874bceaeed1eba92cc567be6db (patch) | |
| tree | d4b602cb3c84c6a49f5fe898d1ee9e79b272717b /src | |
| parent | a8191789153dcc76abb6a4d3cd4e56e2d68c2430 (diff) | |
| download | go-cffdfe8d2cabbe874bceaeed1eba92cc567be6db.tar.xz | |
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 <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>
Diffstat (limited to 'src')
| -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 5eccf86e1a..df75658750 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 8f6880b417..fbd7626225 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 d62d4b4be8..00b511d23b 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) |
