From 4e8199b572f2035b7749cba276ece3a26630d23e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:21 +0200 Subject: Adding upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/once_cell/tests/it.rs | 45 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'vendor/once_cell/tests') diff --git a/vendor/once_cell/tests/it.rs b/vendor/once_cell/tests/it.rs index 410b93b64..d18f0a165 100644 --- a/vendor/once_cell/tests/it.rs +++ b/vendor/once_cell/tests/it.rs @@ -249,10 +249,16 @@ mod unsync { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "critical-section"))] mod sync { use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; + #[cfg(feature = "std")] + use std::sync::Barrier; + + #[cfg(not(feature = "std"))] + use core::cell::Cell; + use crossbeam_utils::thread::scope; use once_cell::sync::{Lazy, OnceCell}; @@ -354,6 +360,7 @@ mod sync { assert_eq!(cell.get(), Some(&"hello".to_string())); } + #[cfg(feature = "std")] #[test] fn wait() { let cell: OnceCell = OnceCell::new(); @@ -365,9 +372,9 @@ mod sync { .unwrap(); } + #[cfg(feature = "std")] #[test] fn get_or_init_stress() { - use std::sync::Barrier; let n_threads = if cfg!(miri) { 30 } else { 1_000 }; let n_cells = if cfg!(miri) { 30 } else { 1_000 }; let cells: Vec<_> = std::iter::repeat_with(|| (Barrier::new(n_threads), OnceCell::new())) @@ -430,6 +437,7 @@ mod sync { #[test] #[cfg_attr(miri, ignore)] // miri doesn't support processes + #[cfg(feature = "std")] fn reentrant_init() { let examples_dir = { let mut exe = std::env::current_exe().unwrap(); @@ -457,6 +465,20 @@ mod sync { } } + #[cfg(not(feature = "std"))] + #[test] + #[should_panic(expected = "reentrant init")] + fn reentrant_init() { + let x: OnceCell> = OnceCell::new(); + let dangling_ref: Cell> = Cell::new(None); + x.get_or_init(|| { + let r = x.get_or_init(|| Box::new(92)); + dangling_ref.set(Some(r)); + Box::new(62) + }); + eprintln!("use after free: {:?}", dangling_ref.get().unwrap()); + } + #[test] fn lazy_new() { let called = AtomicUsize::new(0); @@ -636,10 +658,9 @@ mod sync { } } + #[cfg(feature = "std")] #[test] fn get_does_not_block() { - use std::sync::Barrier; - let cell = OnceCell::new(); let barrier = Barrier::new(2); scope(|scope| { @@ -671,12 +692,11 @@ mod sync { #[cfg(feature = "race")] mod race { + #[cfg(feature = "std")] + use std::sync::Barrier; use std::{ num::NonZeroUsize, - sync::{ - atomic::{AtomicUsize, Ordering::SeqCst}, - Barrier, - }, + sync::atomic::{AtomicUsize, Ordering::SeqCst}, }; use crossbeam_utils::thread::scope; @@ -728,6 +748,7 @@ mod race { assert_eq!(cell.get(), Some(val1)); } + #[cfg(feature = "std")] #[test] fn once_non_zero_usize_first_wins() { let val1 = NonZeroUsize::new(92).unwrap(); @@ -807,12 +828,16 @@ mod race { #[cfg(all(feature = "race", feature = "alloc"))] mod race_once_box { + #[cfg(feature = "std")] + use std::sync::Barrier; use std::sync::{ atomic::{AtomicUsize, Ordering::SeqCst}, - Arc, Barrier, + Arc, }; + #[cfg(feature = "std")] use crossbeam_utils::thread::scope; + use once_cell::race::OnceBox; #[derive(Default)] @@ -842,6 +867,7 @@ mod race_once_box { } } + #[cfg(feature = "std")] #[test] fn once_box_smoke_test() { let heap = Heap::default(); @@ -896,6 +922,7 @@ mod race_once_box { assert_eq!(heap.total(), 0); } + #[cfg(feature = "std")] #[test] fn once_box_first_wins() { let cell = OnceBox::new(); -- cgit v1.2.3