Skip to content

Commit

Permalink
tests: posix: common: separate posix semaphore tests into a standalon…
Browse files Browse the repository at this point in the history
…e 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/semaphore app directory.

Signed-off-by: Marvin Ouma <[email protected]>
  • Loading branch information
Pancakem committed Nov 6, 2024
1 parent 3901591 commit af1f190
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/posix/semaphore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(posix_semaphore)

FILE(GLOB app_sources src/*.c)
zephyr_include_directories(${ZEPHYR_BASE}/lib/posix)

target_sources(app PRIVATE ${app_sources})

target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
11 changes: 11 additions & 0 deletions tests/posix/semaphore/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions tests/posix/semaphore/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_POSIX_API=y
CONFIG_ZTEST=y

CONFIG_POSIX_AEP_CHOICE_BASE=y
CONFIG_POSIX_SEMAPHORES=y
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -95,12 +94,14 @@ ZTEST(semaphore, 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);

Expand Down
25 changes: 25 additions & 0 deletions tests/posix/semaphore/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
common:
filter: not CONFIG_NATIVE_LIBC
tags:
- posix
- semaphore
# 1 tier0 platform per supported architecture
platform_key:
- arch
- simulation
tests:
portability.posix.semaphore:
min_flash: 64
min_ram: 32
portability.posix.semaphore.minimal:
extra_configs:
- CONFIG_MINIMAL_LIBC=y
portability.posix.semaphore.newlib:
filter: TOOLCHAIN_HAS_NEWLIB == 1
extra_configs:
- CONFIG_NEWLIB_LIBC=y
portability.posix.semaphore.picolibc:
tags: picolibc
filter: CONFIG_PICOLIBC_SUPPORTED
extra_configs:
- CONFIG_PICOLIBC=y

0 comments on commit af1f190

Please sign in to comment.