Skip to content

Commit 3fea422

Browse files
Rollup merge of #132093 - jieyouxu:suppress-wer, r=onur-ozkan
compiletest: suppress Windows Error Reporting (WER) for `run-make` tests WER by default will show a *bunch* of error dialogues for missing DLLs on Windows for `run-make` tests. We address that by: 1. Guarding `run-make` test process spawning with `disable_error_reporting`. 2. Fixing `disable_error_reporting` to also add the [`SEM_FAILCRITICALERRORS` flag to `SetErrorMode`][SetErrorMode]. Just `SEM_NOGPFAULTERRORBOX` was not sufficient to suppress error dialogues for e.g. missing DLLs. Fixes #132092. In particular, refer to that issue for the necessary conditions to observe these dialogues from popping up in the first place. I was only able to manually test this locally in my "native" Windows msvc environment and it prevents the WER dialogues from popping up, I don't think it's possible to really test this automatically. [SetErrorMode]: https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode?redirectedfrom=MSDN#parameters
2 parents a0afe45 + 464b242 commit 3fea422

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/tools/compiletest/src/runtest.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,29 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
5959
use std::sync::Mutex;
6060

6161
use windows::Win32::System::Diagnostics::Debug::{
62-
SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
62+
SEM_FAILCRITICALERRORS, SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
6363
};
6464

6565
static LOCK: Mutex<()> = Mutex::new(());
6666

6767
// Error mode is a global variable, so lock it so only one thread will change it
6868
let _lock = LOCK.lock().unwrap();
6969

70-
// Tell Windows to not show any UI on errors (such as terminating abnormally).
71-
// This is important for running tests, since some of them use abnormal
72-
// termination by design. This mode is inherited by all child processes.
70+
// Tell Windows to not show any UI on errors (such as terminating abnormally). This is important
71+
// for running tests, since some of them use abnormal termination by design. This mode is
72+
// inherited by all child processes.
73+
//
74+
// Note that `run-make` tests require `SEM_FAILCRITICALERRORS` in addition to suppress Windows
75+
// Error Reporting (WER) error dialogues that come from "critical failures" such as missing
76+
// DLLs.
77+
//
78+
// See <https://github.com/rust-lang/rust/issues/132092> and
79+
// <https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode?redirectedfrom=MSDN>.
7380
unsafe {
74-
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
81+
// read inherited flags
82+
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
7583
let old_mode = THREAD_ERROR_MODE(old_mode);
76-
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX);
84+
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
7785
let r = f();
7886
SetErrorMode(old_mode);
7987
r

src/tools/compiletest/src/runtest/run_make.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::Path;
22
use std::process::{Command, Output, Stdio};
33
use std::{env, fs};
44

5-
use super::{ProcRes, TestCx};
5+
use super::{ProcRes, TestCx, disable_error_reporting};
66
use crate::util::{copy_dir_all, dylib_env_var};
77

88
impl TestCx<'_> {
@@ -514,8 +514,8 @@ impl TestCx<'_> {
514514
}
515515
}
516516

517-
let (Output { stdout, stderr, status }, truncated) =
518-
self.read2_abbreviated(cmd.spawn().expect("failed to spawn `rmake`"));
517+
let proc = disable_error_reporting(|| cmd.spawn().expect("failed to spawn `rmake`"));
518+
let (Output { stdout, stderr, status }, truncated) = self.read2_abbreviated(proc);
519519
if !status.success() {
520520
let res = ProcRes {
521521
status,

0 commit comments

Comments
 (0)