[LTP] [PATCH v1 13/31] testcases: sysfs: Add sys_bdi01
Cyril Hrubis
chrubis@suse.cz
Tue Aug 18 16:12:53 CEST 2026
A test for /sys/class/bdi/*/* files.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
runtest/sysfs | 1 +
testcases/kernel/sysfs/class/bdi/.gitignore | 1 +
testcases/kernel/sysfs/class/bdi/Makefile | 7 ++
testcases/kernel/sysfs/class/bdi/sys_bdi01.c | 85 ++++++++++++++++++++
4 files changed, 94 insertions(+)
create mode 100644 testcases/kernel/sysfs/class/bdi/.gitignore
create mode 100644 testcases/kernel/sysfs/class/bdi/Makefile
create mode 100644 testcases/kernel/sysfs/class/bdi/sys_bdi01.c
diff --git a/runtest/sysfs b/runtest/sysfs
index b5e644237..c0983a5be 100644
--- a/runtest/sysfs
+++ b/runtest/sysfs
@@ -9,3 +9,4 @@ sys_cpu_smt01 sys_cpu_smt01
sys_cpu_cache01 sys_cpu_cache01
sys_clockevents01 sys_clockevents01
sys_ata01 sys_ata01
+sys_bdi01 sys_bdi01
diff --git a/testcases/kernel/sysfs/class/bdi/.gitignore b/testcases/kernel/sysfs/class/bdi/.gitignore
new file mode 100644
index 000000000..93ce63f2c
--- /dev/null
+++ b/testcases/kernel/sysfs/class/bdi/.gitignore
@@ -0,0 +1 @@
+/sys_bdi01
diff --git a/testcases/kernel/sysfs/class/bdi/Makefile b/testcases/kernel/sysfs/class/bdi/Makefile
new file mode 100644
index 000000000..034038061
--- /dev/null
+++ b/testcases/kernel/sysfs/class/bdi/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+
+top_srcdir ?= ../../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sysfs/class/bdi/sys_bdi01.c b/testcases/kernel/sysfs/class/bdi/sys_bdi01.c
new file mode 100644
index 000000000..9b5df8877
--- /dev/null
+++ b/testcases/kernel/sysfs/class/bdi/sys_bdi01.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Sanity checks for the backing device info (BDI) attributes exported under
+ * /sys/class/bdi/<id>/.
+ *
+ * For every BDI the test verifies that:
+ *
+ * - min_ratio <= max_ratio (both are percentages)
+ * - min_ratio_fine <= max_ratio_fine (both are in parts-per-million, i.e.
+ * 100% == 1000000)
+ * - min_bytes <= max_bytes, when max_bytes is set (0 means "no limit")
+ * - stable_pages_required and strict_limit are booleans
+ * - read_ahead_kb is non-negative
+ *
+ * The test skips with TCONF when no BDI is present.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <dirent.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_sysfs_assert.h"
+
+#define BDI_CLASS "/sys/class/bdi"
+
+static void check_bdi(const char *id)
+{
+ long max_bytes;
+
+ tst_res(TINFO, "Checking bdi '%s'", id);
+
+ TST_SYSFS_ASSERT_RANGELL(0, 100, BDI_CLASS "/%s/min_ratio", id);
+ TST_SYSFS_ASSERT_RANGELL(0, 100, BDI_CLASS "/%s/max_ratio", id);
+ TST_SYSFS_ASSERT_LE_SUFFIX("min_ratio", "max_ratio",
+ BDI_CLASS "/%s/", id);
+
+ TST_SYSFS_ASSERT_RANGELL(0, 1000000, BDI_CLASS "/%s/min_ratio_fine", id);
+ TST_SYSFS_ASSERT_RANGELL(0, 1000000, BDI_CLASS "/%s/max_ratio_fine", id);
+ TST_SYSFS_ASSERT_LE_SUFFIX("min_ratio_fine", "max_ratio_fine",
+ BDI_CLASS "/%s/", id);
+
+ max_bytes = TST_SYSFS_READ_LI(BDI_CLASS "/%s/max_bytes", id);
+
+ if (max_bytes > 0) {
+ TST_SYSFS_ASSERT_LE_SUFFIX("min_bytes", "max_bytes",
+ BDI_CLASS "/%s/", id);
+ }
+
+ TST_SYSFS_ASSERT_BOOL(BDI_CLASS "/%s/stable_pages_required", id);
+ TST_SYSFS_ASSERT_BOOL(BDI_CLASS "/%s/strict_limit", id);
+
+ TST_SYSFS_ASSERT_RANGELL(0, LONG_MAX, BDI_CLASS "/%s/read_ahead_kb", id);
+}
+
+static void do_test(void)
+{
+ DIR *d;
+ struct dirent *ent;
+ int found = 0;
+
+ d = SAFE_OPENDIR(BDI_CLASS);
+
+ while ((ent = SAFE_READDIR(d))) {
+ if (ent->d_name[0] == '.')
+ continue;
+
+ found = 1;
+ check_bdi(ent->d_name);
+ }
+
+ SAFE_CLOSEDIR(d);
+
+ if (!found)
+ tst_res(TCONF, "No BDI found");
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
--
2.54.0
More information about the ltp
mailing list