tests: posix: common: separate posix threads_ext to standalone test
posix.common contains testsuites that can be separated into smaller groups of tests. This change moves pthread_attr into a singular testsuite at tests/posix/threads/ext app directory. Signed-off-by: Marvin Ouma <pancakesdeath@protonmail.com>
This commit is contained in:
parent
5d4353dc9a
commit
1a633609a0
6 changed files with 190 additions and 110 deletions
|
@ -43,64 +43,4 @@ ZTEST(mutex_attr, test_pthread_mutexattr_destroy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(mutex_attr, test_pthread_mutexattr_gettype)
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
pthread_mutexattr_t attr;
|
|
||||||
|
|
||||||
/* degenerate cases */
|
|
||||||
{
|
|
||||||
if (false) {
|
|
||||||
/* undefined behaviour */
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
}
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_gettype(NULL, NULL));
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_gettype(NULL, &type));
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_gettype(&attr, NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_init(&attr));
|
|
||||||
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
zassert_equal(type, PTHREAD_MUTEX_DEFAULT);
|
|
||||||
zassert_ok(pthread_mutexattr_destroy(&attr));
|
|
||||||
}
|
|
||||||
|
|
||||||
ZTEST(mutex_attr, test_pthread_mutexattr_settype)
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
pthread_mutexattr_t attr;
|
|
||||||
|
|
||||||
/* degenerate cases */
|
|
||||||
{
|
|
||||||
if (false) {
|
|
||||||
/* undefined behaviour */
|
|
||||||
zassert_equal(EINVAL,
|
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT));
|
|
||||||
}
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_settype(NULL, 42));
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_NORMAL));
|
|
||||||
zassert_equal(EINVAL, pthread_mutexattr_settype(&attr, 42));
|
|
||||||
}
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_init(&attr));
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT));
|
|
||||||
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
zassert_equal(type, PTHREAD_MUTEX_DEFAULT);
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL));
|
|
||||||
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
zassert_equal(type, PTHREAD_MUTEX_NORMAL);
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
|
|
||||||
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
zassert_equal(type, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
|
|
||||||
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
|
||||||
zassert_equal(type, PTHREAD_MUTEX_ERRORCHECK);
|
|
||||||
|
|
||||||
zassert_ok(pthread_mutexattr_destroy(&attr));
|
|
||||||
}
|
|
||||||
|
|
||||||
ZTEST_SUITE(mutex_attr, NULL, NULL, NULL, NULL, NULL);
|
ZTEST_SUITE(mutex_attr, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
|
@ -147,56 +147,6 @@ ZTEST(pthread_attr, test_pthread_attr_init_destroy)
|
||||||
/* note: attr is still valid and is destroyed in after() */
|
/* note: attr is still valid and is destroyed in after() */
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(pthread_attr, test_pthread_attr_getguardsize)
|
|
||||||
{
|
|
||||||
size_t guardsize;
|
|
||||||
|
|
||||||
/* degenerate cases */
|
|
||||||
{
|
|
||||||
if (false) {
|
|
||||||
/* undefined behaviour */
|
|
||||||
zassert_equal(pthread_attr_getguardsize(NULL, NULL), EINVAL);
|
|
||||||
zassert_equal(pthread_attr_getguardsize(NULL, &guardsize), EINVAL);
|
|
||||||
zassert_equal(pthread_attr_getguardsize(&uninit_attr, &guardsize), EINVAL);
|
|
||||||
}
|
|
||||||
zassert_equal(pthread_attr_getguardsize(&attr, NULL), EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
guardsize = BIOS_FOOD;
|
|
||||||
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
|
||||||
zassert_not_equal(guardsize, BIOS_FOOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZTEST(pthread_attr, test_pthread_attr_setguardsize)
|
|
||||||
{
|
|
||||||
size_t guardsize = CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT;
|
|
||||||
size_t sizes[] = {0, BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS / 2),
|
|
||||||
BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS)};
|
|
||||||
|
|
||||||
/* valid value */
|
|
||||||
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
|
||||||
|
|
||||||
/* degenerate cases */
|
|
||||||
{
|
|
||||||
if (false) {
|
|
||||||
/* undefined behaviour */
|
|
||||||
zassert_equal(pthread_attr_setguardsize(NULL, SIZE_MAX), EINVAL);
|
|
||||||
zassert_equal(pthread_attr_setguardsize(NULL, guardsize), EINVAL);
|
|
||||||
zassert_equal(pthread_attr_setguardsize((pthread_attr_t *)&uninit_attr,
|
|
||||||
guardsize),
|
|
||||||
EINVAL);
|
|
||||||
}
|
|
||||||
zassert_equal(pthread_attr_setguardsize(&attr, SIZE_MAX), EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
ARRAY_FOR_EACH(sizes, i) {
|
|
||||||
zassert_ok(pthread_attr_setguardsize(&attr, sizes[i]));
|
|
||||||
guardsize = ~sizes[i];
|
|
||||||
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
|
||||||
zassert_equal(guardsize, sizes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ZTEST(pthread_attr, test_pthread_attr_getschedparam)
|
ZTEST(pthread_attr, test_pthread_attr_getschedparam)
|
||||||
{
|
{
|
||||||
struct sched_param param = {
|
struct sched_param param = {
|
||||||
|
|
9
tests/posix/threads_ext/CMakeLists.txt
Normal file
9
tests/posix/threads_ext/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(posix_threads_ext)
|
||||||
|
|
||||||
|
target_sources(app PRIVATE src/main.c)
|
||||||
|
|
||||||
|
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
|
5
tests/posix/threads_ext/prj.conf
Normal file
5
tests/posix/threads_ext/prj.conf
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CONFIG_POSIX_API=y
|
||||||
|
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
CONFIG_POSIX_AEP_CHOICE_BASE=y
|
||||||
|
CONFIG_POSIX_THREADS_EXT=y
|
151
tests/posix/threads_ext/src/main.c
Normal file
151
tests/posix/threads_ext/src/main.c
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Meta
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include <zephyr/sys/util.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
#define BIOS_FOOD 0xB105F00D
|
||||||
|
#define SCHED_INVALID 4242
|
||||||
|
#define INVALID_DETACHSTATE 7373
|
||||||
|
|
||||||
|
static bool attr_valid;
|
||||||
|
static pthread_attr_t attr;
|
||||||
|
static const pthread_attr_t uninit_attr;
|
||||||
|
|
||||||
|
ZTEST(posix_threads_ext, test_pthread_attr_getguardsize)
|
||||||
|
{
|
||||||
|
size_t guardsize;
|
||||||
|
|
||||||
|
/* degenerate cases */
|
||||||
|
{
|
||||||
|
if (false) {
|
||||||
|
/* undefined behaviour */
|
||||||
|
zassert_equal(pthread_attr_getguardsize(NULL, NULL), EINVAL);
|
||||||
|
zassert_equal(pthread_attr_getguardsize(NULL, &guardsize), EINVAL);
|
||||||
|
zassert_equal(pthread_attr_getguardsize(&uninit_attr, &guardsize), EINVAL);
|
||||||
|
}
|
||||||
|
zassert_equal(pthread_attr_getguardsize(&attr, NULL), EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
guardsize = BIOS_FOOD;
|
||||||
|
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
||||||
|
zassert_not_equal(guardsize, BIOS_FOOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(posix_threads_ext, test_pthread_attr_setguardsize)
|
||||||
|
{
|
||||||
|
size_t guardsize = CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT;
|
||||||
|
size_t sizes[] = {0, BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS / 2),
|
||||||
|
BIT_MASK(CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS)};
|
||||||
|
|
||||||
|
/* valid value */
|
||||||
|
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
||||||
|
|
||||||
|
/* degenerate cases */
|
||||||
|
{
|
||||||
|
if (false) {
|
||||||
|
/* undefined behaviour */
|
||||||
|
zassert_equal(pthread_attr_setguardsize(NULL, SIZE_MAX), EINVAL);
|
||||||
|
zassert_equal(pthread_attr_setguardsize(NULL, guardsize), EINVAL);
|
||||||
|
zassert_equal(pthread_attr_setguardsize((pthread_attr_t *)&uninit_attr,
|
||||||
|
guardsize),
|
||||||
|
EINVAL);
|
||||||
|
}
|
||||||
|
zassert_equal(pthread_attr_setguardsize(&attr, SIZE_MAX), EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARRAY_FOR_EACH(sizes, i) {
|
||||||
|
zassert_ok(pthread_attr_setguardsize(&attr, sizes[i]));
|
||||||
|
guardsize = ~sizes[i];
|
||||||
|
zassert_ok(pthread_attr_getguardsize(&attr, &guardsize));
|
||||||
|
zassert_equal(guardsize, sizes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(posix_threads_ext, test_pthread_mutexattr_gettype)
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
|
||||||
|
/* degenerate cases */
|
||||||
|
{
|
||||||
|
if (false) {
|
||||||
|
/* undefined behaviour */
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
}
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_gettype(NULL, NULL));
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_gettype(NULL, &type));
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_gettype(&attr, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_init(&attr));
|
||||||
|
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
zassert_equal(type, PTHREAD_MUTEX_DEFAULT);
|
||||||
|
zassert_ok(pthread_mutexattr_destroy(&attr));
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(posix_threads_ext, test_pthread_mutexattr_settype)
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
|
||||||
|
/* degenerate cases */
|
||||||
|
{
|
||||||
|
if (false) {
|
||||||
|
/* undefined behaviour */
|
||||||
|
zassert_equal(EINVAL,
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT));
|
||||||
|
}
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_settype(NULL, 42));
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_NORMAL));
|
||||||
|
zassert_equal(EINVAL, pthread_mutexattr_settype(&attr, 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_init(&attr));
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT));
|
||||||
|
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
zassert_equal(type, PTHREAD_MUTEX_DEFAULT);
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL));
|
||||||
|
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
zassert_equal(type, PTHREAD_MUTEX_NORMAL);
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
|
||||||
|
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
zassert_equal(type, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
|
||||||
|
zassert_ok(pthread_mutexattr_gettype(&attr, &type));
|
||||||
|
zassert_equal(type, PTHREAD_MUTEX_ERRORCHECK);
|
||||||
|
|
||||||
|
zassert_ok(pthread_mutexattr_destroy(&attr));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void before(void *arg)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(arg);
|
||||||
|
|
||||||
|
zassert_ok(pthread_attr_init(&attr));
|
||||||
|
/* TODO: pthread_attr_init() should be sufficient to initialize a thread by itself */
|
||||||
|
/* zassert_ok(pthread_attr_setstack(&attr, &static_thread_stack, STATIC_THREAD_STACK_SIZE));
|
||||||
|
*/
|
||||||
|
attr_valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void after(void *arg)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(arg);
|
||||||
|
|
||||||
|
if (attr_valid) {
|
||||||
|
(void)pthread_attr_destroy(&attr);
|
||||||
|
attr_valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(posix_threads_ext, NULL, NULL, before, after, NULL);
|
25
tests/posix/threads_ext/testcase.yaml
Normal file
25
tests/posix/threads_ext/testcase.yaml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
common:
|
||||||
|
filter: not CONFIG_NATIVE_LIBC
|
||||||
|
tags:
|
||||||
|
- posix
|
||||||
|
- threads_ext
|
||||||
|
# 1 tier0 platform per supported architecture
|
||||||
|
platform_key:
|
||||||
|
- arch
|
||||||
|
- simulation
|
||||||
|
tests:
|
||||||
|
portability.posix.threads_ext:
|
||||||
|
min_flash: 64
|
||||||
|
min_ram: 32
|
||||||
|
portability.posix.threads_ext.minimal:
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_MINIMAL_LIBC=y
|
||||||
|
portability.posix.threads_ext.newlib:
|
||||||
|
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_NEWLIB_LIBC=y
|
||||||
|
portability.posix.threads_ext.picolibc:
|
||||||
|
tags: picolibc
|
||||||
|
filter: CONFIG_PICOLIBC_SUPPORTED
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_PICOLIBC=y
|
Loading…
Add table
Add a link
Reference in a new issue