Skip to content

Commit 4bac287

Browse files
fujitafbq
authored andcommitted
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
1 parent 06bd0e5 commit 4bac287

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

rust/kernel/sync/atomic/predefine.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,20 @@ mod tests {
199199
assert_eq!(v + 25, x.load(Relaxed));
200200
});
201201
}
202+
203+
#[test]
204+
fn atomic_bool_tests() {
205+
let x = Atomic::new(false);
206+
207+
assert_eq!(false, x.load(Relaxed));
208+
x.store(true, Relaxed);
209+
assert_eq!(true, x.load(Relaxed));
210+
211+
assert_eq!(true, x.xchg(false, Relaxed));
212+
assert_eq!(false, x.load(Relaxed));
213+
214+
assert_eq!(Err(false), x.cmpxchg(true, true, Relaxed));
215+
assert_eq!(false, x.load(Relaxed));
216+
assert_eq!(Ok(false), x.cmpxchg(false, true, Full));
217+
}
202218
}

0 commit comments

Comments
 (0)