posix: add pthread specific data deallocation test
This commit adds test to assert that thread specific data is deallocated on thread termination. Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
This commit is contained in:
parent
044b702b90
commit
43f917111b
3 changed files with 42 additions and 0 deletions
|
@ -9,6 +9,8 @@ CONFIG_THREAD_NAME=y
|
||||||
CONFIG_DYNAMIC_THREAD=y
|
CONFIG_DYNAMIC_THREAD=y
|
||||||
CONFIG_THREAD_STACK_INFO=y
|
CONFIG_THREAD_STACK_INFO=y
|
||||||
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6
|
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6
|
||||||
|
CONFIG_POSIX_THREAD_KEYS_MAX=512
|
||||||
|
CONFIG_TEST_EXTRA_STACK_SIZE=4096
|
||||||
|
|
||||||
# for fnmatch()
|
# for fnmatch()
|
||||||
CONFIG_POSIX_C_LIB_EXT=y
|
CONFIG_POSIX_C_LIB_EXT=y
|
||||||
|
|
|
@ -144,6 +144,44 @@ ZTEST(key, test_correct_key_is_deleted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *setspecific_thread(void *count)
|
||||||
|
{
|
||||||
|
int value = 42;
|
||||||
|
int *alloc_count = count;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pthread_key_t key;
|
||||||
|
|
||||||
|
zassert_ok(pthread_key_create(&key, NULL), "failed to create key");
|
||||||
|
if (pthread_setspecific(key, &value) == ENOMEM) {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
*alloc_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(key, test_thread_specific_data_deallocation)
|
||||||
|
{
|
||||||
|
pthread_t thread;
|
||||||
|
static int alloc_count_t0;
|
||||||
|
static int alloc_count_t1;
|
||||||
|
|
||||||
|
zassert_ok(pthread_create(&thread, NULL, setspecific_thread, &alloc_count_t0),
|
||||||
|
"attempt to create thread failed");
|
||||||
|
zassert_ok(pthread_join(thread, NULL), "failed to join thread");
|
||||||
|
printk("first thread allocated %d keys", alloc_count_t0);
|
||||||
|
|
||||||
|
zassert_ok(pthread_create(&thread, NULL, setspecific_thread, &alloc_count_t1),
|
||||||
|
"attempt to create thread failed");
|
||||||
|
zassert_ok(pthread_join(thread, NULL), "failed to join thread");
|
||||||
|
printk("second thread allocated %d keys", alloc_count_t1);
|
||||||
|
|
||||||
|
zassert_equal(alloc_count_t0, alloc_count_t1,
|
||||||
|
"failed to deallocate thread specific data");
|
||||||
|
}
|
||||||
|
|
||||||
static void before(void *arg)
|
static void before(void *arg)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(arg);
|
ARG_UNUSED(arg);
|
||||||
|
|
|
@ -67,6 +67,8 @@ tests:
|
||||||
- CONFIG_DYNAMIC_THREAD=y
|
- CONFIG_DYNAMIC_THREAD=y
|
||||||
- CONFIG_THREAD_STACK_INFO=y
|
- CONFIG_THREAD_STACK_INFO=y
|
||||||
- CONFIG_HEAP_MEM_POOL_SIZE=16384
|
- CONFIG_HEAP_MEM_POOL_SIZE=16384
|
||||||
|
- CONFIG_POSIX_THREAD_KEYS_MAX=2048
|
||||||
|
- CONFIG_TEST_EXTRA_STACK_SIZE=16384
|
||||||
portability.posix.common.static_stack:
|
portability.posix.common.static_stack:
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_DYNAMIC_THREAD=n
|
- CONFIG_DYNAMIC_THREAD=n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue