tests: atomic operation: add new test cases
add new test cases to illustrate the zephyr OS support an array of atomic variables, each bit of which can be modified. Signed-off-by: Ying ming <mingx.ying@intel.com>
This commit is contained in:
parent
0856e99155
commit
1b1d728a18
1 changed files with 15 additions and 0 deletions
|
@ -7,6 +7,9 @@
|
|||
#include <ztest.h>
|
||||
#include <sys/atomic.h>
|
||||
|
||||
/* an example of the number of atomic bit in an array */
|
||||
#define NUM_FLAG_BITS 100
|
||||
|
||||
/**
|
||||
* @addtogroup kernel_common_tests
|
||||
* @{
|
||||
|
@ -31,6 +34,8 @@ void test_atomic(void)
|
|||
atomic_val_t oldvalue;
|
||||
void *ptr_value, *old_ptr_value;
|
||||
|
||||
ATOMIC_DEFINE(flag_bits, NUM_FLAG_BITS) = {0};
|
||||
|
||||
target = 4;
|
||||
value = 5;
|
||||
oldvalue = 6;
|
||||
|
@ -188,6 +193,16 @@ void test_atomic(void)
|
|||
atomic_set_bit_to(&target, i, true);
|
||||
zassert_true(target == (orig | (1 << i)), "atomic_set_bit_to");
|
||||
}
|
||||
|
||||
/* ATOMIC_DEFINE */
|
||||
for (i = 0; i < NUM_FLAG_BITS; i++) {
|
||||
atomic_set_bit(flag_bits, i);
|
||||
zassert_true(!!atomic_test_bit(flag_bits, i) == !!(1),
|
||||
"Failed to set a single bit in an array of atomic variables");
|
||||
atomic_clear_bit(flag_bits, i);
|
||||
zassert_true(!!atomic_test_bit(flag_bits, i) == !!(0),
|
||||
"Failed to clear a single bit in an array of atomic variables");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue