From f7633a55aa098de8409724f3a6211af4a4687101 Mon Sep 17 00:00:00 2001 From: Marvin Ouma Date: Tue, 5 Nov 2024 20:27:37 +0300 Subject: [PATCH] tests: posix: common: separate posix semaphores tests into standalone test posix.common contains testsuites that can be separated into smaller groups of tests. This change moves semaphore into a singular testsuite at tests/posix/semaphores app directory. Signed-off-by: Marvin Ouma --- tests/posix/semaphores/CMakeLists.txt | 9 +++++++ tests/posix/semaphores/Kconfig | 11 ++++++++ tests/posix/semaphores/prj.conf | 5 ++++ .../src/semaphore.c => semaphores/src/main.c} | 21 ++++++++-------- tests/posix/semaphores/testcase.yaml | 25 +++++++++++++++++++ 5 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 tests/posix/semaphores/CMakeLists.txt create mode 100644 tests/posix/semaphores/Kconfig create mode 100644 tests/posix/semaphores/prj.conf rename tests/posix/{common/src/semaphore.c => semaphores/src/main.c} (95%) create mode 100644 tests/posix/semaphores/testcase.yaml diff --git a/tests/posix/semaphores/CMakeLists.txt b/tests/posix/semaphores/CMakeLists.txt new file mode 100644 index 00000000000..b43570e197d --- /dev/null +++ b/tests/posix/semaphores/CMakeLists.txt @@ -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_semaphores) + +target_sources(app PRIVATE src/main.c) + +target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L) diff --git a/tests/posix/semaphores/Kconfig b/tests/posix/semaphores/Kconfig new file mode 100644 index 00000000000..8da58b91138 --- /dev/null +++ b/tests/posix/semaphores/Kconfig @@ -0,0 +1,11 @@ +# Copyright (c) 2023, Meta +# SPDX-License-Identifier: Apache-2.0 + +config TEST_SEM_N_LOOPS + int "Number of loops in semaphore test" + range 16 1024 + default 32 + help + This option is specific to semaphore.test_named_semaphore in semaphore.c + +source "Kconfig.zephyr" diff --git a/tests/posix/semaphores/prj.conf b/tests/posix/semaphores/prj.conf new file mode 100644 index 00000000000..5376678d6a9 --- /dev/null +++ b/tests/posix/semaphores/prj.conf @@ -0,0 +1,5 @@ +CONFIG_POSIX_API=y +CONFIG_ZTEST=y + +CONFIG_POSIX_AEP_CHOICE_BASE=y +CONFIG_POSIX_SEMAPHORES=y diff --git a/tests/posix/common/src/semaphore.c b/tests/posix/semaphores/src/main.c similarity index 95% rename from tests/posix/common/src/semaphore.c rename to tests/posix/semaphores/src/main.c index f9cfe8e8c94..228165fb131 100644 --- a/tests/posix/common/src/semaphore.c +++ b/tests/posix/semaphores/src/main.c @@ -49,8 +49,7 @@ static void semaphore_test(sem_t *sem) ret = pthread_create(&thread1, NULL, child_func, sem); zassert_equal(ret, 0, "Thread creation failed"); - zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, - "clock_gettime failed"); + zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, "clock_gettime failed"); abstime.tv_sec += 5; @@ -72,15 +71,15 @@ static void semaphore_test(sem_t *sem) zassert_equal(sem_getvalue(sem, &val), 0); zassert_equal(val, 1); - zassert_equal(sem_destroy(sem), -1, "acquired semaphore" + zassert_equal(sem_destroy(sem), -1, + "acquired semaphore" " is destroyed"); zassert_equal(errno, EBUSY); /* TESTPOINT: take semaphore which is initialized with 1 */ zassert_equal(sem_trywait(sem), 0); - zassert_equal(pthread_create(&thread2, NULL, child_func, sem), 0, - "Thread creation failed"); + zassert_equal(pthread_create(&thread2, NULL, child_func, sem), 0, "Thread creation failed"); /* TESTPOINT: Wait and acquire semaphore till thread2 gives */ zassert_equal(sem_wait(sem), 0, "sem_wait failed"); @@ -90,17 +89,19 @@ static void semaphore_test(sem_t *sem) zassert_ok(pthread_join(thread2, NULL)); } -ZTEST(semaphore, test_semaphore) +ZTEST(posix_semaphores, test_semaphore) { sem_t sema; /* TESTPOINT: Call sem_post with invalid kobject */ - zassert_equal(sem_post(NULL), -1, "sem_post of" + zassert_equal(sem_post(NULL), -1, + "sem_post of" " invalid semaphore object didn't fail"); zassert_equal(errno, EINVAL); /* TESTPOINT: sem_destroy with invalid kobject */ - zassert_equal(sem_destroy(NULL), -1, "invalid" + zassert_equal(sem_destroy(NULL), -1, + "invalid" " semaphore is destroyed"); zassert_equal(errno, EINVAL); @@ -141,7 +142,7 @@ static void *nsem_close_func(void *p) return NULL; } -ZTEST(semaphore, test_named_semaphore) +ZTEST(posix_semaphores, test_named_semaphore) { pthread_t thread1, thread2; sem_t *sem1, *sem2, *different_sem1; @@ -321,4 +322,4 @@ static void before(void *arg) } } -ZTEST_SUITE(semaphore, NULL, NULL, before, NULL, NULL); +ZTEST_SUITE(posix_semaphores, NULL, NULL, before, NULL, NULL); diff --git a/tests/posix/semaphores/testcase.yaml b/tests/posix/semaphores/testcase.yaml new file mode 100644 index 00000000000..92fdebbd992 --- /dev/null +++ b/tests/posix/semaphores/testcase.yaml @@ -0,0 +1,25 @@ +common: + filter: not CONFIG_NATIVE_LIBC + tags: + - posix + - semaphores + # 1 tier0 platform per supported architecture + platform_key: + - arch + - simulation + min_flash: 64 + min_ram: 32 +tests: + portability.posix.semaphores: {} + portability.posix.semaphores.minimal: + extra_configs: + - CONFIG_MINIMAL_LIBC=y + portability.posix.semaphores.newlib: + filter: TOOLCHAIN_HAS_NEWLIB == 1 + extra_configs: + - CONFIG_NEWLIB_LIBC=y + portability.posix.semaphores.picolibc: + tags: picolibc + filter: CONFIG_PICOLIBC_SUPPORTED + extra_configs: + - CONFIG_PICOLIBC=y