diff mbox series

[v3,5/5] Add cachestat04 test

Message ID 20240722-cachestat-v3-5-a0386f7cdaaa@suse.com
State Accepted
Headers show
Series cachestat testing suite | expand

Commit Message

Andrea Cervesato July 22, 2024, 2:28 p.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies cachestat() for all possible file descriptors,
checking that returned statistics are always zero, unless file
descriptor is unsupported and EBADF is raised.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/cachestat/.gitignore    |  1 +
 testcases/kernel/syscalls/cachestat/cachestat04.c | 58 +++++++++++++++++++++++
 3 files changed, 60 insertions(+)

Comments

Cyril Hrubis July 24, 2024, 9:55 a.m. UTC | #1
Hi!
Again I've added memset() before the cachestat call so that we are sure
that the structure is acutally set and pushed, thanks.
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index 8a297429b..9b041b03d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -65,6 +65,7 @@  cacheflush01 cacheflush01
 cachestat01 cachestat01
 cachestat02 cachestat02
 cachestat03 cachestat03
+cachestat04 cachestat04
 
 chdir01 chdir01
 chdir01A symlink01 -T chdir01
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
index 6cfa3fa10..a3611a533 100644
--- a/testcases/kernel/syscalls/cachestat/.gitignore
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -1,3 +1,4 @@ 
 cachestat01
 cachestat02
 cachestat03
+cachestat04
diff --git a/testcases/kernel/syscalls/cachestat/cachestat04.c b/testcases/kernel/syscalls/cachestat/cachestat04.c
new file mode 100644
index 000000000..0913dd57a
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat04.c
@@ -0,0 +1,58 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies cachestat() for all the possible file descriptors,
+ * checking that cache statistics are always zero, except for unsupported file
+ * descriptors which cause EBADF to be raised.
+ */
+
+#include "tst_test.h"
+#include "lapi/mman.h"
+
+#define MNTPOINT "mnt"
+
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+
+static void check_cachestat(struct tst_fd *fd_in)
+{
+	int ret;
+
+	ret = cachestat(fd_in->fd, cs_range, cs, 0);
+	if (ret == -1) {
+		TST_EXP_EQ_LI(errno, EBADF);
+		return;
+	}
+
+	TST_EXP_EQ_LI(cs->nr_cache, 0);
+	TST_EXP_EQ_LI(cs->nr_dirty, 0);
+	TST_EXP_EQ_LI(cs->nr_writeback, 0);
+	TST_EXP_EQ_LI(cs->nr_evicted, 0);
+	TST_EXP_EQ_LI(cs->nr_recently_evicted, 0);
+}
+
+static void run(void)
+{
+	TST_FD_FOREACH(fd) {
+		tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
+		check_cachestat(&fd);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.min_kver = "6.5",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.bufs = (struct tst_buffers []) {
+		{&cs, .size = sizeof(struct cachestat)},
+		{&cs_range, .size = sizeof(struct cachestat_range)},
+		{}
+	},
+};
+