[PATCH v1 02/31] testcases: sysfs: Add sys_power01

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
A test for sysfs/power/* files.

Signed-off-by: Cyril Hrubis <[email protected]>
---
 runtest/sysfs                              |  1 +
 testcases/kernel/sysfs/Makefile            |  7 +++
 testcases/kernel/sysfs/power/.gitignore    |  1 +
 testcases/kernel/sysfs/power/Makefile      |  7 +++
 testcases/kernel/sysfs/power/sys_power01.c | 66 ++++++++++++++++++++++
 5 files changed, 82 insertions(+)
 create mode 100644 runtest/sysfs
 create mode 100644 testcases/kernel/sysfs/Makefile
 create mode 100644 testcases/kernel/sysfs/power/.gitignore
 create mode 100644 testcases/kernel/sysfs/power/Makefile
 create mode 100644 testcases/kernel/sysfs/power/sys_power01.c

diff --git a/runtest/sysfs b/runtest/sysfs
new file mode 100644
index 000000000..e679cacb1
--- /dev/null
+++ b/runtest/sysfs
@@ -0,0 +1 @@
+sys_power01 sys_power01
diff --git a/testcases/kernel/sysfs/Makefile b/testcases/kernel/sysfs/Makefile
new file mode 100644
index 000000000..654cda49e
--- /dev/null
+++ b/testcases/kernel/sysfs/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2026 Cyril Hrubis <[email protected]>
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/sysfs/power/.gitignore b/testcases/kernel/sysfs/power/.gitignore
new file mode 100644
index 000000000..835842cd0
--- /dev/null
+++ b/testcases/kernel/sysfs/power/.gitignore
@@ -0,0 +1 @@
+/sys_power01
diff --git a/testcases/kernel/sysfs/power/Makefile b/testcases/kernel/sysfs/power/Makefile
new file mode 100644
index 000000000..66e633f40
--- /dev/null
+++ b/testcases/kernel/sysfs/power/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2026 Cyril Hrubis <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sysfs/power/sys_power01.c b/testcases/kernel/sysfs/power/sys_power01.c
new file mode 100644
index 000000000..3c78719e5
--- /dev/null
+++ b/testcases/kernel/sysfs/power/sys_power01.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <[email protected]>
+ */
+
+/*\
+ * Sanity checks for the power management attributes exported under
+ * /sys/power/.
+ *
+ * The test verifies that:
+ *
+ * - pm_async, pm_debug_messages, pm_print_times and sync_on_suspend are
+ *   booleans
+ * - pm_freeze_timeout and wakeup_count are non-negative
+ * - disk is a bracketed-choice file selecting one of platform, shutdown,
+ *   reboot, suspend, test_resume or firmware
+ * - mem_sleep is a bracketed-choice file selecting one of s2idle, shallow or
+ *   deep
+ * - state lists only known sleep states (freeze, standby, mem, disk, on)
+ *
+ * Unlike disk and mem_sleep, state never marks a "current" value with
+ * brackets, it merely enumerates the sleep states the kernel supports, so it
+ * is validated as a plain token set rather than a bracketed choice.
+ *
+ * All checks skip gracefully with TCONF when a particular attribute is not
+ * present.
+ */
+
+#include <limits.h>
+#include "tst_test.h"
+#include "tst_sysfs_assert.h"
+
+#define POWER "/sys/power"
+
+static const char *const disk_allowed[] = {
+	"platform", "shutdown", "reboot", "suspend", "test_resume",
+	"firmware", NULL
+};
+
+static const char *const mem_sleep_allowed[] = {
+	"s2idle", "shallow", "deep", NULL
+};
+
+static const char *const state_allowed[] = {
+	"freeze", "standby", "mem", "disk", "on", NULL
+};
+
+static void do_test(void)
+{
+	TST_SYSFS_ASSERT_BOOL(POWER "/pm_async");
+	TST_SYSFS_ASSERT_BOOL(POWER "/pm_debug_messages");
+	TST_SYSFS_ASSERT_BOOL(POWER "/pm_print_times");
+	TST_SYSFS_ASSERT_BOOL(POWER "/sync_on_suspend");
+
+	TST_SYSFS_ASSERT_RANGELL(0, LONG_MAX, POWER "/pm_freeze_timeout");
+	TST_SYSFS_ASSERT_RANGELL(0, LONG_MAX, POWER "/wakeup_count");
+
+	TST_SYSFS_ASSERT_CHOICE(disk_allowed, NULL, 0, POWER "/disk");
+	TST_SYSFS_ASSERT_CHOICE(mem_sleep_allowed, NULL, 0, POWER "/mem_sleep");
+
+	TST_SYSFS_ASSERT_TOKENS(state_allowed, NULL, POWER "/state");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.