Skip to content

Commit 7329607

Browse files
authored
Split test_ptr_try_cast_into_soundness (#1308)
* [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
1 parent 889ac1b commit 7329607

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/pointer/ptr.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,9 @@ mod tests {
15261526
}
15271527
}
15281528

1529-
#[test]
1530-
fn test_ptr_try_cast_into_soundness() {
1529+
mod test_ptr_try_cast_into_soundness {
1530+
use super::*;
1531+
15311532
// This test is designed so that if `Ptr::try_cast_into_xxx` are
15321533
// buggy, it will manifest as unsoundness that Miri can detect.
15331534

@@ -1650,9 +1651,21 @@ mod tests {
16501651
trailing: [T],
16511652
}
16521653

1654+
// Each test case becomes its own `#[test]` function. We do this because
1655+
// this test in particular takes far, far longer to execute under Miri
1656+
// than all of our other tests combined. Previously, we had these
1657+
// execute sequentially in a single test function. We run Miri tests in
1658+
// parallel in CI, but this test being sequential meant that most of
1659+
// that parallelism was wasted, as all other tests would finish in a
1660+
// fraction of the total execution time, leaving this test to execute on
1661+
// a single thread for the remainder of the test. By putting each test
1662+
// case in its own function, we permit better use of available
1663+
// parallelism.
16531664
macro_rules! test {
1654-
($($ty:ty),*) => {
1655-
$({
1665+
($test_name:ident: $ty:ty) => {
1666+
#[test]
1667+
#[allow(non_snake_case)]
1668+
fn $test_name() {
16561669
const S: usize = core::mem::size_of::<$ty>();
16571670
const N: usize = if S == 0 { 4 } else { S * 4 };
16581671
test::<$ty, _, N>([None]);
@@ -1667,11 +1680,15 @@ mod tests {
16671680
test::<[$ty], _, N>([None, Some(0), Some(1), Some(2), Some(3)]);
16681681
test::<SliceDst<$ty>, _, N>([None, Some(0), Some(1), Some(2), Some(3)]);
16691682
}
1670-
})*
1683+
}
1684+
};
1685+
($ty:ident) => {
1686+
test!($ty: $ty);
16711687
};
1688+
($($ty:ident),*) => { $(test!($ty);)* }
16721689
}
16731690

1674-
test!(());
1691+
test!(empty_tuple: ());
16751692
test!(u8, u16, u32, u64, u128, usize, AU64);
16761693
test!(i8, i16, i32, i64, i128, isize);
16771694
test!(f32, f64);

0 commit comments

Comments
 (0)