Rename flag, datastructure and messaging around muting stdout and stderr

This commit is contained in:
Oli Scherer 2022-04-26 09:33:20 +00:00
parent 1d0fe1b6bb
commit a192a199a8
6 changed files with 22 additions and 22 deletions

View File

@ -374,8 +374,8 @@ fn main() {
miri_config.tag_raw = true;
miri_config.check_number_validity = true;
}
"-Zmiri-drop-stdout-stderr" => {
miri_config.drop_stdout_stderr = true;
"-Zmiri-mute-stdout-stderr" => {
miri_config.mute_stdout_stderr = true;
}
"-Zmiri-track-raw-pointers" => {
eprintln!(

View File

@ -118,7 +118,7 @@ pub struct MiriConfig {
pub strict_provenance: bool,
/// Whether to ignore any output by the program. This is helpful when debugging miri
/// as its messages don't get intermingled with the program messages.
pub drop_stdout_stderr: bool,
pub mute_stdout_stderr: bool,
}
impl Default for MiriConfig {
@ -145,7 +145,7 @@ impl Default for MiriConfig {
panic_on_unsupported: false,
backtrace_style: BacktraceStyle::Short,
strict_provenance: false,
drop_stdout_stderr: false,
mute_stdout_stderr: false,
}
}
}

View File

@ -292,8 +292,8 @@ pub struct Evaluator<'mir, 'tcx> {
/// Failure rate of compare_exchange_weak, between 0.0 and 1.0
pub(crate) cmpxchg_weak_failure_rate: f64,
/// Corresponds to -Zmiri-drop-stdout-stderr and doesn't write the output but acts as if it succeeded.
pub(crate) drop_stdout_stderr: bool,
/// Corresponds to -Zmiri-mute-stdout-stderr and doesn't write the output but acts as if it succeeded.
pub(crate) mute_stdout_stderr: bool,
}
impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
@ -330,7 +330,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
validate: config.validate,
enforce_number_validity: config.check_number_validity,
enforce_abi: config.check_abi,
file_handler: FileHandler::new(config.drop_stdout_stderr),
file_handler: FileHandler::new(config.mute_stdout_stderr),
dir_handler: Default::default(),
time_anchor: Instant::now(),
layouts,
@ -347,7 +347,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
tracked_alloc_ids: config.tracked_alloc_ids.clone(),
check_alignment: config.check_alignment,
cmpxchg_weak_failure_rate: config.cmpxchg_weak_failure_rate,
drop_stdout_stderr: config.drop_stdout_stderr,
mute_stdout_stderr: config.mute_stdout_stderr,
}
}

View File

@ -252,11 +252,11 @@ impl FileDescriptor for io::Stderr {
}
#[derive(Debug)]
struct DevNull;
struct DummyOutput;
impl FileDescriptor for DevNull {
impl FileDescriptor for DummyOutput {
fn as_file_handle<'tcx>(&self) -> InterpResult<'tcx, &FileHandle> {
throw_unsup_format!("/dev/null cannot be used as FileHandle");
throw_unsup_format!("stderr and stdout cannot be used as FileHandle");
}
fn read<'tcx>(
@ -264,7 +264,7 @@ impl FileDescriptor for DevNull {
_communicate_allowed: bool,
_bytes: &mut [u8],
) -> InterpResult<'tcx, io::Result<usize>> {
throw_unsup_format!("cannot read from /dev/null");
throw_unsup_format!("cannot read from stderr or stdout");
}
fn write<'tcx>(
@ -272,7 +272,7 @@ impl FileDescriptor for DevNull {
_communicate_allowed: bool,
bytes: &[u8],
) -> InterpResult<'tcx, io::Result<usize>> {
// We just don't write anything
// We just don't write anything, but report to the user that we did.
Ok(Ok(bytes.len()))
}
@ -281,18 +281,18 @@ impl FileDescriptor for DevNull {
_communicate_allowed: bool,
_offset: SeekFrom,
) -> InterpResult<'tcx, io::Result<u64>> {
throw_unsup_format!("cannot seek on /dev/null");
throw_unsup_format!("cannot seek on stderr or stdout");
}
fn close<'tcx>(
self: Box<Self>,
_communicate_allowed: bool,
) -> InterpResult<'tcx, io::Result<i32>> {
throw_unsup_format!("/dev/null cannot be closed");
throw_unsup_format!("stderr and stdout cannot be closed");
}
fn dup<'tcx>(&mut self) -> io::Result<Box<dyn FileDescriptor>> {
Ok(Box::new(DevNull))
Ok(Box::new(DummyOutput))
}
}
@ -302,11 +302,11 @@ pub struct FileHandler {
}
impl<'tcx> FileHandler {
pub(crate) fn new(drop_stdout_stderr: bool) -> FileHandler {
pub(crate) fn new(mute_stdout_stderr: bool) -> FileHandler {
let mut handles: BTreeMap<_, Box<dyn FileDescriptor>> = BTreeMap::new();
if drop_stdout_stderr {
handles.insert(0i32, Box::new(DevNull));
handles.insert(1i32, Box::new(DevNull));
if mute_stdout_stderr {
handles.insert(0i32, Box::new(DummyOutput));
handles.insert(1i32, Box::new(DummyOutput));
} else {
handles.insert(0i32, Box::new(io::stdin()));
handles.insert(1i32, Box::new(io::stdout()));

View File

@ -75,7 +75,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
use std::io::{self, Write};
let buf_cont = this.read_bytes_ptr(buf, Size::from_bytes(u64::from(n)))?;
let res = if this.machine.drop_stdout_stderr {
let res = if this.machine.mute_stdout_stderr {
Ok(buf_cont.len())
} else if handle == -11 {
io::stdout().write(buf_cont)

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-drop-stdout-stderr
// compile-flags: -Zmiri-mute-stdout-stderr
fn main() {
println!("cake");