-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for rustc/rustdoc broken pipe ICEs
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Check that `rustc` and `rustdoc` does not ICE upon encountering a broken pipe due to unhandled | ||
//! panics from raw std `println!` usages. | ||
//! | ||
//! Regression test for <https://github.com/rust-lang/rust/issues/34376>. | ||
// FIXME(jieyouxu): should test for Windows too, but rustc currently has a hack on Windows that | ||
// suppresses broken pipe errors. | ||
//@ only-unix (related to `-Zon-broken-pipe` behavior) | ||
//@ ignore-cross-compile (needs to run test binary) | ||
|
||
use std::io::Read; | ||
use std::os::unix::process::ExitStatusExt; | ||
use std::process::{Command, Stdio}; | ||
|
||
use run_make_support::{env_var, libc}; | ||
|
||
fn check_broken_pipe_handled_gracefully(name: &str, mut cmd: Command) { | ||
cmd.stdout(Stdio::piped()).stderr(Stdio::piped()); | ||
|
||
let mut child = cmd.spawn().unwrap(); | ||
// Close stdout | ||
drop(child.stdout.take()); | ||
// Read stderr | ||
let mut stderr = String::new(); | ||
child.stderr.as_mut().unwrap().read_to_string(&mut stderr).unwrap(); | ||
let status = child.wait().unwrap(); | ||
|
||
assert!(!status.success(), "{name}"); | ||
|
||
const PANIC_ICE_EXIT_STATUS: i32 = 101; | ||
assert_ne!(status.code(), Some(101), "{name}"); | ||
|
||
// By default with `SIG_DFL`, `SIGPIPE` get `Term` action. | ||
// | ||
// See <https://man7.org/linux/man-pages/man7/signal.7.html>. `SIGPIPE` seems to be signal | ||
// number 13 pretty consistently. | ||
assert_eq!(status.signal(), Some(libc::SIGPIPE), "{name}"); | ||
|
||
assert!(stderr.is_empty(), "{name} stderr:\n{}", stderr); | ||
} | ||
|
||
fn main() { | ||
let mut rustc = Command::new(env_var("RUSTC")); | ||
rustc.arg("--print=sysroot"); | ||
check_broken_pipe_handled_gracefully("rustc", rustc); | ||
|
||
let mut rustdoc = Command::new(env_var("RUSTDOC")); | ||
rustdoc.arg("--version"); | ||
check_broken_pipe_handled_gracefully("rustdoc", rustdoc); | ||
} |