]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: sync: atomic: Add atomic bool tests
authorFUJITA Tomonori <fujita.tomonori@gmail.com>
Thu, 1 Jan 2026 03:49:22 +0000 (12:49 +0900)
committerBoqun Feng <boqun.feng@gmail.com>
Fri, 9 Jan 2026 11:01:41 +0000 (19:01 +0800)
Add tests for Atomic<bool> operations.

Atomic<bool> does not fit into the existing u8/16/32/64 tests so
introduce a dedicated test for it.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20260101034922.2020334-3-fujita.tomonori@gmail.com
rust/kernel/sync/atomic/predefine.rs

index 3fc99174b086917c0ff57aa97dca1348e02757e0..42067c6a266cb9a00f61b0d2eb94458dc474bac9 100644 (file)
@@ -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));
+    }
 }