Skip to content

Rollup of 6 pull requests #132121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compiletest: suppress Windows Error Reporting (WER) for run-make tests
  • Loading branch information
jieyouxu committed Oct 24, 2024
commit 464b2425d810a97450bf2e45f39fc70b5203268c
20 changes: 14 additions & 6 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,29 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
use std::sync::Mutex;

use windows::Win32::System::Diagnostics::Debug::{
SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
SEM_FAILCRITICALERRORS, SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
};

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

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

// Tell Windows to not show any UI on errors (such as terminating abnormally).
// This is important for running tests, since some of them use abnormal
// termination by design. This mode is inherited by all child processes.
// Tell Windows to not show any UI on errors (such as terminating abnormally). This is important
// for running tests, since some of them use abnormal termination by design. This mode is
// inherited by all child processes.
//
// Note that `run-make` tests require `SEM_FAILCRITICALERRORS` in addition to suppress Windows
// Error Reporting (WER) error dialogues that come from "critical failures" such as missing
// DLLs.
//
// See <https://github.com/rust-lang/rust/issues/132092> and
// <https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode?redirectedfrom=MSDN>.
unsafe {
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
// read inherited flags
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
let old_mode = THREAD_ERROR_MODE(old_mode);
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX);
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
let r = f();
SetErrorMode(old_mode);
r
Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;
use std::process::{Command, Output, Stdio};
use std::{env, fs};

use super::{ProcRes, TestCx};
use super::{ProcRes, TestCx, disable_error_reporting};
use crate::util::{copy_dir_all, dylib_env_var};

impl TestCx<'_> {
Expand Down Expand Up @@ -514,8 +514,8 @@ impl TestCx<'_> {
}
}

let (Output { stdout, stderr, status }, truncated) =
self.read2_abbreviated(cmd.spawn().expect("failed to spawn `rmake`"));
let proc = disable_error_reporting(|| cmd.spawn().expect("failed to spawn `rmake`"));
let (Output { stdout, stderr, status }, truncated) = self.read2_abbreviated(proc);
if !status.success() {
let res = ProcRes {
status,
Expand Down
Loading