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.
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
Showing
3 changed files
with
82 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,2 +1,3 @@ | ||
cachestat01 | ||
cachestat02 | ||
cachestat03 |
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,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)}, | ||
{} | ||
}, | ||
}; |