Skip to content

Commit dd78bc0

Browse files
committed
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 <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent bc3bdfa commit dd78bc0

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

src/runtime/syscall_windows_test.go

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -647,39 +647,13 @@ func TestZeroDivisionException(t *testing.T) {
647647
}
648648
}
649649

650-
func testRaiseException(t *testing.T, exitcode int) {
651-
t.Helper()
652-
const EXCEPTION_NONCONTINUABLE = 1
653-
mod := syscall.MustLoadDLL("kernel32.dll")
654-
proc := mod.MustFindProc("RaiseException")
655-
proc.Call(uintptr(exitcode), EXCEPTION_NONCONTINUABLE, 0, 0)
656-
t.Fatal("RaiseException should not return")
657-
}
658-
659-
func TestCrashExitCode(t *testing.T) {
660-
const exitcode = 0xbad
661-
if os.Getenv("TEST_CRASH_EXIT_CODE") == "1" {
662-
testRaiseException(t, exitcode)
663-
}
664-
exe, err := os.Executable()
665-
if err != nil {
666-
t.Fatal(err)
667-
}
668-
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestCrashExitCode"))
669-
cmd.Env = append(cmd.Env, "TEST_CRASH_EXIT_CODE=1", "GOTRACEBACK=crash")
670-
_, err = cmd.CombinedOutput()
671-
if err == nil {
672-
t.Error("test program succeeded unexpectedly")
673-
} else if ee, ok := err.(*exec.ExitError); !ok {
674-
t.Errorf("error (%v) has type %T; expected exec.ExitError", err, err)
675-
} else if got := ee.ExitCode(); got != exitcode {
676-
t.Fatalf("got exit code %d; want %d", got, exitcode)
677-
}
678-
}
679-
680650
func TestWERDialogue(t *testing.T) {
681651
if os.Getenv("TEST_WER_DIALOGUE") == "1" {
682-
testRaiseException(t, 0xbad)
652+
const EXCEPTION_NONCONTINUABLE = 1
653+
mod := syscall.MustLoadDLL("kernel32.dll")
654+
proc := mod.MustFindProc("RaiseException")
655+
proc.Call(0xbad, EXCEPTION_NONCONTINUABLE, 0, 0)
656+
t.Fatal("RaiseException should not return")
683657
}
684658
exe, err := os.Executable()
685659
if err != nil {
@@ -688,7 +662,7 @@ func TestWERDialogue(t *testing.T) {
688662
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestWERDialogue"))
689663
cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer")
690664
// Child process should not open WER dialogue, but return immediately instead.
691-
// The exit code can't be reliably tested here because WER can change it.
665+
// The exit code can't be reliably tested here because Windows can change it.
692666
_, err = cmd.CombinedOutput()
693667
if err == nil {
694668
t.Error("test program succeeded unexpectedly")

0 commit comments

Comments
 (0)