mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
rust: sync: atomic: Add atomic bool tests
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
This commit is contained in:
parent
06bd0e52bf
commit
4bac28727a
|
|
@ -199,4 +199,20 @@ fn atomic_arithmetic_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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user