• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
4  */
5 
6 /*\
7  * [Description]
8  *
9  * This test verifies cachestat() for all the possible file descriptors,
10  * checking that cache statistics are always zero, except for unsupported file
11  * descriptors which cause EBADF to be raised.
12  */
13 
14 #include "tst_test.h"
15 #include "lapi/mman.h"
16 
17 #define MNTPOINT "mnt"
18 
19 static struct cachestat *cs;
20 static struct cachestat_range *cs_range;
21 
check_cachestat(struct tst_fd * fd_in)22 static void check_cachestat(struct tst_fd *fd_in)
23 {
24 	int ret;
25 
26 	memset(cs, 0xff, sizeof(*cs));
27 
28 	ret = cachestat(fd_in->fd, cs_range, cs, 0);
29 	if (ret == -1) {
30 		TST_EXP_EQ_LI(errno, EBADF);
31 		return;
32 	}
33 
34 	TST_EXP_EQ_LI(cs->nr_cache, 0);
35 	TST_EXP_EQ_LI(cs->nr_dirty, 0);
36 	TST_EXP_EQ_LI(cs->nr_writeback, 0);
37 	TST_EXP_EQ_LI(cs->nr_evicted, 0);
38 	TST_EXP_EQ_LI(cs->nr_recently_evicted, 0);
39 }
40 
run(void)41 static void run(void)
42 {
43 	TST_FD_FOREACH(fd) {
44 		tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
45 		check_cachestat(&fd);
46 	}
47 }
48 
49 static struct tst_test test = {
50 	.timeout = 2,
51 	.test_all = run,
52 	.mount_device = 1,
53 	.mntpoint = MNTPOINT,
54 	.bufs = (struct tst_buffers []) {
55 		{&cs, .size = sizeof(struct cachestat)},
56 		{&cs_range, .size = sizeof(struct cachestat_range)},
57 		{}
58 	},
59 };
60 
61