Skip to content

Commit

Permalink
Fix compiletest: don't abbreviate the output (rust-lang#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaiser authored Jul 12, 2022
1 parent cb1a606 commit 69a021f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 64 deletions.
68 changes: 7 additions & 61 deletions tools/compiletest/src/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,26 @@
// Modifications Copyright Kani Contributors
// See GitHub history for details.

// FIXME: This is a complete copy of `cargo/src/cargo/util/read2.rs`
// Consider unify the read2() in libstd, cargo and this to prevent further code duplication.

pub use self::imp::read2;
use std::io;
use std::process::{Child, Output};

pub fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
use io::Write;
use std::mem::replace;

const HEAD_LEN: usize = 160 * 1024;
const TAIL_LEN: usize = 256 * 1024;

enum ProcOutput {
Full(Vec<u8>),
Abbreviated { head: Vec<u8>, skipped: usize, tail: Box<[u8]> },
}

impl ProcOutput {
fn extend(&mut self, data: &[u8]) {
let new_self = match *self {
ProcOutput::Full(ref mut bytes) => {
bytes.extend_from_slice(data);
let new_len = bytes.len();
if new_len <= HEAD_LEN + TAIL_LEN {
return;
}
let tail = bytes.split_off(new_len - TAIL_LEN).into_boxed_slice();
let head = replace(bytes, Vec::new());
let skipped = new_len - HEAD_LEN - TAIL_LEN;
ProcOutput::Abbreviated { head, skipped, tail }
}
ProcOutput::Abbreviated { ref mut skipped, ref mut tail, .. } => {
*skipped += data.len();
if data.len() <= TAIL_LEN {
tail[..data.len()].copy_from_slice(data);
tail.rotate_left(data.len());
} else {
tail.copy_from_slice(&data[(data.len() - TAIL_LEN)..]);
}
return;
}
};
*self = new_self;
}

fn into_bytes(self) -> Vec<u8> {
match self {
ProcOutput::Full(bytes) => bytes,
ProcOutput::Abbreviated { mut head, skipped, tail } => {
write!(&mut head, "\n\n<<<<<< SKIPPED {} BYTES >>>>>>\n\n", skipped).unwrap();
head.extend_from_slice(&tail);
head
}
}
}
}

let mut stdout = ProcOutput::Full(Vec::new());
let mut stderr = ProcOutput::Full(Vec::new());
pub fn read2(mut child: Child) -> io::Result<Output> {
let mut stdout = Vec::new();
let mut stderr = Vec::new();

drop(child.stdin.take());
read2(
self::imp::read2(
child.stdout.take().unwrap(),
child.stderr.take().unwrap(),
&mut |is_stdout, data, _| {
if is_stdout { &mut stdout } else { &mut stderr }.extend(data);
let out = if is_stdout { &mut stdout } else { &mut stderr };
out.extend(data.iter());
data.clear();
},
)?;
let status = child.wait()?;

Ok(Output { status, stdout: stdout.into_bytes(), stderr: stderr.into_bytes() })
Ok(Output { status, stdout, stderr })
}

#[cfg(not(any(unix, windows)))]
Expand Down
5 changes: 2 additions & 3 deletions tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::common::{CargoKani, Expected, Kani, KaniFixme, Stub};
use crate::common::{Config, TestPaths};
use crate::header::TestProps;
use crate::json;
use crate::read2::read2_abbreviated;
use crate::read2::read2;
use crate::util::logv;
use regex::Regex;

Expand Down Expand Up @@ -87,8 +87,7 @@ impl<'test> TestCx<'test> {
let child = disable_error_reporting(|| command.spawn())
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", &command));

let Output { status, stdout, stderr } =
read2_abbreviated(child).expect("failed to read output");
let Output { status, stdout, stderr } = read2(child).expect("failed to read output");

let result = ProcRes {
status,
Expand Down

0 comments on commit 69a021f

Please sign in to comment.