pthread: test: facilitate dynamically allocated thread stacks
Tests for dynamically allocated POSIX thread stacks. Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This commit is contained in:
parent
115efa2e35
commit
5a28297cf3
|
@ -1,6 +1,6 @@
|
|||
CONFIG_PTHREAD_IPC=y
|
||||
CONFIG_POSIX_API=y
|
||||
CONFIG_MAX_PTHREAD_COUNT=20
|
||||
CONFIG_MAX_PTHREAD_COUNT=10
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_SEM_VALUE_MAX=32767
|
||||
|
|
|
@ -216,6 +216,9 @@ void *thread_top_term(void *p1)
|
|||
}
|
||||
|
||||
if (id >= 2) {
|
||||
if (IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
|
||||
zassert_false(pthread_detach(self), "failed to set detach state");
|
||||
}
|
||||
ret = pthread_detach(self);
|
||||
if (id == 2) {
|
||||
zassert_equal(ret, EINVAL, "re-detached thread!");
|
||||
|
@ -345,8 +348,13 @@ ZTEST(posix_apis, test_pthread_execution)
|
|||
getschedparam.sched_priority,
|
||||
"scheduling priorities do not match!");
|
||||
|
||||
ret = pthread_create(&newthread[i], &attr[i], thread_top_exec,
|
||||
INT_TO_POINTER(i));
|
||||
if (IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
|
||||
ret = pthread_create(&newthread[i], NULL, thread_top_exec,
|
||||
INT_TO_POINTER(i));
|
||||
} else {
|
||||
ret = pthread_create(&newthread[i], &attr[i], thread_top_exec,
|
||||
INT_TO_POINTER(i));
|
||||
}
|
||||
|
||||
/* TESTPOINT: Check if thread is created successfully */
|
||||
zassert_false(ret, "Number of threads exceed max limit");
|
||||
|
@ -500,8 +508,13 @@ ZTEST(posix_apis, test_pthread_termination)
|
|||
schedparam.sched_priority = 2;
|
||||
pthread_attr_setschedparam(&attr[i], &schedparam);
|
||||
pthread_attr_setstack(&attr[i], &stack_t[i][0], STACKS);
|
||||
ret = pthread_create(&newthread[i], &attr[i], thread_top_term,
|
||||
INT_TO_POINTER(i));
|
||||
if (IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
|
||||
ret = pthread_create(&newthread[i], NULL, thread_top_term,
|
||||
INT_TO_POINTER(i));
|
||||
} else {
|
||||
ret = pthread_create(&newthread[i], &attr[i], thread_top_term,
|
||||
INT_TO_POINTER(i));
|
||||
}
|
||||
|
||||
zassert_false(ret, "Not enough space to create new thread");
|
||||
}
|
||||
|
@ -571,8 +584,10 @@ ZTEST(posix_apis, test_pthread_create_negative)
|
|||
pthread_attr_t attr1;
|
||||
|
||||
/* create pthread without attr initialized */
|
||||
ret = pthread_create(&pthread1, NULL, create_thread1, (void *)1);
|
||||
zassert_equal(ret, EINVAL, "create thread with NULL successful");
|
||||
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
|
||||
ret = pthread_create(&pthread1, NULL, create_thread1, (void *)1);
|
||||
zassert_equal(ret, EAGAIN, "create thread with NULL successful");
|
||||
}
|
||||
|
||||
/* initialized attr without set stack to create thread */
|
||||
ret = pthread_attr_init(&attr1);
|
||||
|
@ -777,3 +792,23 @@ ZTEST(posix_apis, test_pthread_equal)
|
|||
zassert_true(pthread_equal(pthread_self(), pthread_self()));
|
||||
zassert_false(pthread_equal(pthread_self(), (pthread_t)4242));
|
||||
}
|
||||
|
||||
static void *fun(void *arg)
|
||||
{
|
||||
*((uint32_t *)arg) = 0xB105F00D;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZTEST(posix_apis, test_pthread_dynamic_stacks)
|
||||
{
|
||||
pthread_t th;
|
||||
uint32_t x = 0;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) {
|
||||
ztest_test_skip();
|
||||
}
|
||||
|
||||
zassert_ok(pthread_create(&th, NULL, fun, &x));
|
||||
zassert_ok(pthread_join(th, NULL));
|
||||
zassert_equal(0xB105F00D, x);
|
||||
}
|
||||
|
|
|
@ -86,3 +86,12 @@ tests:
|
|||
portability.posix.common.signal.big_nsig:
|
||||
extra_configs:
|
||||
- CONFIG_POSIX_RTSIG_MAX=1024
|
||||
portability.posix.common.dynamic_stack:
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
- qemu_riscv64
|
||||
extra_configs:
|
||||
- CONFIG_DYNAMIC_THREAD=y
|
||||
- CONFIG_THREAD_STACK_INFO=y
|
||||
- CONFIG_DYNAMIC_THREAD_POOL_SIZE=5
|
||||
- CONFIG_HEAP_MEM_POOL_SIZE=16384
|
||||
|
|
Loading…
Reference in a new issue