Skip to content

Commit

Permalink
Add fchmodat2_02 test
Browse files Browse the repository at this point in the history
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
acerv committed Aug 2, 2024
1 parent 5c85eb2 commit 6f7a218
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ fchmodat01 fchmodat01
fchmodat02 fchmodat02

fchmodat2_01 fchmodat2_01
fchmodat2_02 fchmodat2_02

fchown01 fchown01
fchown01_16 fchown01_16
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/fchmodat2/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
fchmodat2_01
fchmodat2_02
68 changes: 68 additions & 0 deletions testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c
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,
};

0 comments on commit 6f7a218

Please sign in to comment.