From 5581e338067c5af7937f41d0b6ee55cfc8319cc0 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 6 Apr 2022 23:48:26 +0200 Subject: [PATCH] Add test for FUTEX_*_BITSET. --- tests/run-pass/concurrency/linux-futex.rs | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/run-pass/concurrency/linux-futex.rs b/tests/run-pass/concurrency/linux-futex.rs index 7ffe59e7a1b..fb7c022929b 100644 --- a/tests/run-pass/concurrency/linux-futex.rs +++ b/tests/run-pass/concurrency/linux-futex.rs @@ -160,6 +160,53 @@ fn wait_wake() { assert!((200..1000).contains(&start.elapsed().as_millis())); } +fn wait_wake_bitset() { + let start = Instant::now(); + + static FUTEX: i32 = 0; + + thread::spawn(move || { + thread::sleep(Duration::from_millis(200)); + unsafe { + assert_eq!(libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAKE_BITSET, + 10, // Wake up at most 10 threads. + 0, + 0, + 0b1001, // bitset + ), 0); // Didn't match any thread. + } + thread::sleep(Duration::from_millis(200)); + unsafe { + assert_eq!(libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAKE_BITSET, + 10, // Wake up at most 10 threads. + 0, + 0, + 0b0110, // bitset + ), 1); // Woken up one thread. + } + }); + + unsafe { + assert_eq!(libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAIT_BITSET, + 0, + ptr::null::(), + 0, + 0b0100, // bitset + ), 0); + } + + assert!((400..1000).contains(&start.elapsed().as_millis())); +} + fn main() { wake_nobody(); wake_dangling(); @@ -167,4 +214,5 @@ fn main() { wait_timeout(); wait_absolute_timeout(); wait_wake(); + wait_wake_bitset(); }