diff --git a/doc/services/portability/posix.rst b/doc/services/portability/posix.rst index 6028ab508d71..83d8c78cbcec 100644 --- a/doc/services/portability/posix.rst +++ b/doc/services/portability/posix.rst @@ -376,16 +376,17 @@ required for error and event handling. pause(), raise(), sigaction(), - igaddset(), - sigdelset(), - sigemptyset(), - sigfillset(), - igismember(), + sigaddset(),yes + sigdelset(),yes + sigemptyset(),yes + sigfillset(),yes + sigismember(),yes signal(), sigpending(), sigprocmask(), igsuspend(), - sigwait() + sigwait(), + strsignal(),yes .. csv-table:: POSIX_SPIN_LOCKS :header: API, Supported diff --git a/include/zephyr/posix/signal.h b/include/zephyr/posix/signal.h index 88b137e7547a..0cfa5649b387 100644 --- a/include/zephyr/posix/signal.h +++ b/include/zephyr/posix/signal.h @@ -12,6 +12,57 @@ extern "C" { #endif +#ifdef CONFIG_POSIX_SIGNAL +#define SIGHUP 1 /**< Hangup */ +#define SIGINT 2 /**< Interrupt */ +#define SIGQUIT 3 /**< Quit */ +#define SIGILL 4 /**< Illegal instruction */ +#define SIGTRAP 5 /**< Trace/breakpoint trap */ +#define SIGABRT 6 /**< Aborted */ +#define SIGBUS 7 /**< Bus error */ +#define SIGFPE 8 /**< Arithmetic exception */ +#define SIGKILL 9 /**< Killed */ +#define SIGUSR1 10 /**< User-defined signal 1 */ +#define SIGSEGV 11 /**< Invalid memory reference */ +#define SIGUSR2 12 /**< User-defined signal 2 */ +#define SIGPIPE 13 /**< Broken pipe */ +#define SIGALRM 14 /**< Alarm clock */ +#define SIGTERM 15 /**< Terminated */ +/* 16 not used */ +#define SIGCHLD 17 /**< Child status changed */ +#define SIGCONT 18 /**< Continued */ +#define SIGSTOP 19 /**< Stop executing */ +#define SIGTSTP 20 /**< Stopped */ +#define SIGTTIN 21 /**< Stopped (read) */ +#define SIGTTOU 22 /**< Stopped (write) */ +#define SIGURG 23 /**< Urgent I/O condition */ +#define SIGXCPU 24 /**< CPU time limit exceeded */ +#define SIGXFSZ 25 /**< File size limit exceeded */ +#define SIGVTALRM 26 /**< Virtual timer expired */ +#define SIGPROF 27 /**< Profiling timer expired */ +/* 28 not used */ +#define SIGPOLL 29 /**< Pollable event occurred */ +/* 30 not used */ +#define SIGSYS 31 /**< Bad system call */ + +#define SIGRTMIN 32 +#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX) +#define _NSIG (SIGRTMAX + 1) + +BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0); + +typedef struct { + unsigned long sig[DIV_ROUND_UP(_NSIG, BITS_PER_LONG)]; +} sigset_t; + +char *strsignal(int signum); +int sigemptyset(sigset_t *set); +int sigfillset(sigset_t *set); +int sigaddset(sigset_t *set, int signo); +int sigdelset(sigset_t *set, int signo); +int sigismember(const sigset_t *set, int signo); +#endif /* CONFIG_POSIX_SIGNAL */ + #ifndef SIGEV_NONE #define SIGEV_NONE 1 #endif diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index d0c1c88910f5..48bb598ef2d5 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -1,5 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 +set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated) + zephyr_syscall_header( ${ZEPHYR_BASE}/include/zephyr/posix/time.h ) @@ -10,6 +12,20 @@ if(CONFIG_POSIX_API) zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix) endif() +if(CONFIG_POSIX_SIGNAL) + set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h) + + add_custom_command( + OUTPUT ${STRSIGNAL_TABLE_H} + COMMAND + ${PYTHON_EXECUTABLE} + ${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py + -i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + -o ${STRSIGNAL_TABLE_H} + DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + ) +endif() + if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_CLOCK OR CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT) # This is a temporary workaround so that Newlib declares the appropriate @@ -29,6 +45,7 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c) zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK timer.c) zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H}) zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC barrier.c) diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index 15f019d4a30e..199ed956af25 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -44,10 +44,12 @@ source "lib/posix/Kconfig.fnmatch" source "lib/posix/Kconfig.fs" source "lib/posix/Kconfig.getopt" source "lib/posix/Kconfig.key" +source "lib/posix/Kconfig.limits" source "lib/posix/Kconfig.mqueue" source "lib/posix/Kconfig.mutex" source "lib/posix/Kconfig.pthread" source "lib/posix/Kconfig.semaphore" +source "lib/posix/Kconfig.signal" source "lib/posix/Kconfig.spinlock" source "lib/posix/Kconfig.timer" source "lib/posix/Kconfig.uname" diff --git a/lib/posix/Kconfig.limits b/lib/posix/Kconfig.limits new file mode 100644 index 000000000000..cc651203961c --- /dev/null +++ b/lib/posix/Kconfig.limits @@ -0,0 +1,13 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +if POSIX_SIGNAL +config POSIX_LIMITS_RTSIG_MAX + int "_POSIX_RTSIG_MAX value in limits.h" + default 8 + help + Define the _POSIX_RTSIG_MAX value in limits.h. + IEEE 1003.1 defines this to be 8. + +endif diff --git a/lib/posix/Kconfig.signal b/lib/posix/Kconfig.signal new file mode 100644 index 000000000000..c51e68f1f36a --- /dev/null +++ b/lib/posix/Kconfig.signal @@ -0,0 +1,26 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_SIGNAL + bool "Support for POSIX signal APIs" + default y if POSIX_API + help + Enable support for POSIX signal APIs. + +if POSIX_SIGNAL +config POSIX_RTSIG_MAX + int "Maximum number of realtime signals" + default 31 + help + Define the maximum number of realtime signals (RTSIG_MAX). + The range of realtime signals is [SIGRTMIN .. (SIGRTMIN+RTSIG_MAX)] + +config POSIX_SIGNAL_STRING_DESC + bool "Use full description for the strsignal API" + default y + help + Use full description for the strsignal API. + Will use 256 bytes of ROM. + +endif diff --git a/lib/posix/signal.c b/lib/posix/signal.c new file mode 100644 index 000000000000..809ba84dc3a6 --- /dev/null +++ b/lib/posix/signal.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "posix/strsignal_table.h" + +#include +#include + +#include + +#define SIGNO_WORD_IDX(_signo) (signo / BITS_PER_LONG) +#define SIGNO_WORD_BIT(_signo) (signo & BIT_MASK(LOG2(BITS_PER_LONG))) + +BUILD_ASSERT(CONFIG_POSIX_LIMITS_RTSIG_MAX >= 0); +BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= CONFIG_POSIX_LIMITS_RTSIG_MAX); + +static inline bool signo_valid(int signo) +{ + return ((signo > 0) && (signo < _NSIG)); +} + +static inline bool signo_is_rt(int signo) +{ + return ((signo >= SIGRTMIN) && (signo <= SIGRTMAX)); +} + +int sigemptyset(sigset_t *set) +{ + *set = (sigset_t){0}; + return 0; +} + +int sigfillset(sigset_t *set) +{ + for (int i = 0; i < ARRAY_SIZE(set->sig); i++) { + set->sig[i] = -1; + } + + return 0; +} + +int sigaddset(sigset_t *set, int signo) +{ + if (!signo_valid(signo)) { + errno = EINVAL; + return -1; + } + + WRITE_BIT(set->sig[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 1); + + return 0; +} + +int sigdelset(sigset_t *set, int signo) +{ + if (!signo_valid(signo)) { + errno = EINVAL; + return -1; + } + + WRITE_BIT(set->sig[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 0); + + return 0; +} + +int sigismember(const sigset_t *set, int signo) +{ + if (!signo_valid(signo)) { + errno = EINVAL; + return -1; + } + + return 1 & (set->sig[SIGNO_WORD_IDX(signo)] >> SIGNO_WORD_BIT(signo)); +} + +char *strsignal(int signum) +{ + static char buf[sizeof("RT signal " STRINGIFY(SIGRTMAX))]; + + if (!signo_valid(signum)) { + errno = EINVAL; + return "Invalid signal"; + } + + if (signo_is_rt(signum)) { + snprintf(buf, sizeof(buf), "RT signal %d", signum - SIGRTMIN); + return buf; + } + + if (IS_ENABLED(CONFIG_POSIX_SIGNAL_STRING_DESC)) { + if (strsignal_list[signum] != NULL) { + return (char *)strsignal_list[signum]; + } + } + + snprintf(buf, sizeof(buf), "Signal %d", signum); + + return buf; +} diff --git a/scripts/build/gen_strsignal_table.py b/scripts/build/gen_strsignal_table.py new file mode 100755 index 000000000000..b60b23237dc6 --- /dev/null +++ b/scripts/build/gen_strsignal_table.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +import argparse +import os +import re + + +def front_matter(): + return f''' +/* + * This file is generated by {__file__} + */ + +#include +''' + + +def gen_strsignal_table(input, output): + with open(input, 'r') as inf: + + highest_signo = 0 + symbols = [] + msgs = {} + + for line in inf.readlines(): + # Select items of the form below (note: SIGNO is numeric) + # #define SYMBOL SIGNO /**< MSG */ + pat = r'^#define[\s]+(SIG[A-Z_]*)[\s]+([1-9][0-9]*)[\s]+/\*\*<[\s]+(.*)[\s]+\*/[\s]*$' + match = re.match(pat, line) + + if not match: + continue + + symbol = match[1] + signo = int(match[2]) + msg = match[3] + + symbols.append(symbol) + msgs[symbol] = msg + + highest_signo = max(int(signo), highest_signo) + + try: + os.makedirs(os.path.dirname(output)) + except BaseException: + # directory already present + pass + + with open(output, 'w') as outf: + + print(front_matter(), file=outf) + + # Generate string table + print( + f'static const char *const strsignal_list[{highest_signo + 1}] = {{', file=outf) + for symbol in symbols: + print(f'\t[{symbol}] = "{msgs[symbol]}",', file=outf) + + print('};', file=outf) + + +def parse_args(): + parser = argparse.ArgumentParser(allow_abbrev=False) + parser.add_argument( + '-i', + '--input', + dest='input', + required=True, + help='input file (e.g. include/zephyr/posix/signal.h)') + parser.add_argument( + '-o', + '--output', + dest='output', + required=True, + help='output file (e.g. build/zephyr/misc/generated/lib/posix/strsignal_table.h)') + + args = parser.parse_args() + + return args + + +def main(): + args = parse_args() + gen_strsignal_table(args.input, args.output) + + +if __name__ == '__main__': + main() diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6e55520a2afe..61a25dae678e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4150,13 +4150,15 @@ sub process { # check for new typedefs, only function parameters and sparse annotations # make sense. - if ($line =~ /\btypedef\s/ && - $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && - $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && - $line !~ /\b$typeTypedefs\b/ && - $line !~ /\b__bitwise\b/) { - WARN("NEW_TYPEDEFS", - "do not add new typedefs\n" . $herecurr); + if ($realfile =~ /\/include\/zephyr\/posix\/*.h/) { + if ($line =~ /\btypedef\s/ && + $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && + $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && + $line !~ /\b$typeTypedefs\b/ && + $line !~ /\b__bitwise\b/) { + WARN("NEW_TYPEDEFS", + "do not add new typedefs\n" . $herecurr); + } } # * goes on variable not on type diff --git a/tests/posix/common/CMakeLists.txt b/tests/posix/common/CMakeLists.txt index e3ba5d8eaa6a..1a4aefa91631 100644 --- a/tests/posix/common/CMakeLists.txt +++ b/tests/posix/common/CMakeLists.txt @@ -5,4 +5,6 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(posix_common) FILE(GLOB app_sources src/*.c) +zephyr_include_directories(${ZEPHYR_BASE}/lib/posix) + target_sources(app PRIVATE ${app_sources}) diff --git a/tests/posix/common/src/signal.c b/tests/posix/common/src/signal.c new file mode 100644 index 000000000000..79b78e5444e4 --- /dev/null +++ b/tests/posix/common/src/signal.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2023 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +ZTEST(posix_apis, test_signal_emptyset) +{ + sigset_t set; + + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + set.sig[i] = -1; + } + + zassert_ok(sigemptyset(&set)); + + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], 0u, "set.sig[%d] is not empty: 0x%lx", i, set.sig[i]); + } +} + +ZTEST(posix_apis, test_signal_fillset) +{ + sigset_t set = (sigset_t){0}; + + zassert_ok(sigfillset(&set)); + + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], -1, "set.sig[%d] is not filled: 0x%lx", i, set.sig[i]); + } +} + +ZTEST(posix_apis, test_signal_addset_oor) +{ + sigset_t set = (sigset_t){0}; + + zassert_equal(sigaddset(&set, -1), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigaddset(&set, 0), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigaddset(&set, _NSIG), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); +} + +ZTEST(posix_apis, test_signal_addset) +{ + int signo; + sigset_t set = (sigset_t){0}; + sigset_t target = (sigset_t){0}; + + signo = SIGHUP; + zassert_ok(sigaddset(&set, signo)); + WRITE_BIT(target.sig[0], signo, 1); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGSYS; + zassert_ok(sigaddset(&set, signo)); + WRITE_BIT(target.sig[0], signo, 1); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGRTMIN; /* >=32, will be in the second sig set for 32bit */ + zassert_ok(sigaddset(&set, signo)); +#ifdef CONFIG_64BIT + WRITE_BIT(target.sig[0], signo, 1); +#else /* 32BIT */ + WRITE_BIT(target.sig[1], (signo)-BITS_PER_LONG, 1); +#endif + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGRTMAX; + zassert_ok(sigaddset(&set, signo)); + WRITE_BIT(target.sig[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 1); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } +} + +ZTEST(posix_apis, test_signal_delset_oor) +{ + sigset_t set = (sigset_t){0}; + + zassert_equal(sigdelset(&set, -1), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigdelset(&set, 0), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigdelset(&set, _NSIG), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); +} + +ZTEST(posix_apis, test_signal_delset) +{ + int signo; + sigset_t set = (sigset_t){0}; + sigset_t target = (sigset_t){0}; + + signo = SIGHUP; + zassert_ok(sigdelset(&set, signo)); + WRITE_BIT(target.sig[0], signo, 0); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGSYS; + zassert_ok(sigdelset(&set, signo)); + WRITE_BIT(target.sig[0], signo, 0); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGRTMIN; /* >=32, will be in the second sig set for 32bit */ + zassert_ok(sigdelset(&set, signo)); +#ifdef CONFIG_64BIT + WRITE_BIT(target.sig[0], signo, 0); +#else /* 32BIT */ + WRITE_BIT(target.sig[1], (signo)-BITS_PER_LONG, 0); +#endif + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } + + signo = SIGRTMAX; + zassert_ok(sigdelset(&set, signo)); + WRITE_BIT(target.sig[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 0); + for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { + zassert_equal(set.sig[i], target.sig[i], + "set.sig[%d of %d] has content: %lx, expected %lx", i, + ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + } +} + +ZTEST(posix_apis, test_signal_ismember_oor) +{ + sigset_t set = {0}; + + zassert_equal(sigismember(&set, -1), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigismember(&set, 0), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + zassert_equal(sigismember(&set, _NSIG), -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); +} + +ZTEST(posix_apis, test_signal_ismember) +{ + sigset_t set = (sigset_t){0}; + +#ifdef CONFIG_64BIT + set.sig[0] = BIT(SIGHUP) | BIT(SIGSYS) | BIT(SIGRTMIN); +#else /* 32BIT */ + set.sig[0] = BIT(SIGHUP) | BIT(SIGSYS); + set.sig[1] = BIT((SIGRTMIN)-BITS_PER_LONG); +#endif + WRITE_BIT(set.sig[SIGRTMAX / BITS_PER_LONG], SIGRTMAX % BITS_PER_LONG, 1); + + zassert_equal(sigismember(&set, SIGHUP), 1, "%s expected to be member", "SIGHUP"); + zassert_equal(sigismember(&set, SIGSYS), 1, "%s expected to be member", "SIGSYS"); + zassert_equal(sigismember(&set, SIGRTMIN), 1, "%s expected to be member", "SIGRTMIN"); + zassert_equal(sigismember(&set, SIGRTMAX), 1, "%s expected to be member", "SIGRTMAX"); + + zassert_equal(sigismember(&set, SIGKILL), 0, "%s not expected to be member", "SIGKILL"); + zassert_equal(sigismember(&set, SIGTERM), 0, "%s not expected to be member", "SIGTERM"); +} + +ZTEST(posix_apis, test_signal_strsignal) +{ + char buf[sizeof("RT signal " STRINGIFY(SIGRTMAX))] = {0}; + + zassert_mem_equal(strsignal(-1), "Invalid signal", sizeof("Invalid signal")); + zassert_mem_equal(strsignal(0), "Invalid signal", sizeof("Invalid signal")); + zassert_mem_equal(strsignal(_NSIG), "Invalid signal", sizeof("Invalid signal")); + + zassert_mem_equal(strsignal(30), "Signal 30", sizeof("Signal 30")); + snprintf(buf, sizeof(buf), "RT signal %d", SIGRTMIN - SIGRTMIN); + zassert_mem_equal(strsignal(SIGRTMIN), buf, strlen(buf)); + snprintf(buf, sizeof(buf), "RT signal %d", SIGRTMAX - SIGRTMIN); + zassert_mem_equal(strsignal(SIGRTMAX), buf, strlen(buf)); + +#ifdef CONFIG_POSIX_SIGNAL_STRING_DESC + zassert_mem_equal(strsignal(SIGHUP), "Hangup", sizeof("Hangup")); + zassert_mem_equal(strsignal(SIGSYS), "Bad system call", sizeof("Bad system call")); +#else + zassert_mem_equal(strsignal(SIGHUP), "Signal 1", sizeof("Signal 1")); + zassert_mem_equal(strsignal(SIGSYS), "Signal 31", sizeof("Signal 31")); +#endif +} diff --git a/tests/posix/common/testcase.yaml b/tests/posix/common/testcase.yaml index 899bb8910bce..a3086233b6c3 100644 --- a/tests/posix/common/testcase.yaml +++ b/tests/posix/common/testcase.yaml @@ -80,3 +80,9 @@ tests: - CONFIG_SPIN_VALIDATE=n integration_platforms: - mps2_an385 + portability.posix.common.signal.strsignal_no_desc: + extra_configs: + - CONFIG_POSIX_SIGNAL_STRING_DESC=n + portability.posix.common.signal.big_nsig: + extra_configs: + - CONFIG_POSIX_RTSIG_MAX=1024 diff --git a/tests/posix/headers/src/signal_h.c b/tests/posix/headers/src/signal_h.c index 9b8711e530e0..852cddf3df0f 100644 --- a/tests/posix/headers/src/signal_h.c +++ b/tests/posix/headers/src/signal_h.c @@ -25,7 +25,6 @@ ZTEST(posix_headers, test_signal_h) /* zassert_not_equal(-1, SIG_IGN); */ /* not implemented */ /* zassert_not_equal((sig_atomic_t)-1, (sig_atomic_t)0); */ /* not implemented */ - /* zassert_not_equal((sigset_t)-1, (sigset_t)0); */ /* not implemented */ /* zassert_not_equal((pid_t)-1, (pid_t)0); */ /* not implemented */ zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify)); @@ -42,35 +41,8 @@ ZTEST(posix_headers, test_signal_h) zassert_not_equal(-1, offsetof(union sigval, sival_ptr)); /* zassert_not_equal(-1, RTSIG_MAX); */ /* not implemented */ - /* zassert_true(SIGRTMIN >= 0); */ /* not implemented */ - /* zassert_true(SIGRTMAX >= SIGRTMIN); */ /* not implemented */ /* zassert_true(SIGRTMAX - SIGRTMIN >= RTSIG_MAX); */ /* not implemented */ - /* zassert_not_equal(-1, SIGABRT); */ /* not implemented */ - /* zassert_not_equal(-1, SIGALRM); */ /* not implemented */ - /* zassert_not_equal(-1, SIGBUS); */ /* not implemented */ - /* zassert_not_equal(-1, SIGCHLD); */ /* not implemented */ - /* zassert_not_equal(-1, SIGCONT); */ /* not implemented */ - /* zassert_not_equal(-1, SIGFPE); */ /* not implemented */ - /* zassert_not_equal(-1, SIGHUP); */ /* not implemented */ - /* zassert_not_equal(-1, SIGILL); */ /* not implemented */ - /* zassert_not_equal(-1, SIGINT); */ /* not implemented */ - /* zassert_not_equal(-1, SIGKILL); */ /* not implemented */ - /* zassert_not_equal(-1, SIGPIPE); */ /* not implemented */ - /* zassert_not_equal(-1, SIGQUIT); */ /* not implemented */ - /* zassert_not_equal(-1, SIGSEGV); */ /* not implemented */ - /* zassert_not_equal(-1, SIGSTOP); */ /* not implemented */ - /* zassert_not_equal(-1, SIGTERM); */ /* not implemented */ - /* zassert_not_equal(-1, SIGTSTP); */ /* not implemented */ - /* zassert_not_equal(-1, SIGTTIN); */ /* not implemented */ - /* zassert_not_equal(-1, SIGTTOU); */ /* not implemented */ - /* zassert_not_equal(-1, SIGUSR1); */ /* not implemented */ - /* zassert_not_equal(-1, SIGUSR2); */ /* not implemented */ - /* zassert_not_equal(-1, SIGTRAP); */ /* not implemented */ - /* zassert_not_equal(-1, SIGURG); */ /* not implemented */ - /* zassert_not_equal(-1, SIGXCPU); */ /* not implemented */ - /* zassert_not_equal(-1, SIGXFSZ); */ /* not implemented */ - /* zassert_not_equal(-1, SIG_BLOCK); */ /* not implemented */ /* zassert_not_equal(-1, SIG_UNBLOCK); */ /* not implemented */ /* zassert_not_equal(-1, SIG_SETMASK); */ /* not implemented */ @@ -158,6 +130,42 @@ ZTEST(posix_headers, test_signal_h) /* zassert_not_equal(-1, SI_ASYNCIO); */ /* not implemented */ /* zassert_not_equal(-1, SI_MESGQ); */ /* not implemented */ +#ifdef CONFIG_POSIX_SIGNAL + zassert_true(SIGRTMIN >= 0); + zassert_true(SIGRTMAX >= SIGRTMIN); + zassert_not_equal(-1, SIGABRT); + zassert_not_equal(-1, SIGALRM); + zassert_not_equal(-1, SIGBUS); + zassert_not_equal(-1, SIGCHLD); + zassert_not_equal(-1, SIGCONT); + zassert_not_equal(-1, SIGFPE); + zassert_not_equal(-1, SIGHUP); + zassert_not_equal(-1, SIGILL); + zassert_not_equal(-1, SIGINT); + zassert_not_equal(-1, SIGKILL); + zassert_not_equal(-1, SIGPIPE); + zassert_not_equal(-1, SIGQUIT); + zassert_not_equal(-1, SIGSEGV); + zassert_not_equal(-1, SIGSTOP); + zassert_not_equal(-1, SIGTERM); + zassert_not_equal(-1, SIGTSTP); + zassert_not_equal(-1, SIGTTIN); + zassert_not_equal(-1, SIGTTOU); + zassert_not_equal(-1, SIGUSR1); + zassert_not_equal(-1, SIGUSR2); + zassert_not_equal(-1, SIGTRAP); + zassert_not_equal(-1, SIGURG); + zassert_not_equal(-1, SIGXCPU); + zassert_not_equal(-1, SIGXFSZ); + zassert_not_equal(((sigset_t){.sig[0] = 0}).sig[0], ((sigset_t){.sig[0] = -1}).sig[0]); + zassert_not_null(sigemptyset); + zassert_not_null(sigfillset); + zassert_not_null(sigaddset); + zassert_not_null(sigdelset); + zassert_not_null(sigismember); + zassert_not_null(strsignal); +#endif /* CONFIG_POSIX_SIGNAL */ + if (IS_ENABLED(CONFIG_POSIX_API)) { /* zassert_not_null(kill); */ /* not implemented */ /* zassert_not_null(killpg); */ /* not implemented */ @@ -167,15 +175,10 @@ ZTEST(posix_headers, test_signal_h) /* zassert_not_null(pthread_sigmask); */ /* not implemented */ /* zassert_not_null(raise); */ /* not implemented */ /* zassert_not_null(sigaction); */ /* not implemented */ - /* zassert_not_null(sigaddset); */ /* not implemented */ /* zassert_not_null(sigaltstack); */ /* not implemented */ - /* zassert_not_null(sigdelset); */ /* not implemented */ - /* zassert_not_null(sigemptyset); */ /* not implemented */ - /* zassert_not_null(sigfillset); */ /* not implemented */ /* zassert_not_null(sighold); */ /* not implemented */ /* zassert_not_null(sigignore); */ /* not implemented */ /* zassert_not_null(siginterrupt); */ /* not implemented */ - /* zassert_not_null(sigismember); */ /* not implemented */ /* zassert_not_null(signal); */ /* not implemented */ /* zassert_not_null(sigpause); */ /* not implemented */ /* zassert_not_null(sigpending); */ /* not implemented */