forked from linux-test-project/ltp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add negative cases for signalfd(), when errno is EBADF or EINVAL Signed-off-by: Ma Xinjian <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/signalfd01 | ||
/signalfd02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved. | ||
* Author: Ma Xinjian <[email protected]> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* Verify that signalfd(2) fails with: | ||
* | ||
* - EBADF when fd is invalid | ||
* - EINVAL when fd is not a valid signalfd file descriptor | ||
* - EINVAL when flags are invalid | ||
*/ | ||
|
||
#include <sys/signalfd.h> | ||
#include "tst_test.h" | ||
|
||
#define SIGNAL_FILE "signal_file" | ||
|
||
static int fd_ebadf = -2; | ||
static int fd_einval1; | ||
static int fd_einval2 = -1; | ||
|
||
static sigset_t *mask; | ||
|
||
static struct test_case_t { | ||
int *fd; | ||
int flags; | ||
int expected_errno; | ||
char *desc; | ||
} tcases[] = { | ||
{&fd_ebadf, 0, EBADF, "fd is invalid"}, | ||
{&fd_einval1, 0, EINVAL, | ||
"fd is not a valid signalfd file descriptor"}, | ||
{&fd_einval2, -1, EINVAL, "flags are invalid"}, | ||
}; | ||
|
||
static void setup(void) | ||
{ | ||
SAFE_SIGEMPTYSET(mask); | ||
SAFE_SIGADDSET(mask, SIGUSR1); | ||
SAFE_SIGPROCMASK(SIG_BLOCK, mask, NULL); | ||
|
||
fd_einval1 = SAFE_OPEN(SIGNAL_FILE, O_CREAT, 0777); | ||
} | ||
|
||
static void cleanup(void) | ||
{ | ||
if (fd_einval1 > 0) | ||
SAFE_CLOSE(fd_einval1); | ||
} | ||
|
||
static void verify_signalfd(unsigned int i) | ||
{ | ||
struct test_case_t *tc = &tcases[i]; | ||
|
||
TST_EXP_FAIL2(signalfd(*(tc->fd), mask, tc->flags), | ||
tc->expected_errno, "%s", tc->desc); | ||
} | ||
|
||
static struct tst_test test = { | ||
.tcnt = ARRAY_SIZE(tcases), | ||
.test = verify_signalfd, | ||
.setup = setup, | ||
.cleanup = cleanup, | ||
.needs_tmpdir = 1, | ||
.bufs = (struct tst_buffers []) { | ||
{&mask, .size = sizeof(sigset_t)}, | ||
{} | ||
} | ||
}; |