Skip to content

Commit

Permalink
test: add test_thread_cnd_timedwait
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Mar 13, 2023
1 parent 67d7340 commit b987425
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ static const struct test tests_integration[] = {
TEST(test_tmr_jiffies),
TEST(test_tmr_jiffies_usec),
TEST(test_turn_thread),
TEST(test_thread_cnd_timedwait),
};


Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ int test_sys_getenv(void);
int test_tcp(void);
int test_telev(void);
int test_thread(void);
int test_thread_cnd_timedwait(void);
int test_tmr_jiffies(void);
int test_tmr_jiffies_usec(void);
int test_try_into(void);
Expand Down
36 changes: 36 additions & 0 deletions test/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,39 @@ int test_thread(void)
out:
return err;
}


int test_thread_cnd_timedwait(void)
{
cnd_t cnd;
mtx_t mtx;
struct timespec tp;
int err = 0;

cnd_init(&cnd);
mtx_init(&mtx, mtx_plain);

err = tmr_timespec_get(&tp, 100);
TEST_ERR(err);

mtx_lock(&mtx);

uint64_t start = tmr_jiffies();
int ret = cnd_timedwait(&cnd, &mtx, &tp);
TEST_EQUALS(thrd_timedout, ret);
uint64_t end = tmr_jiffies();

if (end - start < 100) {
err = ETIME;
TEST_ERR(err);
}

if (end - start > 500) {
err = ETIMEDOUT;
TEST_ERR(err);
}

out:
mtx_unlock(&mtx);
return err;
}

0 comments on commit b987425

Please sign in to comment.