diff options
Diffstat (limited to 'src/runtime/syscall_windows_test.go')
| -rw-r--r-- | src/runtime/syscall_windows_test.go | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/runtime/syscall_windows_test.go b/src/runtime/syscall_windows_test.go index 8686d3f7f8..e4b4118d9a 100644 --- a/src/runtime/syscall_windows_test.go +++ b/src/runtime/syscall_windows_test.go @@ -647,20 +647,27 @@ func TestZeroDivisionException(t *testing.T) { } } -func TestWERDialogue(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_WER_DIALOGUE") == "1" { - const EXCEPTION_NONCONTINUABLE = 1 - mod := syscall.MustLoadDLL("kernel32.dll") - proc := mod.MustFindProc("RaiseException") - proc.Call(exitcode, EXCEPTION_NONCONTINUABLE, 0, 0) - t.Fatal("RaiseException should not return") - return + if os.Getenv("TEST_CRASH_EXIT_CODE") == "1" { + testRaiseException(t, exitcode) } - cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-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. - _, err := cmd.CombinedOutput() + 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 { @@ -670,6 +677,24 @@ func TestWERDialogue(t *testing.T) { } } +func TestWERDialogue(t *testing.T) { + if os.Getenv("TEST_WER_DIALOGUE") == "1" { + testRaiseException(t, 0xbad) + } + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + 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. + _, err = cmd.CombinedOutput() + if err == nil { + t.Error("test program succeeded unexpectedly") + } +} + func TestWindowsStackMemory(t *testing.T) { o := runTestProg(t, "testprog", "StackMemory") stackUsage, err := strconv.Atoi(o) |
