tests: clock: tests for k_cycle_get_64
This change adds tests for 64-bit cycle counters. Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This commit is contained in:
parent
918a574c88
commit
964b153f96
|
@ -83,7 +83,7 @@ void test_clock_uptime(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Test clock cycle functionality
|
||||
* @brief Test 32-bit clock cycle functionality
|
||||
*
|
||||
* @details
|
||||
* Test Objectve:
|
||||
|
@ -122,7 +122,7 @@ void test_clock_uptime(void)
|
|||
* @see k_cycle_get_32(), k_uptime_get_32()
|
||||
*/
|
||||
|
||||
void test_clock_cycle(void)
|
||||
void test_clock_cycle_32(void)
|
||||
{
|
||||
uint32_t c32, c0, c1, t32;
|
||||
|
||||
|
@ -160,6 +160,39 @@ void test_clock_cycle(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test 64-bit clock cycle functionality
|
||||
*/
|
||||
void test_clock_cycle_64(void)
|
||||
{
|
||||
uint32_t d32;
|
||||
uint64_t d64;
|
||||
uint32_t t32[2];
|
||||
uint64_t t64[2];
|
||||
|
||||
if (!IS_ENABLED(CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER)) {
|
||||
ztest_test_skip();
|
||||
}
|
||||
|
||||
t64[0] = k_cycle_get_64();
|
||||
t32[0] = k_cycle_get_32();
|
||||
|
||||
k_msleep(1);
|
||||
|
||||
t32[1] = k_cycle_get_32();
|
||||
t64[1] = k_cycle_get_64();
|
||||
|
||||
d32 = MIN(t32[1] - t32[0], t32[0] - t32[1]);
|
||||
d64 = MIN(t64[1] - t64[0], t64[1] - t64[0]);
|
||||
|
||||
zassert_true(d64 >= d32,
|
||||
"k_cycle_get() (64-bit): d64: %" PRIu64 " < d32: %u", d64, d32);
|
||||
|
||||
zassert_true(d64 < (d32 << 1),
|
||||
"k_cycle_get() (64-bit): d64: %" PRIu64 " >= 2 * d32: %u",
|
||||
d64, (d32 << 1));
|
||||
}
|
||||
|
||||
/*
|
||||
*help function
|
||||
*/
|
||||
|
|
|
@ -37,7 +37,8 @@ extern void test_threads_access_atomic(void);
|
|||
extern void test_errno(void);
|
||||
extern void test_printk(void);
|
||||
extern void test_timeout_order(void);
|
||||
extern void test_clock_cycle(void);
|
||||
extern void test_clock_cycle_32(void);
|
||||
extern void test_clock_cycle_64(void);
|
||||
extern void test_clock_uptime(void);
|
||||
extern void test_ms_time_duration(void);
|
||||
extern void test_multilib(void);
|
||||
|
@ -156,7 +157,8 @@ void test_main(void)
|
|||
ztest_unit_test(test_printk),
|
||||
ztest_1cpu_unit_test(test_timeout_order),
|
||||
ztest_user_unit_test(test_clock_uptime),
|
||||
ztest_unit_test(test_clock_cycle),
|
||||
ztest_unit_test(test_clock_cycle_32),
|
||||
ztest_unit_test(test_clock_cycle_64),
|
||||
ztest_unit_test(test_version),
|
||||
ztest_unit_test(test_multilib),
|
||||
ztest_unit_test(test_thread_context),
|
||||
|
|
Loading…
Reference in a new issue