Skip to content

Commit

Permalink
posix: signal: implement sigismember
Browse files Browse the repository at this point in the history
Implementation and ztest for sigismember.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
  • Loading branch information
ycsin committed Jul 6, 2023
1 parent 3fa7b3d commit 3302c47
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/services/portability/posix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ required for error and event handling.
sigdelset(),yes
sigemptyset(),yes
sigfillset(),yes
igismember(),
sigismember(),yes
signal(),
sigpending(),
sigprocmask(),
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/posix/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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
Expand Down
10 changes: 10 additions & 0 deletions lib/posix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ int sigdelset(sigset_t *set, int signo)

return 0;
}

int sigismember(const sigset_t *set, int signo)
{
if (signo_invalid(signo)) {
errno = EINVAL;
return -1;
}

return 1 & (set->sig[signo_word_idx(signo)] >> signo_word_bit(signo));
}
39 changes: 39 additions & 0 deletions tests/posix/common/src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,42 @@ ZTEST(posix_apis, test_signal_delset_32)
1, ARRAY_SIZE(set.sig), set.sig[1], sig_mask[1]);
}
#endif /* CONFIG_64BIT */

ZTEST(posix_apis, test_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_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");
}

0 comments on commit 3302c47

Please sign in to comment.