Skip to content

Commit

Permalink
tests: posix: test pthread_cleanup_push() / pop()
Browse files Browse the repository at this point in the history
Add a test for pthread_cleanup_push() and
pthread_cleanup_pop().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
  • Loading branch information
cfriedt committed Nov 27, 2023
1 parent 3ead0fb commit 7901655
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/posix/common/src/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,33 @@ ZTEST(posix_apis, test_pthread_join_detached)
/* need to allow this thread to be clean-up by the recycler */
k_msleep(500);
}

static void cleanup_handler(void *arg)
{
bool *boolp = (bool *)arg;

*boolp = true;
}

static void *test_pthread_cleanup_entry(void *arg)
{
bool executed[2] = {0};

pthread_cleanup_push(cleanup_handler, &executed[0]);
pthread_cleanup_push(cleanup_handler, &executed[1]);
pthread_cleanup_pop(false);
pthread_cleanup_pop(true);

zassert_true(executed[0]);
zassert_false(executed[1]);

return NULL;
}

ZTEST(posix_apis, test_pthread_cleanup)
{
pthread_t th;

zassert_ok(pthread_create(&th, NULL, test_pthread_cleanup_entry, NULL));
zassert_ok(pthread_join(th, NULL));
}

0 comments on commit 7901655

Please sign in to comment.