Skip to content

Commit

Permalink
Split test_ptr_try_cast_into_soundness (#1308)
Browse files Browse the repository at this point in the history
* [ci] Run Miri tests on multiple threads

Use `cargo nextest` to run Miri tests on twice the number of threads as
there are CPU cores.

* Split `test_ptr_try_cast_into_soundness`

This should enable better parallelization, especially under Miri in CI.

Comparing [1] (run with the parent commit) and [2] (run with this
commit), we see an overall speedup of 22m51s -> 18m28s, or ~19%.

[1] https://github.com/google/zerocopy/actions/runs/9148942749
[2] https://github.com/google/zerocopy/actions/runs/9148952446
  • Loading branch information
joshlf committed May 19, 2024
1 parent 889ac1b commit 7329607
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,9 @@ mod tests {
}
}

#[test]
fn test_ptr_try_cast_into_soundness() {
mod test_ptr_try_cast_into_soundness {
use super::*;

// This test is designed so that if `Ptr::try_cast_into_xxx` are
// buggy, it will manifest as unsoundness that Miri can detect.

Expand Down Expand Up @@ -1650,9 +1651,21 @@ mod tests {
trailing: [T],
}

// Each test case becomes its own `#[test]` function. We do this because
// this test in particular takes far, far longer to execute under Miri
// than all of our other tests combined. Previously, we had these
// execute sequentially in a single test function. We run Miri tests in
// parallel in CI, but this test being sequential meant that most of
// that parallelism was wasted, as all other tests would finish in a
// fraction of the total execution time, leaving this test to execute on
// a single thread for the remainder of the test. By putting each test
// case in its own function, we permit better use of available
// parallelism.
macro_rules! test {
($($ty:ty),*) => {
$({
($test_name:ident: $ty:ty) => {
#[test]
#[allow(non_snake_case)]
fn $test_name() {
const S: usize = core::mem::size_of::<$ty>();
const N: usize = if S == 0 { 4 } else { S * 4 };
test::<$ty, _, N>([None]);
Expand All @@ -1667,11 +1680,15 @@ mod tests {
test::<[$ty], _, N>([None, Some(0), Some(1), Some(2), Some(3)]);
test::<SliceDst<$ty>, _, N>([None, Some(0), Some(1), Some(2), Some(3)]);
}
})*
}
};
($ty:ident) => {
test!($ty: $ty);
};
($($ty:ident),*) => { $(test!($ty);)* }
}

test!(());
test!(empty_tuple: ());
test!(u8, u16, u32, u64, u128, usize, AU64);
test!(i8, i16, i32, i64, i128, isize);
test!(f32, f64);
Expand Down

0 comments on commit 7329607

Please sign in to comment.