From: FUJITA Tomonori Date: Thu, 1 Jan 2026 03:49:22 +0000 (+0900) Subject: rust: sync: atomic: Add atomic bool tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bac28727a2b3f33e6375aeafdf31df67deff5d0;p=thirdparty%2Fkernel%2Flinux.git rust: sync: atomic: Add atomic bool tests Add tests for Atomic operations. Atomic does not fit into the existing u8/16/32/64 tests so introduce a dedicated test for it. Signed-off-by: FUJITA Tomonori Reviewed-by: Gary Guo Signed-off-by: Boqun Feng Link: https://patch.msgid.link/20260101034922.2020334-3-fujita.tomonori@gmail.com --- diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs index 3fc99174b0869..42067c6a266cb 100644 --- a/rust/kernel/sync/atomic/predefine.rs +++ b/rust/kernel/sync/atomic/predefine.rs @@ -199,4 +199,20 @@ mod tests { assert_eq!(v + 25, x.load(Relaxed)); }); } + + #[test] + fn atomic_bool_tests() { + let x = Atomic::new(false); + + assert_eq!(false, x.load(Relaxed)); + x.store(true, Relaxed); + assert_eq!(true, x.load(Relaxed)); + + assert_eq!(true, x.xchg(false, Relaxed)); + assert_eq!(false, x.load(Relaxed)); + + assert_eq!(Err(false), x.cmpxchg(true, true, Relaxed)); + assert_eq!(false, x.load(Relaxed)); + assert_eq!(Ok(false), x.cmpxchg(false, true, Full)); + } }