Skip to content

Commit

Permalink
test/thread: add thrd_equal testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Oct 21, 2024
1 parent 27d55ca commit d93b0fd
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
#include <re_dbg.h>


static int thread_equal(void *thrd)
{
thrd_t t = *(thrd_t *)thrd;

if (thrd_equal(t, thrd_current()))
return 0;

return EINVAL;
}


static int thread(void *id)
{
int n = *(int *)id;
Expand All @@ -27,24 +38,37 @@ static int thread(void *id)
int test_thread(void)
{
thrd_t thr;
thrd_t thr_main = thrd_current();
int err;
int id;

err = thread_create_name(&thr, "test1", NULL, NULL);
TEST_EQUALS(EINVAL, err);

id = 23;
id = 23;
err = thread_create_name(&thr, "test2", thread, (void *)&id);
TEST_ERR(err);
thrd_join(thr, &err);
TEST_EQUALS(thrd_error, err);

id = 42;
id = 42;
err = thread_create_name(&thr, "test3", thread, (void *)&id);
TEST_ERR(err);
thrd_join(thr, &err);
TEST_EQUALS(EPROTO, err);

err = thread_create_name(&thr, "test_not_equal", thread_equal,
&thr_main);
TEST_ERR(err);
thrd_join(thr, &err);
TEST_EQUALS(EINVAL, err);

err = thread_create_name(&thr, "test_equal", thread_equal, &thr);
TEST_ERR(err);
TEST_EQUALS(0, thrd_equal(thr, thrd_current()));
thrd_join(thr, &err);
TEST_EQUALS(0, err);

err = 0;

out:
Expand Down

0 comments on commit d93b0fd

Please sign in to comment.