Skip to content

Commit

Permalink
Add cachestat03 test
Browse files Browse the repository at this point in the history
This test verifies that cachestat() syscall is properly failing with
relative error codes according to input parameters.

- EFAULT: cstat or cstat_range points to an illegal address
- EINVAL: invalid flags
- EBADF: invalid file descriptor
- EOPNOTSUPP: file descriptor is of a hugetlbfs file

Signed-off-by: Andrea Cervesato <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
acerv authored and metan-ucw committed Jul 23, 2024
1 parent fea5759 commit 1564e8c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ cacheflush01 cacheflush01

cachestat01 cachestat01
cachestat02 cachestat02
cachestat03 cachestat03

chdir01 chdir01
chdir01A symlink01 -T chdir01
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/cachestat/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cachestat01
cachestat02
cachestat03
80 changes: 80 additions & 0 deletions testcases/kernel/syscalls/cachestat/cachestat03.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
*/

/*\
* [Description]
*
* This test verifies that cachestat() syscall is properly failing with relative
* error codes according to input parameters.
*
* - EFAULT: cstat or cstat_range points to an illegal address
* - EINVAL: invalid flags
* - EBADF: invalid file descriptor
* - EOPNOTSUPP: file descriptor is of a hugetlbfs file
*/

#define MNTPOINT "mnt"

#include "cachestat.h"

static int fd;
static int fd_hugepage;
static int invalid_fd = -1;
static struct cachestat *cs;
static struct cachestat *cs_null;
static struct cachestat_range *cs_range;
static struct cachestat_range *cs_range_null;

static struct tcase {
int *fd;
struct cachestat_range **range;
struct cachestat **data;
int flags;
int exp_errno;
char *msg;
} tcases[] = {
{&invalid_fd, &cs_range, &cs, 0, EBADF, "Invalid fd (-1)"},
{&fd, &cs_range_null, &cs, 0, EFAULT, "Invalid range (NULL)"},
{&fd, &cs_range, &cs_null, 0, EFAULT, "Invalid data (NULL)"},
{&fd, &cs_range, &cs, -1, EINVAL, "Invalid args (-1)"},
{&fd_hugepage, &cs_range, &cs, 0, EOPNOTSUPP, "Unsupported hugetlbfs"},
};

static void run(unsigned int i)
{
struct tcase *tc = &tcases[i];

TST_EXP_FAIL(cachestat(*tc->fd, *tc->range, *tc->data, tc->flags),
tc->exp_errno, "%s", tc->msg);
}

static void setup(void)
{
fd = SAFE_OPEN("test", O_CREAT | O_RDWR, 0700);
fd_hugepage = SAFE_OPEN(MNTPOINT"/test", O_CREAT | O_RDWR, 0700);
}

static void cleanup(void)
{
SAFE_CLOSE(fd);
SAFE_CLOSE(fd_hugepage);
}

static struct tst_test test = {
.test = run,
.setup = setup,
.cleanup = cleanup,
.mntpoint = MNTPOINT,
.needs_hugetlbfs = 1,
.hugepages = {1, TST_NEEDS},
.tcnt = ARRAY_SIZE(tcases),
.min_kver = "6.5",
.needs_tmpdir = 1,
.bufs = (struct tst_buffers []) {
{&cs, .size = sizeof(struct cachestat)},
{&cs_range, .size = sizeof(struct cachestat_range)},
{}
},
};

0 comments on commit 1564e8c

Please sign in to comment.