1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

test/unittest: init ztimer, work around ztimer_t uint64_t

This commit is contained in:
Karl Fessel 2021-12-03 16:27:51 +01:00
parent 0433548346
commit d7d1f7acad
2 changed files with 14 additions and 4 deletions

View File

@ -10,6 +10,7 @@
#include "embUnit.h"
#include "xtimer.h"
#include "ztimer.h"
#include "test_utils/interactive_sync.h"
@ -25,6 +26,11 @@ int main(void)
{
test_utils_interactive_sync();
#if MODULE_ZTIMER_USEC || MODULE_ZTIMER_MSEC || MODULE_ZTIMER_SEC
/* auto_init is disabled, but some modules depends on this module being initialized */
ztimer_init();
#endif
#ifdef MODULE_XTIMER
/* auto_init is disabled, but some modules depends on this module being initialized */
xtimer_init();

View File

@ -120,7 +120,8 @@ static void test_ztimer_convert_muldiv64_set_speedup(void)
TEST_ASSERT_EQUAL_INT(4294968LU, ztimer_now(&zmock.super));
/* convert has overflowed ((2000 + 4294966000) % 2**32 = 704U)*/
TEST_ASSERT_EQUAL_INT(704LU, ztimer_now(z));
/* cast in case ztimer_now_t is uint64_t */
TEST_ASSERT_EQUAL_INT(704LU, (uint32_t) ztimer_now(z));
/* assert t hasn't triggered yet */
TEST_ASSERT_EQUAL_INT(0, val);
@ -180,21 +181,24 @@ static void test_ztimer_convert_muldiv64_set_slowdown(void)
ztimer_set(z, &t, 4294968);
ztimer_mock_advance(&zmock, UINT32_MAX);
TEST_ASSERT_EQUAL_INT(999, ztimer_now(&zmock.super));
/* cast in case ztimer_now_t is uint64_t */
TEST_ASSERT_EQUAL_INT(999, (uint32_t) ztimer_now(&zmock.super));
/* ztimer_now(z) is now at (UINT32_MAX + 1000)/1000) == 4294968 */
TEST_ASSERT_EQUAL_INT(4294968, ztimer_now(z));
TEST_ASSERT_EQUAL_INT(0, val);
ztimer_mock_advance(&zmock, 704);
TEST_ASSERT_EQUAL_INT(1703, ztimer_now(&zmock.super));
/* cast in case ztimer_now_t is uint64_t */
TEST_ASSERT_EQUAL_INT(1703, (uint32_t) ztimer_now(&zmock.super));
TEST_ASSERT_EQUAL_INT(4294969, ztimer_now(z));
/* assert that this has not triggered yet. */
TEST_ASSERT_EQUAL_INT(0, val);
ztimer_mock_advance(&zmock, 1);
TEST_ASSERT_EQUAL_INT(1704, ztimer_now(&zmock.super));
/* cast in case ztimer_now_t is uint64_t */
TEST_ASSERT_EQUAL_INT(1704, (uint32_t) ztimer_now(&zmock.super));
TEST_ASSERT_EQUAL_INT(4294969, ztimer_now(z));
TEST_ASSERT_EQUAL_INT(1, val);
val = 0;