Skip to content

Commit f7633a5

Browse files
Pancakemnashif
authored andcommitted
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 <[email protected]>
1 parent ed5ce47 commit f7633a5

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

tests/posix/semaphores/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(posix_semaphores)
6+
7+
target_sources(app PRIVATE src/main.c)
8+
9+
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)

tests/posix/semaphores/Kconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2023, Meta
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config TEST_SEM_N_LOOPS
5+
int "Number of loops in semaphore test"
6+
range 16 1024
7+
default 32
8+
help
9+
This option is specific to semaphore.test_named_semaphore in semaphore.c
10+
11+
source "Kconfig.zephyr"

tests/posix/semaphores/prj.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_POSIX_API=y
2+
CONFIG_ZTEST=y
3+
4+
CONFIG_POSIX_AEP_CHOICE_BASE=y
5+
CONFIG_POSIX_SEMAPHORES=y

tests/posix/common/src/semaphore.c renamed to tests/posix/semaphores/src/main.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ static void semaphore_test(sem_t *sem)
4949
ret = pthread_create(&thread1, NULL, child_func, sem);
5050
zassert_equal(ret, 0, "Thread creation failed");
5151

52-
zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0,
53-
"clock_gettime failed");
52+
zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, "clock_gettime failed");
5453

5554
abstime.tv_sec += 5;
5655

@@ -72,15 +71,15 @@ static void semaphore_test(sem_t *sem)
7271
zassert_equal(sem_getvalue(sem, &val), 0);
7372
zassert_equal(val, 1);
7473

75-
zassert_equal(sem_destroy(sem), -1, "acquired semaphore"
74+
zassert_equal(sem_destroy(sem), -1,
75+
"acquired semaphore"
7676
" is destroyed");
7777
zassert_equal(errno, EBUSY);
7878

7979
/* TESTPOINT: take semaphore which is initialized with 1 */
8080
zassert_equal(sem_trywait(sem), 0);
8181

82-
zassert_equal(pthread_create(&thread2, NULL, child_func, sem), 0,
83-
"Thread creation failed");
82+
zassert_equal(pthread_create(&thread2, NULL, child_func, sem), 0, "Thread creation failed");
8483

8584
/* TESTPOINT: Wait and acquire semaphore till thread2 gives */
8685
zassert_equal(sem_wait(sem), 0, "sem_wait failed");
@@ -90,17 +89,19 @@ static void semaphore_test(sem_t *sem)
9089
zassert_ok(pthread_join(thread2, NULL));
9190
}
9291

93-
ZTEST(semaphore, test_semaphore)
92+
ZTEST(posix_semaphores, test_semaphore)
9493
{
9594
sem_t sema;
9695

9796
/* TESTPOINT: Call sem_post with invalid kobject */
98-
zassert_equal(sem_post(NULL), -1, "sem_post of"
97+
zassert_equal(sem_post(NULL), -1,
98+
"sem_post of"
9999
" invalid semaphore object didn't fail");
100100
zassert_equal(errno, EINVAL);
101101

102102
/* TESTPOINT: sem_destroy with invalid kobject */
103-
zassert_equal(sem_destroy(NULL), -1, "invalid"
103+
zassert_equal(sem_destroy(NULL), -1,
104+
"invalid"
104105
" semaphore is destroyed");
105106
zassert_equal(errno, EINVAL);
106107

@@ -141,7 +142,7 @@ static void *nsem_close_func(void *p)
141142
return NULL;
142143
}
143144

144-
ZTEST(semaphore, test_named_semaphore)
145+
ZTEST(posix_semaphores, test_named_semaphore)
145146
{
146147
pthread_t thread1, thread2;
147148
sem_t *sem1, *sem2, *different_sem1;
@@ -321,4 +322,4 @@ static void before(void *arg)
321322
}
322323
}
323324

324-
ZTEST_SUITE(semaphore, NULL, NULL, before, NULL, NULL);
325+
ZTEST_SUITE(posix_semaphores, NULL, NULL, before, NULL, NULL);

tests/posix/semaphores/testcase.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
common:
2+
filter: not CONFIG_NATIVE_LIBC
3+
tags:
4+
- posix
5+
- semaphores
6+
# 1 tier0 platform per supported architecture
7+
platform_key:
8+
- arch
9+
- simulation
10+
min_flash: 64
11+
min_ram: 32
12+
tests:
13+
portability.posix.semaphores: {}
14+
portability.posix.semaphores.minimal:
15+
extra_configs:
16+
- CONFIG_MINIMAL_LIBC=y
17+
portability.posix.semaphores.newlib:
18+
filter: TOOLCHAIN_HAS_NEWLIB == 1
19+
extra_configs:
20+
- CONFIG_NEWLIB_LIBC=y
21+
portability.posix.semaphores.picolibc:
22+
tags: picolibc
23+
filter: CONFIG_PICOLIBC_SUPPORTED
24+
extra_configs:
25+
- CONFIG_PICOLIBC=y

0 commit comments

Comments
 (0)