From aa36237e1604de6a2a6275f5580c9d680d627c2f Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 6 Oct 2021 15:52:54 +0100 Subject: Add -Z oom={panic,abort} command-line option --- src/test/ui/oom_unwind.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/ui/oom_unwind.rs (limited to 'src/test') diff --git a/src/test/ui/oom_unwind.rs b/src/test/ui/oom_unwind.rs new file mode 100644 index 00000000000..7742d6f8372 --- /dev/null +++ b/src/test/ui/oom_unwind.rs @@ -0,0 +1,22 @@ +// compile-flags: -Z oom=panic +// run-pass +// no-prefer-dynamic +// needs-unwind + +#![feature(bench_black_box)] + +use std::hint::black_box; +use std::mem::forget; +use std::panic::catch_unwind; + +fn main() { + let panic = catch_unwind(|| { + // This is guaranteed to exceed even the size of the address space + for _ in 0..16 { + // Truncates to a suitable value for both 32-bit and 64-bit targets. + let alloc_size = 0x1000_0000_1000_0000u64 as usize; + forget(black_box(vec![0u8; alloc_size])); + } + }); + assert!(panic.is_err()); +} -- cgit 1.4.1-3-g733a5 From 0254e318b820d79bb448d4d22d93e345e67b25eb Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sat, 5 Mar 2022 00:11:46 +0000 Subject: Restrict oom_unwind test to Linux --- src/test/ui/oom_unwind.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/test') diff --git a/src/test/ui/oom_unwind.rs b/src/test/ui/oom_unwind.rs index 7742d6f8372..d036c817a0e 100644 --- a/src/test/ui/oom_unwind.rs +++ b/src/test/ui/oom_unwind.rs @@ -2,6 +2,7 @@ // run-pass // no-prefer-dynamic // needs-unwind +// only-linux #![feature(bench_black_box)] -- cgit 1.4.1-3-g733a5