tests: posix: add tests for pthread_testcancel()
Add tests for pthread_testcancel() signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
This commit is contained in:
parent
fe5806aff0
commit
042b522506
|
@ -487,6 +487,46 @@ ZTEST(pthread, test_pthread_cleanup)
|
||||||
zassert_ok(pthread_join(th, NULL));
|
zassert_ok(pthread_join(th, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool testcancel_ignored;
|
||||||
|
static bool testcancel_failed;
|
||||||
|
|
||||||
|
static void *test_pthread_cancel_fn(void *arg)
|
||||||
|
{
|
||||||
|
zassert_ok(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL));
|
||||||
|
|
||||||
|
testcancel_ignored = false;
|
||||||
|
|
||||||
|
/* this should be ignored */
|
||||||
|
pthread_testcancel();
|
||||||
|
|
||||||
|
testcancel_ignored = true;
|
||||||
|
|
||||||
|
/* this will mark it pending */
|
||||||
|
zassert_ok(pthread_cancel(pthread_self()));
|
||||||
|
|
||||||
|
/* enable the thread to be cancelled */
|
||||||
|
zassert_ok(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL));
|
||||||
|
|
||||||
|
testcancel_failed = false;
|
||||||
|
|
||||||
|
/* this should terminate the thread */
|
||||||
|
pthread_testcancel();
|
||||||
|
|
||||||
|
testcancel_failed = true;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(pthread, test_pthread_testcancel)
|
||||||
|
{
|
||||||
|
pthread_t th;
|
||||||
|
|
||||||
|
zassert_ok(pthread_create(&th, NULL, test_pthread_cancel_fn, NULL));
|
||||||
|
zassert_ok(pthread_join(th, NULL));
|
||||||
|
zassert_true(testcancel_ignored);
|
||||||
|
zassert_false(testcancel_failed);
|
||||||
|
}
|
||||||
|
|
||||||
static void before(void *arg)
|
static void before(void *arg)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(arg);
|
ARG_UNUSED(arg);
|
||||||
|
|
|
@ -158,7 +158,7 @@ ZTEST(posix_headers, test_pthread_h)
|
||||||
zassert_not_null(pthread_spin_lock);
|
zassert_not_null(pthread_spin_lock);
|
||||||
zassert_not_null(pthread_spin_trylock);
|
zassert_not_null(pthread_spin_trylock);
|
||||||
zassert_not_null(pthread_spin_unlock);
|
zassert_not_null(pthread_spin_unlock);
|
||||||
/* zassert_not_null(pthread_testcancel); */ /* not implemented */
|
zassert_not_null(pthread_testcancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
Loading…
Reference in a new issue