forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#96551 - ferrocene:pa-ignore-paths-when-abbrev…
…iating, r=Mark-Simulacrum [compiletest] Ignore known paths when abbreviating output To prevent out of memory conditions, compiletest limits the amount of output a test can generate, abbreviating it if the test emits more than a threshold. While the behavior is desirable, it also causes some issues (like rust-lang#96229, rust-lang#94322 and rust-lang#92211). The latest one happened recently, when the `src/test/ui/numeric/numeric-cast.rs` test started to fail on systems where the path of the rust-lang/rust checkout is too long. This includes my own development machine and [LLVM's CI](rust-lang#96362 (comment)). Rust's CI uses a pretty short directory name for the checkout, which hides these sort of problems until someone runs the test suite on their own computer. When developing the fix I tried to find the most targeted fix that would prevent this class of failures from happening in the future, deferring the decision on if/how to redesign abbreviation to a later date. The solution I came up with was to ignore known base paths when calculating whether the output exceeds the abbreviation threshold, which removes this kind of nondeterminism. This PR is best reviewed commit-by-commit.
- Loading branch information
Showing
3 changed files
with
249 additions
and
60 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
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,123 @@ | ||
use crate::read2::{ProcOutput, FILTERED_PATHS_PLACEHOLDER_LEN, HEAD_LEN, TAIL_LEN}; | ||
|
||
#[test] | ||
fn test_abbreviate_short_string() { | ||
let mut out = ProcOutput::new(); | ||
out.extend(b"Hello world!", &[]); | ||
assert_eq!(b"Hello world!", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_short_string_multiple_steps() { | ||
let mut out = ProcOutput::new(); | ||
|
||
out.extend(b"Hello ", &[]); | ||
out.extend(b"world!", &[]); | ||
|
||
assert_eq!(b"Hello world!", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_long_string() { | ||
let mut out = ProcOutput::new(); | ||
|
||
let data = vec![b'.'; HEAD_LEN + TAIL_LEN + 16]; | ||
out.extend(&data, &[]); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 16 BYTES >>>>>>\n\n"); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_long_string_multiple_steps() { | ||
let mut out = ProcOutput::new(); | ||
|
||
out.extend(&vec![b'.'; HEAD_LEN], &[]); | ||
out.extend(&vec![b'.'; TAIL_LEN], &[]); | ||
// Also test whether the rotation works | ||
out.extend(&vec![b'!'; 16], &[]); | ||
out.extend(&vec![b'?'; 16], &[]); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 32 BYTES >>>>>>\n\n"); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 32]); | ||
expected.extend_from_slice(&vec![b'!'; 16]); | ||
expected.extend_from_slice(&vec![b'?'; 16]); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filterss_are_detected() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &["foo".to_string(), "quux".to_string()]; | ||
|
||
out.extend(b"Hello foo", filters); | ||
// Check items from a previous extension are not double-counted. | ||
out.extend(b"! This is a qu", filters); | ||
// Check items are detected across extensions. | ||
out.extend(b"ux.", filters); | ||
|
||
match &out { | ||
ProcOutput::Full { bytes, filtered_len } => assert_eq!( | ||
*filtered_len, | ||
bytes.len() + FILTERED_PATHS_PLACEHOLDER_LEN * filters.len() | ||
- filters.iter().map(|i| i.len()).sum::<usize>() | ||
), | ||
ProcOutput::Abbreviated { .. } => panic!("out should not be abbreviated"), | ||
} | ||
|
||
assert_eq!(b"Hello foo! This is a quux.", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filters_avoid_abbreviations() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &[std::iter::repeat('a').take(64).collect::<String>()]; | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN - FILTERED_PATHS_PLACEHOLDER_LEN as usize]; | ||
expected.extend_from_slice(filters[0].as_bytes()); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
|
||
out.extend(&expected, filters); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filters_can_still_cause_abbreviations() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &[std::iter::repeat('a').take(64).collect::<String>()]; | ||
|
||
let mut input = vec![b'.'; HEAD_LEN]; | ||
input.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
input.extend_from_slice(filters[0].as_bytes()); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 64 BYTES >>>>>>\n\n"); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 64]); | ||
expected.extend_from_slice(&vec![b'a'; 64]); | ||
|
||
out.extend(&input, filters); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} |
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