Skip to content

Commit

Permalink
rt_sigqueueinfo02: Add negative tests for rt_sigqueueinfo
Browse files Browse the repository at this point in the history
Add negative cases for rt_sigqueueinfo(), when errno is EINVAL, EPERM or ESRCH

Signed-off-by: Ma Xinjian <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
MaXinjian authored and metan-ucw committed Oct 15, 2024
1 parent 67394e8 commit 0d845b4
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ rt_sigaction03 rt_sigaction03
rt_sigprocmask01 rt_sigprocmask01
rt_sigprocmask02 rt_sigprocmask02
rt_sigqueueinfo01 rt_sigqueueinfo01
rt_sigqueueinfo02 rt_sigqueueinfo02
rt_sigsuspend01 rt_sigsuspend01
rt_sigtimedwait01 rt_sigtimedwait01
rt_tgsigqueueinfo01 rt_tgsigqueueinfo01
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/rt_sigqueueinfo/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/rt_sigqueueinfo01
/rt_sigqueueinfo02
99 changes: 99 additions & 0 deletions testcases/kernel/syscalls/rt_sigqueueinfo/rt_sigqueueinfo02.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
* Author: Ma Xinjian <[email protected]>
*/

/*\
* [Description]
*
* Verify that, rt_sigqueueinfo(2) sets errno to
*
* - EINVAL if sig is invalid
* - EPERM if uinfo->si_code is invalid
* - ESRCH if no thread group matching tgid is found
*/

#include <pwd.h>
#include <signal.h>
#include "config.h"
#include "tst_test.h"

#ifdef HAVE_STRUCT_SIGACTION_SA_SIGACTION
#include "rt_sigqueueinfo.h"

static siginfo_t siginfo_einval;
static siginfo_t siginfo_eperm;
static siginfo_t siginfo_esrch;

static pid_t tgid_notfound = -1;

static struct test_case_t {
pid_t *tgid;
int sig;
siginfo_t *uinfo;
int expected_errno;
char *desc;
} tcases[] = {
{NULL, -1, &siginfo_einval, EINVAL, "sig is invalid"},
{NULL, SIGUSR1, &siginfo_eperm, EPERM, "uinfo->si_code is invalid"},
{&tgid_notfound, SIGUSR1, &siginfo_esrch, ESRCH,
"no thread group matching tgid is found"},
};

static void setup(void)
{
siginfo_einval.si_code = SI_QUEUE;
siginfo_eperm.si_code = 0;
siginfo_esrch.si_code = SI_QUEUE;
}

static void parent_do(struct test_case_t *tc, pid_t pid)
{
pid_t real_pid;

if (tc->tgid)
real_pid = *(tc->tgid);
else
real_pid = pid;

TST_EXP_FAIL(sys_rt_sigqueueinfo(real_pid, tc->sig, tc->uinfo),
tc->expected_errno, "%s", tc->desc);
TST_CHECKPOINT_WAKE(0);
}

static void child_do(void)
{
TST_CHECKPOINT_WAIT(0);
}

static void verify_rt_sigqueueinfo(unsigned int i)
{
struct test_case_t *tc = &tcases[i];
pid_t pid = SAFE_FORK();

if (!pid) {
child_do();
exit(0);
}
parent_do(tc, pid);
SAFE_WAITPID(pid, NULL, 0);
}

static struct tst_test test = {
.setup = setup,
.tcnt = ARRAY_SIZE(tcases),
.test = verify_rt_sigqueueinfo,
.forks_child = 1,
.needs_checkpoints = 1,
.bufs = (struct tst_buffers []) {
{&siginfo_einval, .size = sizeof(siginfo_einval)},
{&siginfo_eperm, .size = sizeof(siginfo_eperm)},
{&siginfo_esrch, .size = sizeof(siginfo_esrch)},
{},
}
};

#else
TST_TEST_TCONF("This system does not support rt_sigqueueinfo()");
#endif /* HAVE_STRUCT_SIGACTION_SA_SIGACTION */

0 comments on commit 0d845b4

Please sign in to comment.