From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rayon-core/tests/double_init_fail.rs | 14 ++++ vendor/rayon-core/tests/init_zero_threads.rs | 9 +++ vendor/rayon-core/tests/scope_join.rs | 45 ++++++++++++ vendor/rayon-core/tests/scoped_threadpool.rs | 96 +++++++++++++++++++++++++ vendor/rayon-core/tests/simple_panic.rs | 7 ++ vendor/rayon-core/tests/stack_overflow_crash.rs | 82 +++++++++++++++++++++ 6 files changed, 253 insertions(+) create mode 100644 vendor/rayon-core/tests/double_init_fail.rs create mode 100644 vendor/rayon-core/tests/init_zero_threads.rs create mode 100644 vendor/rayon-core/tests/scope_join.rs create mode 100644 vendor/rayon-core/tests/scoped_threadpool.rs create mode 100644 vendor/rayon-core/tests/simple_panic.rs create mode 100644 vendor/rayon-core/tests/stack_overflow_crash.rs (limited to 'vendor/rayon-core/tests') diff --git a/vendor/rayon-core/tests/double_init_fail.rs b/vendor/rayon-core/tests/double_init_fail.rs new file mode 100644 index 000000000..ea06bf0e1 --- /dev/null +++ b/vendor/rayon-core/tests/double_init_fail.rs @@ -0,0 +1,14 @@ +use rayon_core::ThreadPoolBuilder; +use std::error::Error; + +#[test] +fn double_init_fail() { + let result1 = ThreadPoolBuilder::new().build_global(); + assert_eq!(result1.unwrap(), ()); + let err = ThreadPoolBuilder::new().build_global().unwrap_err(); + assert!(err.source().is_none()); + assert_eq!( + err.to_string(), + "The global thread pool has already been initialized.", + ); +} diff --git a/vendor/rayon-core/tests/init_zero_threads.rs b/vendor/rayon-core/tests/init_zero_threads.rs new file mode 100644 index 000000000..ebd73c585 --- /dev/null +++ b/vendor/rayon-core/tests/init_zero_threads.rs @@ -0,0 +1,9 @@ +use rayon_core::ThreadPoolBuilder; + +#[test] +fn init_zero_threads() { + ThreadPoolBuilder::new() + .num_threads(0) + .build_global() + .unwrap(); +} diff --git a/vendor/rayon-core/tests/scope_join.rs b/vendor/rayon-core/tests/scope_join.rs new file mode 100644 index 000000000..9d88133bc --- /dev/null +++ b/vendor/rayon-core/tests/scope_join.rs @@ -0,0 +1,45 @@ +/// Test that one can emulate join with `scope`: +fn pseudo_join(f: F, g: G) +where + F: FnOnce() + Send, + G: FnOnce() + Send, +{ + rayon_core::scope(|s| { + s.spawn(|_| g()); + f(); + }); +} + +fn quick_sort(v: &mut [T]) { + if v.len() <= 1 { + return; + } + + let mid = partition(v); + let (lo, hi) = v.split_at_mut(mid); + pseudo_join(|| quick_sort(lo), || quick_sort(hi)); +} + +fn partition(v: &mut [T]) -> usize { + let pivot = v.len() - 1; + let mut i = 0; + for j in 0..pivot { + if v[j] <= v[pivot] { + v.swap(i, j); + i += 1; + } + } + v.swap(i, pivot); + i +} + +fn is_sorted(v: &[T]) -> bool { + (1..v.len()).all(|i| v[i - 1] <= v[i]) +} + +#[test] +fn scope_join() { + let mut v: Vec = (0..256).rev().collect(); + quick_sort(&mut v); + assert!(is_sorted(&v)); +} diff --git a/vendor/rayon-core/tests/scoped_threadpool.rs b/vendor/rayon-core/tests/scoped_threadpool.rs new file mode 100644 index 000000000..db3d0b874 --- /dev/null +++ b/vendor/rayon-core/tests/scoped_threadpool.rs @@ -0,0 +1,96 @@ +use crossbeam_utils::thread; +use rayon_core::ThreadPoolBuilder; + +#[derive(PartialEq, Eq, Debug)] +struct Local(i32); + +scoped_tls::scoped_thread_local!(static LOCAL: Local); + +#[test] +fn missing_scoped_tls() { + LOCAL.set(&Local(42), || { + let pool = ThreadPoolBuilder::new() + .build() + .expect("thread pool created"); + + // `LOCAL` is not set in the pool. + pool.install(|| { + assert!(!LOCAL.is_set()); + }); + }); +} + +#[test] +fn spawn_scoped_tls_threadpool() { + LOCAL.set(&Local(42), || { + LOCAL.with(|x| { + thread::scope(|scope| { + let pool = ThreadPoolBuilder::new() + .spawn_handler(move |thread| { + scope + .builder() + .spawn(move |_| { + // Borrow the same local value in the thread pool. + LOCAL.set(x, || thread.run()) + }) + .map(|_| ()) + }) + .build() + .expect("thread pool created"); + + // The pool matches our local value. + pool.install(|| { + assert!(LOCAL.is_set()); + LOCAL.with(|y| { + assert_eq!(x, y); + }); + }); + + // If we change our local value, the pool is not affected. + LOCAL.set(&Local(-1), || { + pool.install(|| { + assert!(LOCAL.is_set()); + LOCAL.with(|y| { + assert_eq!(x, y); + }); + }); + }); + }) + .expect("scope threads ok"); + // `thread::scope` will wait for the threads to exit before returning. + }); + }); +} + +#[test] +fn build_scoped_tls_threadpool() { + LOCAL.set(&Local(42), || { + LOCAL.with(|x| { + ThreadPoolBuilder::new() + .build_scoped( + move |thread| LOCAL.set(x, || thread.run()), + |pool| { + // The pool matches our local value. + pool.install(|| { + assert!(LOCAL.is_set()); + LOCAL.with(|y| { + assert_eq!(x, y); + }); + }); + + // If we change our local value, the pool is not affected. + LOCAL.set(&Local(-1), || { + pool.install(|| { + assert!(LOCAL.is_set()); + LOCAL.with(|y| { + assert_eq!(x, y); + }); + }); + }); + }, + ) + .expect("thread pool created"); + // Internally, `crossbeam::scope` will wait for the threads to exit before returning. + }); + }); +} diff --git a/vendor/rayon-core/tests/simple_panic.rs b/vendor/rayon-core/tests/simple_panic.rs new file mode 100644 index 000000000..2564482a4 --- /dev/null +++ b/vendor/rayon-core/tests/simple_panic.rs @@ -0,0 +1,7 @@ +use rayon_core::join; + +#[test] +#[should_panic(expected = "should panic")] +fn simple_panic() { + join(|| {}, || panic!("should panic")); +} diff --git a/vendor/rayon-core/tests/stack_overflow_crash.rs b/vendor/rayon-core/tests/stack_overflow_crash.rs new file mode 100644 index 000000000..61288982c --- /dev/null +++ b/vendor/rayon-core/tests/stack_overflow_crash.rs @@ -0,0 +1,82 @@ +use rayon_core::ThreadPoolBuilder; + +use std::env; +use std::process::Command; + +#[cfg(target_os = "linux")] +use std::os::unix::process::ExitStatusExt; + +fn force_stack_overflow(depth: u32) { + let _buffer = [0u8; 1024 * 1024]; + if depth > 0 { + force_stack_overflow(depth - 1); + } +} + +#[cfg(unix)] +fn disable_core() { + unsafe { + libc::setrlimit( + libc::RLIMIT_CORE, + &libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }, + ); + } +} + +#[cfg(unix)] +fn overflow_code() -> Option { + None +} + +#[cfg(windows)] +fn overflow_code() -> Option { + use std::os::windows::process::ExitStatusExt; + use std::process::ExitStatus; + + ExitStatus::from_raw(0xc00000fd /*STATUS_STACK_OVERFLOW*/).code() +} + +fn main() { + if env::args().len() == 1 { + // first check that the recursivecall actually causes a stack overflow, and does not get optimized away + { + let status = Command::new(env::current_exe().unwrap()) + .arg("8") + .status() + .unwrap(); + + #[cfg(any(unix, windows))] + assert_eq!(status.code(), overflow_code()); + + #[cfg(target_os = "linux")] + assert!( + status.signal() == Some(11 /*SIGABRT*/) || status.signal() == Some(6 /*SIGSEGV*/) + ); + } + + // now run with a larger stack and verify correct operation + { + let status = Command::new(env::current_exe().unwrap()) + .arg("48") + .status() + .unwrap(); + assert_eq!(status.code(), Some(0)); + #[cfg(target_os = "linux")] + assert_eq!(status.signal(), None); + } + } else { + let stack_size_in_mb: usize = env::args().nth(1).unwrap().parse().unwrap(); + let pool = ThreadPoolBuilder::new() + .stack_size(stack_size_in_mb * 1024 * 1024) + .build() + .unwrap(); + pool.install(|| { + #[cfg(unix)] + disable_core(); + force_stack_overflow(32); + }); + } +} -- cgit v1.2.3