From a70b15fe702fda5d5484b34a53461d94cc3cb160 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Thu, 6 Jul 2023 17:28:21 +0800 Subject: [PATCH] posix: signal: implement sigismember Implementation and ztest for sigismember. Signed-off-by: Yong Cong Sin _NSIG)) { + errno = EINVAL; + return -1; + } + + sig = signo - 1; + if (_NSIG_WORDS == 1) { + return 1 & (set->sig[0] >> sig); + } else { + return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW)); + } +} diff --git a/tests/posix/common/src/signal.c b/tests/posix/common/src/signal.c index 759e3062758b618..bcac72a31603a68 100644 --- a/tests/posix/common/src/signal.c +++ b/tests/posix/common/src/signal.c @@ -200,3 +200,42 @@ ZTEST(posix_apis, test_posix_signal_delset_32) 1, ARRAY_SIZE(set.sig), set.sig[1], sig_mask[1]); } #endif /* CONFIG_64BIT */ + +ZTEST(posix_apis, test_posix_signal_ismember_oor) +{ + int rc; + sigset_t set = {0}; + + rc = sigismember(&set, -1); + zassert_equal(rc, -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + rc = sigismember(&set, 0); + zassert_equal(rc, -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + + rc = sigismember(&set, _NSIG + 1); + zassert_equal(rc, -1, "rc should be -1"); + zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); +} + +ZTEST(posix_apis, test_posix_signal_ismember) +{ + sigset_t set; + +#ifdef CONFIG_64BIT + set.sig[0] = BIT(SIGHUP - 1) | BIT(SIGRTMIN - 1) | BIT(SIGRTMIN) | BIT(SIGRTMAX - 1); +#else /* 32BIT */ + set.sig[0] = BIT(SIGHUP - 1) | BIT(SIGRTMIN - 1); + set.sig[1] = BIT(SIGRTMIN % BITS_PER_LONG) | BIT((SIGRTMAX - 1) % BITS_PER_LONG); +#endif + + zassert_equal(sigismember(&set, SIGHUP), 1, "%s expected to be member", "SIGHUP"); + zassert_equal(sigismember(&set, SIGRTMIN), 1, "%s expected to be member", "SIGRTMIN"); + zassert_equal(sigismember(&set, SIGRTMIN + 1), 1, "%s expected to be member", + "SIGRTMIN + 1"); + 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"); +}