-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test verifies that fchmodat2() syscall properly raises errors with invalid arguments. Reviewed-by: Petr Vorel <pvorel@suse.cz> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
- Loading branch information
Showing
3 changed files
with
70 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 @@ | ||
fchmodat2_01 | ||
fchmodat2_02 |
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,68 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* This test verifies that fchmodat2() syscall properly raises errors with | ||
* invalid values. | ||
*/ | ||
|
||
#include "tst_test.h" | ||
#include "lapi/fcntl.h" | ||
#include "lapi/syscalls.h" | ||
#include "tst_tmpdir.h" | ||
|
||
#define FILENAME "file.bin" | ||
|
||
static char *tmpdir; | ||
static int fd; | ||
static int fd_invalid = -1; | ||
|
||
static struct tcase { | ||
int *fd; | ||
char *fname; | ||
int mode; | ||
int flag; | ||
int exp_errno; | ||
char *msg; | ||
} tcases[] = { | ||
{&fd_invalid, FILENAME, 0777, 0, EBADF, "bad file descriptor"}, | ||
{&fd, "doesnt_exist.txt", 0777, 0, ENOENT, "unexisting file"}, | ||
{&fd, FILENAME, 0777, -1, EINVAL, "invalid flags"}, | ||
}; | ||
|
||
static void run(unsigned int i) | ||
{ | ||
struct tcase *tc = &tcases[i]; | ||
|
||
TST_EXP_FAIL(tst_syscall(__NR_fchmodat2, | ||
*tc->fd, tc->fname, tc->mode, tc->flag), | ||
tc->exp_errno, | ||
"Test %s", tc->msg); | ||
} | ||
|
||
static void setup(void) | ||
{ | ||
tmpdir = tst_tmpdir_path(); | ||
|
||
SAFE_TOUCH(FILENAME, 0640, NULL); | ||
fd = SAFE_OPEN(tmpdir, O_PATH | O_DIRECTORY, 0640); | ||
} | ||
|
||
static void cleanup(void) | ||
{ | ||
if (fd != -1) | ||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static struct tst_test test = { | ||
.test = run, | ||
.tcnt = ARRAY_SIZE(tcases), | ||
.setup = setup, | ||
.cleanup = cleanup, | ||
.needs_tmpdir = 1, | ||
}; | ||
|