Skip to content

Commit 371994e

Browse files
committed
Auto merge of rust-lang#112314 - ferrocene:pa-core-alloc-abort, r=bjorn3
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort` Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure. This PR marks all of these tests with this attribute: ```rust #[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")] ``` I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2 parents 5683791 + a988dc2 commit 371994e

File tree

12 files changed

+42
-48
lines changed

12 files changed

+42
-48
lines changed

compiler/rustc_codegen_cranelift/patches/0023-coretests-Ignore-failing-tests.patch

-36
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,6 @@ Subject: [PATCH] [core] Ignore failing tests
1010
library/core/tests/time.rs | 1 +
1111
4 files changed, 18 insertions(+), 2 deletions(-)
1212

13-
diff --git a/array.rs b/array.rs
14-
index 4bc44e9..8e3c7a4 100644
15-
--- a/array.rs
16-
+++ b/array.rs
17-
@@ -242,6 +242,7 @@ fn iterator_drops() {
18-
assert_eq!(i.get(), 5);
19-
}
20-
21-
+/*
22-
// This test does not work on targets without panic=unwind support.
23-
// To work around this problem, test is marked is should_panic, so it will
24-
// be automagically skipped on unsuitable targets, such as
25-
@@ -283,6 +284,7 @@ fn array_default_impl_avoids_leaks_on_panic() {
26-
assert_eq!(COUNTER.load(Relaxed), 0);
27-
panic!("test succeeded")
28-
}
29-
+*/
30-
31-
#[test]
32-
fn empty_array_is_always_default() {
33-
@@ -304,6 +304,7 @@ fn array_map() {
34-
assert_eq!(b, [1, 2, 3]);
35-
}
36-
37-
+/*
38-
// See note on above test for why `should_panic` is used.
39-
#[test]
40-
#[should_panic(expected = "test succeeded")]
41-
@@ -332,6 +333,7 @@ fn array_map_drop_safety() {
42-
assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create);
43-
panic!("test succeeded")
44-
}
45-
+*/
46-
47-
#[test]
48-
fn cell_allows_array_cycle() {
4913
diff --git a/atomic.rs b/atomic.rs
5014
index 13b12db..96fe4b9 100644
5115
--- a/atomic.rs

library/alloc/src/collections/binary_heap/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ fn test_drain_sorted() {
309309
}
310310

311311
#[test]
312+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
312313
fn test_drain_sorted_leak() {
313314
let d0 = CrashTestDummy::new(0);
314315
let d1 = CrashTestDummy::new(1);
@@ -475,6 +476,7 @@ fn test_retain() {
475476
}
476477

477478
#[test]
479+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
478480
fn test_retain_catch_unwind() {
479481
let mut heap = BinaryHeap::from(vec![3, 1, 2]);
480482

@@ -502,6 +504,7 @@ fn test_retain_catch_unwind() {
502504
// FIXME: re-enable emscripten once it can unwind again
503505
#[test]
504506
#[cfg(not(target_os = "emscripten"))]
507+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
505508
fn panic_safe() {
506509
use rand::seq::SliceRandom;
507510
use std::cmp;

library/alloc/src/collections/btree/map/tests.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ mod test_drain_filter {
11551155
}
11561156

11571157
#[test]
1158+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
11581159
fn drop_panic_leak() {
11591160
let a = CrashTestDummy::new(0);
11601161
let b = CrashTestDummy::new(1);
@@ -1175,6 +1176,7 @@ mod test_drain_filter {
11751176
}
11761177

11771178
#[test]
1179+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
11781180
fn pred_panic_leak() {
11791181
let a = CrashTestDummy::new(0);
11801182
let b = CrashTestDummy::new(1);
@@ -1201,6 +1203,7 @@ mod test_drain_filter {
12011203

12021204
// Same as above, but attempt to use the iterator again after the panic in the predicate
12031205
#[test]
1206+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
12041207
fn pred_panic_reuse() {
12051208
let a = CrashTestDummy::new(0);
12061209
let b = CrashTestDummy::new(1);
@@ -1449,6 +1452,7 @@ fn test_clear() {
14491452
}
14501453

14511454
#[test]
1455+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
14521456
fn test_clear_drop_panic_leak() {
14531457
let a = CrashTestDummy::new(0);
14541458
let b = CrashTestDummy::new(1);
@@ -1540,11 +1544,13 @@ fn test_clone_panic_leak(size: usize) {
15401544
}
15411545

15421546
#[test]
1547+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
15431548
fn test_clone_panic_leak_height_0() {
15441549
test_clone_panic_leak(3)
15451550
}
15461551

15471552
#[test]
1553+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
15481554
fn test_clone_panic_leak_height_1() {
15491555
test_clone_panic_leak(MIN_INSERTS_HEIGHT_1)
15501556
}
@@ -2099,6 +2105,7 @@ create_append_test!(test_append_239, 239);
20992105
create_append_test!(test_append_1700, 1700);
21002106

21012107
#[test]
2108+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
21022109
fn test_append_drop_leak() {
21032110
let a = CrashTestDummy::new(0);
21042111
let b = CrashTestDummy::new(1);
@@ -2240,6 +2247,7 @@ fn test_split_off_large_random_sorted() {
22402247
}
22412248

22422249
#[test]
2250+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
22432251
fn test_into_iter_drop_leak_height_0() {
22442252
let a = CrashTestDummy::new(0);
22452253
let b = CrashTestDummy::new(1);
@@ -2263,6 +2271,7 @@ fn test_into_iter_drop_leak_height_0() {
22632271
}
22642272

22652273
#[test]
2274+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
22662275
fn test_into_iter_drop_leak_height_1() {
22672276
let size = MIN_INSERTS_HEIGHT_1;
22682277
for panic_point in vec![0, 1, size - 2, size - 1] {

library/alloc/src/collections/btree/set/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ fn test_drain_filter() {
377377
}
378378

379379
#[test]
380+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
380381
fn test_drain_filter_drop_panic_leak() {
381382
let a = CrashTestDummy::new(0);
382383
let b = CrashTestDummy::new(1);
@@ -397,6 +398,7 @@ fn test_drain_filter_drop_panic_leak() {
397398
}
398399

399400
#[test]
401+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
400402
fn test_drain_filter_pred_panic_leak() {
401403
let a = CrashTestDummy::new(0);
402404
let b = CrashTestDummy::new(1);

library/alloc/src/collections/linked_list/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ fn drain_filter_complex() {
985985
}
986986

987987
#[test]
988+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
988989
fn drain_filter_drop_panic_leak() {
989990
let d0 = CrashTestDummy::new(0);
990991
let d1 = CrashTestDummy::new(1);
@@ -1018,6 +1019,7 @@ fn drain_filter_drop_panic_leak() {
10181019
}
10191020

10201021
#[test]
1022+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
10211023
fn drain_filter_pred_panic_leak() {
10221024
static mut DROPS: i32 = 0;
10231025

@@ -1124,6 +1126,7 @@ fn test_drop_clear() {
11241126
}
11251127

11261128
#[test]
1129+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
11271130
fn test_drop_panic() {
11281131
static mut DROPS: i32 = 0;
11291132

library/alloc/src/slice/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ std::thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
187187

188188
#[test]
189189
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
190+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
190191
fn panic_safe() {
191192
panic::update_hook(move |prev, info| {
192193
if !SILENCE_PANIC.with(|s| s.get()) {

library/alloc/tests/slice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ fn test_box_slice_clone() {
14181418
#[test]
14191419
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
14201420
#[cfg_attr(target_os = "emscripten", ignore)]
1421+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
14211422
fn test_box_slice_clone_panics() {
14221423
use std::sync::atomic::{AtomicUsize, Ordering};
14231424
use std::sync::Arc;

library/alloc/tests/string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ fn test_remove_matches() {
394394
}
395395

396396
#[test]
397+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
397398
fn test_retain() {
398399
let mut s = String::from("α_β_γ");
399400

library/alloc/tests/vec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ fn test_retain_predicate_order() {
314314
}
315315

316316
#[test]
317+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
317318
fn test_retain_pred_panic_with_hole() {
318319
let v = (0..5).map(Rc::new).collect::<Vec<_>>();
319320
catch_unwind(AssertUnwindSafe(|| {
@@ -331,6 +332,7 @@ fn test_retain_pred_panic_with_hole() {
331332
}
332333

333334
#[test]
335+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
334336
fn test_retain_pred_panic_no_hole() {
335337
let v = (0..5).map(Rc::new).collect::<Vec<_>>();
336338
catch_unwind(AssertUnwindSafe(|| {
@@ -346,6 +348,7 @@ fn test_retain_pred_panic_no_hole() {
346348
}
347349

348350
#[test]
351+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
349352
fn test_retain_drop_panic() {
350353
struct Wrap(Rc<i32>);
351354

@@ -806,6 +809,7 @@ fn test_drain_end_overflow() {
806809
}
807810

808811
#[test]
812+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
809813
fn test_drain_leak() {
810814
static mut DROPS: i32 = 0;
811815

@@ -1038,6 +1042,7 @@ fn test_into_iter_clone() {
10381042
}
10391043

10401044
#[test]
1045+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
10411046
fn test_into_iter_leak() {
10421047
static mut DROPS: i32 = 0;
10431048

@@ -1195,6 +1200,7 @@ fn test_from_iter_specialization_head_tail_drop() {
11951200
}
11961201

11971202
#[test]
1203+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
11981204
fn test_from_iter_specialization_panic_during_iteration_drops() {
11991205
let drop_count: Vec<_> = (0..=2).map(|_| Rc::new(())).collect();
12001206
let src: Vec<_> = drop_count.iter().cloned().collect();
@@ -1219,6 +1225,7 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
12191225
}
12201226

12211227
#[test]
1228+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
12221229
fn test_from_iter_specialization_panic_during_drop_doesnt_leak() {
12231230
static mut DROP_COUNTER_OLD: [usize; 5] = [0; 5];
12241231
static mut DROP_COUNTER_NEW: [usize; 2] = [0; 2];
@@ -1494,6 +1501,7 @@ fn drain_filter_complex() {
14941501
// FIXME: re-enable emscripten once it can unwind again
14951502
#[test]
14961503
#[cfg(not(target_os = "emscripten"))]
1504+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
14971505
fn drain_filter_consumed_panic() {
14981506
use std::rc::Rc;
14991507
use std::sync::Mutex;
@@ -1546,6 +1554,7 @@ fn drain_filter_consumed_panic() {
15461554
// FIXME: Re-enable emscripten once it can catch panics
15471555
#[test]
15481556
#[cfg(not(target_os = "emscripten"))]
1557+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
15491558
fn drain_filter_unconsumed_panic() {
15501559
use std::rc::Rc;
15511560
use std::sync::Mutex;
@@ -2414,6 +2423,7 @@ fn test_vec_dedup() {
24142423
}
24152424

24162425
#[test]
2426+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
24172427
fn test_vec_dedup_panicking() {
24182428
#[derive(Debug)]
24192429
struct Panic<'a> {
@@ -2470,6 +2480,7 @@ fn test_vec_dedup_panicking() {
24702480

24712481
// Regression test for issue #82533
24722482
#[test]
2483+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
24732484
fn test_extend_from_within_panicking_clone() {
24742485
struct Panic<'dc> {
24752486
drop_count: &'dc AtomicU32,

library/alloc/tests/vec_deque.rs

+3
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ fn test_drop_clear() {
747747
}
748748

749749
#[test]
750+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
750751
fn test_drop_panic() {
751752
static mut DROPS: i32 = 0;
752753

@@ -1601,6 +1602,7 @@ fn test_try_rfold_moves_iter() {
16011602
}
16021603

16031604
#[test]
1605+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
16041606
fn truncate_leak() {
16051607
static mut DROPS: i32 = 0;
16061608

@@ -1634,6 +1636,7 @@ fn truncate_leak() {
16341636
}
16351637

16361638
#[test]
1639+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
16371640
fn test_drain_leak() {
16381641
static mut DROPS: i32 = 0;
16391642

library/core/tests/array.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,8 @@ fn iterator_drops() {
257257
assert_eq!(i.get(), 5);
258258
}
259259

260-
// This test does not work on targets without panic=unwind support.
261-
// To work around this problem, test is marked is should_panic, so it will
262-
// be automagically skipped on unsuitable targets, such as
263-
// wasm32-unknown-unknown.
264-
//
265-
// It means that we use panic for indicating success.
266-
#[test]
267-
#[should_panic(expected = "test succeeded")]
260+
#[test]
261+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
268262
fn array_default_impl_avoids_leaks_on_panic() {
269263
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
270264
static COUNTER: AtomicUsize = AtomicUsize::new(0);
@@ -296,7 +290,6 @@ fn array_default_impl_avoids_leaks_on_panic() {
296290
assert_eq!(*panic_msg, "bomb limit exceeded");
297291
// check that all bombs are successfully dropped
298292
assert_eq!(COUNTER.load(Relaxed), 0);
299-
panic!("test succeeded")
300293
}
301294

302295
#[test]
@@ -317,9 +310,8 @@ fn array_map() {
317310
assert_eq!(b, [1, 2, 3]);
318311
}
319312

320-
// See note on above test for why `should_panic` is used.
321313
#[test]
322-
#[should_panic(expected = "test succeeded")]
314+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
323315
fn array_map_drop_safety() {
324316
static DROPPED: AtomicUsize = AtomicUsize::new(0);
325317
struct DropCounter;
@@ -341,7 +333,6 @@ fn array_map_drop_safety() {
341333
});
342334
assert!(success.is_err());
343335
assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create);
344-
panic!("test succeeded")
345336
}
346337

347338
#[test]

library/test/src/tests.rs

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub fn ignored_tests_result_in_ignored() {
154154
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
155155
#[test]
156156
#[cfg(not(target_os = "emscripten"))]
157+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
157158
fn test_should_panic() {
158159
fn f() -> Result<(), String> {
159160
panic!();
@@ -184,6 +185,7 @@ fn test_should_panic() {
184185
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
185186
#[test]
186187
#[cfg(not(target_os = "emscripten"))]
188+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
187189
fn test_should_panic_good_message() {
188190
fn f() -> Result<(), String> {
189191
panic!("an error message");
@@ -214,6 +216,7 @@ fn test_should_panic_good_message() {
214216
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
215217
#[test]
216218
#[cfg(not(target_os = "emscripten"))]
219+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
217220
fn test_should_panic_bad_message() {
218221
use crate::tests::TrFailedMsg;
219222
fn f() -> Result<(), String> {
@@ -249,6 +252,7 @@ fn test_should_panic_bad_message() {
249252
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
250253
#[test]
251254
#[cfg(not(target_os = "emscripten"))]
255+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
252256
fn test_should_panic_non_string_message_type() {
253257
use crate::tests::TrFailedMsg;
254258
use std::any::TypeId;
@@ -288,6 +292,7 @@ fn test_should_panic_non_string_message_type() {
288292
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
289293
#[test]
290294
#[cfg(not(target_os = "emscripten"))]
295+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
291296
fn test_should_panic_but_succeeds() {
292297
let should_panic_variants = [ShouldPanic::Yes, ShouldPanic::YesWithMessage("error message")];
293298

0 commit comments

Comments
 (0)