Skip to content

Commit

Permalink
tests: Add more test cases for load/store/swap
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Nov 26, 2024
1 parent 2147fb2 commit ff7d45f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ macro_rules! __test_atomic_int_load_store {
VAR.store(10, store_order);
let a = <$atomic_type>::new(1);
assert_eq!(a.load(load_order), 1);
a.store(2, store_order);
assert_eq!(a.load(load_order), 2);
a.store($int_type::MIN, store_order);
assert_eq!(a.load(load_order), $int_type::MIN);
a.store($int_type::MAX, store_order);
assert_eq!(a.load(load_order), $int_type::MAX);
}
}
};
Expand Down Expand Up @@ -276,7 +278,9 @@ macro_rules! __test_atomic_int {
test_swap_ordering(|order| a.swap(5, order));
for &order in &helper::SWAP_ORDERINGS {
assert_eq!(a.swap(10, order), 5);
assert_eq!(a.swap(5, order), 10);
assert_eq!(a.swap($int_type::MIN, order), 5);
assert_eq!(a.swap($int_type::MAX, order), $int_type::MIN);
assert_eq!(a.swap(5, order), $int_type::MAX);
}
}
#[test]
Expand Down
12 changes: 8 additions & 4 deletions tests/api-test/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ macro_rules! __test_atomic_int {
VAR.store(10, store_order);
let a = <$atomic_type>::new(1);
assert_eq!(a.load(load_order), 1);
a.store(2, store_order);
assert_eq!(a.load(load_order), 2);
a.store($int_type::MIN, store_order);
assert_eq!(a.load(load_order), $int_type::MIN);
a.store($int_type::MAX, store_order);
assert_eq!(a.load(load_order), $int_type::MAX);
}
}
__run_test!(swap);
fn swap() {
let a = <$atomic_type>::new(5);
for &order in &helper::SWAP_ORDERINGS {
let a = <$atomic_type>::new(5);
assert_eq!(a.swap(10, order), 5);
assert_eq!(a.swap(5, order), 10);
assert_eq!(a.swap($int_type::MIN, order), 5);
assert_eq!(a.swap($int_type::MAX, order), $int_type::MIN);
assert_eq!(a.swap(5, order), $int_type::MAX);
}
}
__run_test!(compare_exchange);
Expand Down

0 comments on commit ff7d45f

Please sign in to comment.