mirror of
https://github.com/golang/go
synced 2024-11-17 00:44:46 -07:00
runtime: remove TestCrashExitCode
TestCrashExitCode was added in CL 491935 to test that the exit code is honored when using GOTRACEBACK=crash, which is what normally happens on a stock Windows. The problem is that some applications (not only WER, as I incorrectly assumed in CL 491935) can hijack a crashing process and change its exit code. There is no way to tell if a crashing process using GOTRACEBACK=crash/ wer will have its error code hijacked, so we better don't test this behavior, which in fact is not documented by the Go runtime. Change-Id: Ib8247a8a1fe6303c4c7812a1bf2ded5f4e89acb1 Reviewed-on: https://go-review.googlesource.com/c/go/+/493495 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
bc3bdfa977
commit
dd78bc0564
@ -647,39 +647,13 @@ func TestZeroDivisionException(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testRaiseException(t *testing.T, exitcode int) {
|
||||
t.Helper()
|
||||
const EXCEPTION_NONCONTINUABLE = 1
|
||||
mod := syscall.MustLoadDLL("kernel32.dll")
|
||||
proc := mod.MustFindProc("RaiseException")
|
||||
proc.Call(uintptr(exitcode), EXCEPTION_NONCONTINUABLE, 0, 0)
|
||||
t.Fatal("RaiseException should not return")
|
||||
}
|
||||
|
||||
func TestCrashExitCode(t *testing.T) {
|
||||
const exitcode = 0xbad
|
||||
if os.Getenv("TEST_CRASH_EXIT_CODE") == "1" {
|
||||
testRaiseException(t, exitcode)
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestCrashExitCode"))
|
||||
cmd.Env = append(cmd.Env, "TEST_CRASH_EXIT_CODE=1", "GOTRACEBACK=crash")
|
||||
_, err = cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Error("test program succeeded unexpectedly")
|
||||
} else if ee, ok := err.(*exec.ExitError); !ok {
|
||||
t.Errorf("error (%v) has type %T; expected exec.ExitError", err, err)
|
||||
} else if got := ee.ExitCode(); got != exitcode {
|
||||
t.Fatalf("got exit code %d; want %d", got, exitcode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWERDialogue(t *testing.T) {
|
||||
if os.Getenv("TEST_WER_DIALOGUE") == "1" {
|
||||
testRaiseException(t, 0xbad)
|
||||
const EXCEPTION_NONCONTINUABLE = 1
|
||||
mod := syscall.MustLoadDLL("kernel32.dll")
|
||||
proc := mod.MustFindProc("RaiseException")
|
||||
proc.Call(0xbad, EXCEPTION_NONCONTINUABLE, 0, 0)
|
||||
t.Fatal("RaiseException should not return")
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
@ -688,7 +662,7 @@ func TestWERDialogue(t *testing.T) {
|
||||
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestWERDialogue"))
|
||||
cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer")
|
||||
// Child process should not open WER dialogue, but return immediately instead.
|
||||
// The exit code can't be reliably tested here because WER can change it.
|
||||
// The exit code can't be reliably tested here because Windows can change it.
|
||||
_, err = cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Error("test program succeeded unexpectedly")
|
||||
|
Loading…
Reference in New Issue
Block a user