Skip to content

Commit

Permalink
don't even try to compare with reference when there was truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 9, 2023
1 parent 4b0519d commit 24c14a4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/tools/compiletest/src/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ use std::io::{self, Write};
use std::mem::replace;
use std::process::{Child, Output};

pub fn read2_abbreviated(mut child: Child, filter_paths_from_len: &[String]) -> io::Result<Output> {
#[derive(Copy, Clone, Debug)]
pub enum Truncated {
Yes,
No,
}

pub fn read2_abbreviated(
mut child: Child,
filter_paths_from_len: &[String],
) -> io::Result<(Output, Truncated)> {
let mut stdout = ProcOutput::new();
let mut stderr = ProcOutput::new();

Expand All @@ -24,7 +33,9 @@ pub fn read2_abbreviated(mut child: Child, filter_paths_from_len: &[String]) ->
)?;
let status = child.wait()?;

Ok(Output { status, stdout: stdout.into_bytes(), stderr: stderr.into_bytes() })
let truncated =
if stdout.truncated() || stderr.truncated() { Truncated::Yes } else { Truncated::No };
Ok((Output { status, stdout: stdout.into_bytes(), stderr: stderr.into_bytes() }, truncated))
}

const MAX_OUT_LEN: usize = 1024 * 1024;
Expand All @@ -46,6 +57,10 @@ impl ProcOutput {
ProcOutput::Full { bytes: Vec::new(), filtered_len: 0 }
}

fn truncated(&self) -> bool {
matches!(self, Self::Abbreviated { .. })
}

fn extend(&mut self, data: &[u8], filter_paths_from_len: &[String]) {
let new_self = match *self {
ProcOutput::Full { ref mut bytes, ref mut filtered_len } => {
Expand Down
28 changes: 23 additions & 5 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::compute_diff::{write_diff, write_filtered_diff};
use crate::errors::{self, Error, ErrorKind};
use crate::header::TestProps;
use crate::json;
use crate::read2::read2_abbreviated;
use crate::read2::{read2_abbreviated, Truncated};
use crate::util::{add_dylib_path, dylib_env_var, logv, PathBufExt};
use crate::ColorConfig;
use regex::{Captures, Regex};
Expand Down Expand Up @@ -701,6 +701,7 @@ impl<'test> TestCx<'test> {
status: output.status,
stdout: String::from_utf8(output.stdout).unwrap(),
stderr: String::from_utf8(output.stderr).unwrap(),
truncated: Truncated::No,
cmdline: format!("{cmd:?}"),
};
self.dump_output(&proc_res.stdout, &proc_res.stderr);
Expand Down Expand Up @@ -1275,6 +1276,7 @@ impl<'test> TestCx<'test> {
status,
stdout: String::from_utf8(stdout).unwrap(),
stderr: String::from_utf8(stderr).unwrap(),
truncated: Truncated::No,
cmdline,
};
if adb.kill().is_err() {
Expand Down Expand Up @@ -1557,7 +1559,13 @@ impl<'test> TestCx<'test> {
};

self.dump_output(&out, &err);
ProcRes { status, stdout: out, stderr: err, cmdline: format!("{:?}", cmd) }
ProcRes {
status,
stdout: out,
stderr: err,
truncated: Truncated::No,
cmdline: format!("{:?}", cmd),
}
}

fn cleanup_debug_info_options(&self, options: &Vec<String>) -> Vec<String> {
Expand Down Expand Up @@ -2218,7 +2226,7 @@ impl<'test> TestCx<'test> {
dylib
}

fn read2_abbreviated(&self, child: Child) -> Output {
fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) {
let mut filter_paths_from_len = Vec::new();
let mut add_path = |path: &Path| {
let path = path.display().to_string();
Expand Down Expand Up @@ -2265,12 +2273,13 @@ impl<'test> TestCx<'test> {
child.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}

let Output { status, stdout, stderr } = self.read2_abbreviated(child);
let (Output { status, stdout, stderr }, truncated) = self.read2_abbreviated(child);

let result = ProcRes {
status,
stdout: String::from_utf8_lossy(&stdout).into_owned(),
stderr: String::from_utf8_lossy(&stderr).into_owned(),
truncated,
cmdline,
};

Expand Down Expand Up @@ -3601,12 +3610,14 @@ impl<'test> TestCx<'test> {
}
}

let output = self.read2_abbreviated(cmd.spawn().expect("failed to spawn `make`"));
let (output, truncated) =
self.read2_abbreviated(cmd.spawn().expect("failed to spawn `make`"));
if !output.status.success() {
let res = ProcRes {
status: output.status,
stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
truncated,
cmdline: format!("{:?}", cmd),
};
self.fatal_proc_rec("make failed", &res);
Expand Down Expand Up @@ -3768,6 +3779,12 @@ impl<'test> TestCx<'test> {
let emit_metadata = self.should_emit_metadata(pm);
let proc_res = self.compile_test(should_run, emit_metadata);
self.check_if_test_should_compile(&proc_res, pm);
if matches!(proc_res.truncated, Truncated::Yes) {
self.fatal_proc_rec(
&format!("compiler output got truncated, cannot compare with reference file"),
&proc_res,
);
}

// if the user specified a format in the ui test
// print the output to the stderr file, otherwise extract
Expand Down Expand Up @@ -4459,6 +4476,7 @@ pub struct ProcRes {
status: ExitStatus,
stdout: String,
stderr: String,
truncated: Truncated,
cmdline: String,
}

Expand Down

0 comments on commit 24c14a4

Please sign in to comment.