Skip to content

Commit 2fd8c5b

Browse files
committed
runtime: don't check the exit code in TestWERDialogue
TestWERDialogue intent is to check that the WER dialog doesn't pop-up when `GOTRACEBACK=wer` is set. CL 474915 extended the test to also check the error code of the crashed process. This change is causing failures in Microsoft internal test pipelines because some WER setups can modify the exit code of the crashed application, for example to signal that the crash dump has been collected. Fix this issue by not checking the error code in TestWERDialogue. Also, add a new test, TestCrashExitCode, which does the same but using `GOTRACEBACK=crash` instead, so that we have one test that checks the error code. Change-Id: Iedde09e1df7223009ebef38a32a460f1ab07e31a Reviewed-on: https://go-review.googlesource.com/c/go/+/491935 Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent e335a26 commit 2fd8c5b

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

src/runtime/syscall_windows_test.go

+37-12
Original file line numberDiff line numberDiff line change
@@ -647,20 +647,27 @@ func TestZeroDivisionException(t *testing.T) {
647647
}
648648
}
649649

650-
func TestWERDialogue(t *testing.T) {
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) {
651660
const exitcode = 0xbad
652-
if os.Getenv("TEST_WER_DIALOGUE") == "1" {
653-
const EXCEPTION_NONCONTINUABLE = 1
654-
mod := syscall.MustLoadDLL("kernel32.dll")
655-
proc := mod.MustFindProc("RaiseException")
656-
proc.Call(exitcode, EXCEPTION_NONCONTINUABLE, 0, 0)
657-
t.Fatal("RaiseException should not return")
658-
return
661+
if os.Getenv("TEST_CRASH_EXIT_CODE") == "1" {
662+
testRaiseException(t, exitcode)
659663
}
660-
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestWERDialogue"))
661-
cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer")
662-
// Child process should not open WER dialogue, but return immediately instead.
663-
_, err := cmd.CombinedOutput()
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()
664671
if err == nil {
665672
t.Error("test program succeeded unexpectedly")
666673
} else if ee, ok := err.(*exec.ExitError); !ok {
@@ -670,6 +677,24 @@ func TestWERDialogue(t *testing.T) {
670677
}
671678
}
672679

680+
func TestWERDialogue(t *testing.T) {
681+
if os.Getenv("TEST_WER_DIALOGUE") == "1" {
682+
testRaiseException(t, 0xbad)
683+
}
684+
exe, err := os.Executable()
685+
if err != nil {
686+
t.Fatal(err)
687+
}
688+
cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestWERDialogue"))
689+
cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer")
690+
// 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.
692+
_, err = cmd.CombinedOutput()
693+
if err == nil {
694+
t.Error("test program succeeded unexpectedly")
695+
}
696+
}
697+
673698
func TestWindowsStackMemory(t *testing.T) {
674699
o := runTestProg(t, "testprog", "StackMemory")
675700
stackUsage, err := strconv.Atoi(o)

0 commit comments

Comments
 (0)