Skip to content

Commit efec7cd

Browse files
committed
Auto merge of #75694 - RalfJung:miri-align-to, r=nagisa
enable align_to tests in Miri With rust-lang/miri#1074 resolved, we can enable these tests in Miri. I also tweaked the test sized to get reasonable execution times with decent test coverage.
2 parents 521db88 + 6a06bfc commit efec7cd

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

library/core/tests/ascii.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,8 @@ fn test_is_ascii_align_size_thoroughly() {
361361
repeat(b0).take(l).chain(repeat(b1).take(l)).collect()
362362
}
363363

364-
// Miri is too slow for much of this, and in miri `align_offset` always
365-
// returns `usize::max_value()` anyway (at the moment), so we just test
366-
// lightly.
367-
let iter = if cfg!(miri) { 0..5 } else { 0..100 };
364+
// Miri is too slow
365+
let iter = if cfg!(miri) { 0..20 } else { 0..100 };
368366

369367
for i in iter {
370368
#[cfg(not(miri))]
@@ -379,7 +377,7 @@ fn test_is_ascii_align_size_thoroughly() {
379377
];
380378

381379
#[cfg(miri)]
382-
let cases = &[repeat_concat(b'a', 0x80u8, i)];
380+
let cases = &[b"a".repeat(i), b"\x80".repeat(i), repeat_concat(b'a', 0x80u8, i)];
383381

384382
for case in cases {
385383
for pos in 0..=case.len() {

library/core/tests/ptr.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ fn write_unaligned_drop() {
300300
}
301301

302302
#[test]
303-
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
304303
fn align_offset_zst() {
305304
// For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at
306305
// all, because no amount of elements will align the pointer.
@@ -315,7 +314,6 @@ fn align_offset_zst() {
315314
}
316315

317316
#[test]
318-
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
319317
fn align_offset_stride1() {
320318
// For pointers of stride = 1, the pointer can always be aligned. The offset is equal to
321319
// number of bytes.
@@ -337,7 +335,6 @@ fn align_offset_stride1() {
337335
}
338336

339337
#[test]
340-
#[cfg_attr(miri, ignore)] // Miri is too slow
341338
fn align_offset_weird_strides() {
342339
#[repr(packed)]
343340
struct A3(u16, u8);
@@ -384,7 +381,9 @@ fn align_offset_weird_strides() {
384381
// implementation
385382
let mut align = 1;
386383
let mut x = false;
387-
while align < 1024 {
384+
// Miri is too slow
385+
let limit = if cfg!(miri) { 32 } else { 1024 };
386+
while align < limit {
388387
for ptr in 1usize..4 * align {
389388
unsafe {
390389
x |= test_weird_stride::<A3>(ptr as *const A3, align);

library/core/tests/slice.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,6 @@ pub mod memchr {
16301630
}
16311631

16321632
#[test]
1633-
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
16341633
fn test_align_to_simple() {
16351634
let bytes = [1u8, 2, 3, 4, 5, 6, 7];
16361635
let (prefix, aligned, suffix) = unsafe { bytes.align_to::<u16>() };
@@ -1660,7 +1659,6 @@ fn test_align_to_zst() {
16601659
}
16611660

16621661
#[test]
1663-
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
16641662
fn test_align_to_non_trivial() {
16651663
#[repr(align(8))]
16661664
struct U64(u64, u64);

0 commit comments

Comments
 (0)