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 <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
qmuntal 2023-05-03 12:19:58 +02:00 committed by Quim Muntal
parent e335a2665f
commit 2fd8c5b2d8
1 changed files with 37 additions and 12 deletions

View File

@ -647,20 +647,27 @@ func TestZeroDivisionException(t *testing.T) {
} }
} }
func TestWERDialogue(t *testing.T) { func testRaiseException(t *testing.T, exitcode int) {
const exitcode = 0xbad t.Helper()
if os.Getenv("TEST_WER_DIALOGUE") == "1" {
const EXCEPTION_NONCONTINUABLE = 1 const EXCEPTION_NONCONTINUABLE = 1
mod := syscall.MustLoadDLL("kernel32.dll") mod := syscall.MustLoadDLL("kernel32.dll")
proc := mod.MustFindProc("RaiseException") proc := mod.MustFindProc("RaiseException")
proc.Call(exitcode, EXCEPTION_NONCONTINUABLE, 0, 0) proc.Call(uintptr(exitcode), EXCEPTION_NONCONTINUABLE, 0, 0)
t.Fatal("RaiseException should not return") t.Fatal("RaiseException should not return")
return }
func TestCrashExitCode(t *testing.T) {
const exitcode = 0xbad
if os.Getenv("TEST_CRASH_EXIT_CODE") == "1" {
testRaiseException(t, exitcode)
} }
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestWERDialogue")) exe, err := os.Executable()
cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer") if err != nil {
// Child process should not open WER dialogue, but return immediately instead. t.Fatal(err)
_, err := cmd.CombinedOutput() }
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 { if err == nil {
t.Error("test program succeeded unexpectedly") t.Error("test program succeeded unexpectedly")
} else if ee, ok := err.(*exec.ExitError); !ok { } 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) { func TestWindowsStackMemory(t *testing.T) {
o := runTestProg(t, "testprog", "StackMemory") o := runTestProg(t, "testprog", "StackMemory")
stackUsage, err := strconv.Atoi(o) stackUsage, err := strconv.Atoi(o)