mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 06:23:53 +01:00
tests/bitarithm_timings: add bitarithm_test_and_clear() to the test
This commit is contained in:
parent
a8904edd7d
commit
74bbb87f78
@ -40,6 +40,15 @@
|
||||
#define TIMEOUT (TIMEOUT_S * US_PER_SEC)
|
||||
#define PER_ITERATION (4)
|
||||
|
||||
#if ARCH_32_BIT
|
||||
#define TEST_AND_CLEAR_TEST_MASK_0 (0xA2101045UL)
|
||||
#define TEST_AND_CLEAR_TEST_MASK_1 (0x22101044UL)
|
||||
#else
|
||||
#define TEST_AND_CLEAR_TEST_MASK_0 (0x9045UL)
|
||||
#define TEST_AND_CLEAR_TEST_MASK_1 (0x1244UL)
|
||||
|
||||
#endif
|
||||
|
||||
static atomic_bool done;
|
||||
|
||||
static void callback(void *unused)
|
||||
@ -84,6 +93,36 @@ static void run_test(const char *name, unsigned (*test)(unsigned))
|
||||
printf("+ %s: %lu iterations per second\r\n", name, (4*PER_ITERATION) * count / TIMEOUT_S);
|
||||
}
|
||||
|
||||
static unsigned do_test_and_clear(unsigned state)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
unsigned found = 0;
|
||||
|
||||
while (state) {
|
||||
state = bitarithm_test_and_clear(state, &index);
|
||||
found |= 1 << index;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static void run_test_test_and_clear(void)
|
||||
{
|
||||
unsigned long count = 0;
|
||||
atomic_store(&done, false);
|
||||
|
||||
xtimer_t xtimer = { .callback = callback };
|
||||
xtimer_set(&xtimer, TIMEOUT);
|
||||
|
||||
do {
|
||||
assert(do_test_and_clear(TEST_AND_CLEAR_TEST_MASK_0) == TEST_AND_CLEAR_TEST_MASK_0);
|
||||
assert(do_test_and_clear(TEST_AND_CLEAR_TEST_MASK_1) == TEST_AND_CLEAR_TEST_MASK_1);
|
||||
++count;
|
||||
} while (atomic_load(&done) == false);
|
||||
|
||||
printf("+ %s: %lu iterations per second\r\n", "bitarithm_test_and_clear", 2 * count / TIMEOUT_S);
|
||||
}
|
||||
|
||||
#define run_test(test) run_test(#test, test)
|
||||
|
||||
int main(void)
|
||||
@ -93,6 +132,7 @@ int main(void)
|
||||
run_test(bitarithm_msb);
|
||||
run_test(bitarithm_lsb);
|
||||
run_test(bitarithm_bits_set);
|
||||
run_test_test_and_clear();
|
||||
|
||||
printf("Done.\r\n");
|
||||
return 0;
|
||||
|
||||
@ -15,6 +15,7 @@ def testfunc(child):
|
||||
child.expect(r'\+ bitarithm_msb: \d+ iterations per second')
|
||||
child.expect(r'\+ bitarithm_lsb: \d+ iterations per second')
|
||||
child.expect(r'\+ bitarithm_bits_set: \d+ iterations per second')
|
||||
child.expect(r'\+ bitarithm_test_and_clear: \d+ iterations per second')
|
||||
child.expect_exact("Done.")
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user