Skip to content

Commit

Permalink
tests/unittests: tests-ztimer: add ztimer_is_set() regression test
Browse files Browse the repository at this point in the history
(cherry picked from commit 20981e5)
  • Loading branch information
kaspar030 committed Apr 22, 2021
1 parent 3811dd8 commit e543b37
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/unittests/tests-ztimer/tests-ztimer-mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,41 @@ static void test_ztimer_mock_set16(void)
TEST_ASSERT_EQUAL_INT(0x100207d2, now);
}

/**
* @brief Testing ztimer_is_set()
*/
static void test_ztimer_mock_is_set(void)
{
ztimer_mock_t zmock;
ztimer_clock_t *z = &zmock.super;

/* Basic sanity test of the mock implementation */
ztimer_mock_init(&zmock, 32);

uint32_t count = 0;
ztimer_t alarm = { .callback = cb_incr, .arg = &count, };
ztimer_t alarm2 = { .callback = cb_incr, .arg = &count, };

ztimer_set(z, &alarm, 1000);
ztimer_set(z, &alarm2, 2000);

TEST_ASSERT_EQUAL_INT(0, count);
TEST_ASSERT(ztimer_is_set(z, &alarm));
TEST_ASSERT(ztimer_is_set(z, &alarm2));

ztimer_mock_advance(&zmock, 1000);

TEST_ASSERT_EQUAL_INT(1, count);
TEST_ASSERT(!ztimer_is_set(z, &alarm));
TEST_ASSERT(ztimer_is_set(z, &alarm2));

ztimer_mock_advance(&zmock, 1000);

TEST_ASSERT_EQUAL_INT(2, count);
TEST_ASSERT(!ztimer_is_set(z, &alarm));
TEST_ASSERT(!ztimer_is_set(z, &alarm2));
}

Test *tests_ztimer_mock_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
Expand All @@ -258,6 +293,7 @@ Test *tests_ztimer_mock_tests(void)
new_TestFixture(test_ztimer_mock_now3),
new_TestFixture(test_ztimer_mock_set32),
new_TestFixture(test_ztimer_mock_set16),
new_TestFixture(test_ztimer_mock_is_set),
};

EMB_UNIT_TESTCALLER(ztimer_tests, NULL, NULL, fixtures);
Expand Down

0 comments on commit e543b37

Please sign in to comment.