From ea62b8e6c541a1869ad0c0857a6bf9b0a20fbd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Thu, 3 Oct 2024 16:27:11 +0000 Subject: [PATCH] Add regression test for rustc/rustdoc broken pipe ICEs --- tests/run-make/broken-pipe-no-ice/rmake.rs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/run-make/broken-pipe-no-ice/rmake.rs diff --git a/tests/run-make/broken-pipe-no-ice/rmake.rs b/tests/run-make/broken-pipe-no-ice/rmake.rs new file mode 100644 index 0000000000000..0addec30b47a5 --- /dev/null +++ b/tests/run-make/broken-pipe-no-ice/rmake.rs @@ -0,0 +1,43 @@ +//! 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 . + +//@ ignore-cross-compile (needs to run test binary) + +#![feature(anonymous_pipe)] + +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) { + let (reader, writer) = std::pipe::pipe().unwrap(); + drop(reader); // close read-end + cmd.stdout(writer).stderr(Stdio::piped()); + + let mut child = cmd.spawn().unwrap(); + + 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}"); + + 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); +}