Skip to contentSkip to conversation

power_management: rewrite runpwtests04.sh in C

PATCH In review Jinseok Kim 3 participants 4 messages Aug 5 – Aug 6 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/1 power_management: rewrite runpwtests04.sh in C

Rewrite the cpuidle sysfs smoke test using the LTP C API.

Keep the existing readability checks for current_governor_ro and current_driver, and extend the coverage to available_governors and current_governor. Also verify that writing an invalid governor to current_governor is rejected with EINVAL.

---
Changes in v8:
- Reword the commit message to describe the extended test coverage.
- Remove unnecessary save/restore for current_governor.
- Sort and anchor .gitignore entries.
- Link to v7: https://lore.kernel.org/ltp/[email protected]

Changes in v7:
- Replace the array-based test with dedicated helper functions.
- Use TST_EXP_FAIL2() for the invalid governor test.
- Clarify the test description.
- Link to v6: https://lore.kernel.org/ltp/[email protected]

Changes in v6:
- Expand test coverage to include 4 core cpuidle sysfs ABIs.
- Add verification of read() system call return values (bytes read).
- Add negative testing for 'current_governor' to verify EINVAL return value.
- Replace manual access() check with LTP .save_restore.
- Link to v5: https://lore.kernel.org/ltp/[email protected]

Changes in v5:
- Remove runpwtests04.sh
- Link to v4: https://lore.kernel.org/ltp/[email protected]

Changes in v4:
- Fix patch application failure reported by CI.
- Link to v3: https://lore.kernel.org/ltp/[email protected]

Changes in v3:
- Replace SAFE_OPEN() with open() to convert ENOENT to TCONF.
- Add a cleanup function.
- Link to v2: https://lore.kernel.org/ltp/[email protected]

Changes in v2:
- Update runtest entry
- Clarify commit message
- Link to v1: https://lore.kernel.org/ltp/[email protected]

---
 runtest/power_management_tests                |   2 +-
 testcases/kernel/power_management/.gitignore  |   3 +-
 testcases/kernel/power_management/cpuidle01.c | 102 ++++++++++++++++++
 .../kernel/power_management/runpwtests04.sh   |  58 ----------
 4 files changed, 105 insertions(+), 60 deletions(-)
 create mode 100644 testcases/kernel/power_management/cpuidle01.c
 delete mode 100755 testcases/kernel/power_management/runpwtests04.sh
runtest/power_management_tests +1 -1
index 4da57ee72..0f2656b52 100644
@@ -1,5 +1,5 @@
 #POWER_MANAGEMENT
 high_freq_hwp_cap_cppc high_freq_hwp_cap_cppc
+cpuidle01 cpuidle01
 runpwtests03 runpwtests03.sh
-runpwtests04 runpwtests04.sh
 runpwtests06 runpwtests06.sh
testcases/kernel/power_management/.gitignore +2 -1
index 03f0c83e4..052696dc5 100644
@@ -1 +1,2 @@
-high_freq_hwp_cap_cppc
+/cpuidle01
+/high_freq_hwp_cap_cppc
testcases/kernel/power_management/cpuidle01.c new file +102 -0

102 lines not on this page · raw message

testcases/kernel/power_management/runpwtests04.sh deleted +0 -58

58 lines not on this page · raw message

--
2.43.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Jinseok Kim,

Patch does not apply:
error: patch failed: runtest/power_management_tests:1
error: runtest/power_management_tests: patch does not apply
error: patch failed: testcases/kernel/power_management/.gitignore:1
error: testcases/kernel/power_management/.gitignore: patch does not apply Patch failed at 0001 power_management: rewrite runpwtests04.sh in C

=> please rebase and repost.

Quoted 15 lines

runpwtests06 runpwtests06.sh

testcases/kernel/power_management/.gitignore +2 -1
index 03f0c83e4..052696dc5 100644
@@ -1 +1,2 @@
-high_freq_hwp_cap_cppc
+/cpuidle01
+/high_freq_hwp_cap_cppc
testcases/kernel/power_management/cpuidle01.c new file +0 -0
new file mode 100644
index 000000000..7e7b8d01f

testcases/kernel/power_management/cpuidle01.c line 3

Quoted 3 lines
testcases/kernel/power_management/cpuidle01.c new file +3 -0
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Jinseok Kim <[email protected]>

Maybe add a note:

Based on a script written by Nageswara R Sastry <[email protected]> Copyright (c) International Business Machines Corp., 2001

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Jinseok Kim

Hi Jinseok Kim,

testcases/kernel/power_management/cpuidle01.c line 96

Quoted 6 lines
testcases/kernel/power_management/cpuidle01.c new file +6 -0
+static void run(void)
+{
+	check_available_governors();
+	check_current_driver();
+	check_current_governor();
+	check_current_governor_ro();

please instead of this and .test_all use a test struct, the way we use in basically any test, see e.g. testcases/kernel/syscalls/mbind/mbind01.c testcases/kernel/syscalls/bind/bind01.c

then you'll use:
.tcnt = ARRAY_SIZE(tcase),
.test = do_test

Kind regards,
Petr

Quoted 6 lines
testcases/kernel/power_management/cpuidle01.c new file +6 -0
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp

A message that is not in the archive (sent off-list or not yet received): 20260805154727.GB649402@pevik

#4 lore raw
Quoted 4 lines · Petr Vorel

Hi Jinseok Kim,

[Cc Jan ]

CC mailing list

Quoted 36 lines
Quoted 23 lines
testcases/kernel/power_management/cpuidle01.c new file +22 -0
+/*\
+ * Basic cpuidle sysfs smoke test.
+ *
+ * Verify that selected cpuidle sysfs files are readable and contain
+ * non-empty values. Also verify that current_governor rejects an
+ * invalid governor.
+ *
+ * Root privileges are required to write to current_governor.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+
+#define CPUIDLE_PATH "/sys/devices/system/cpu/cpuidle"
+#define AVAILABLE_GOVERNORS CPUIDLE_PATH "/available_governors"
+#define CURRENT_DRIVER CPUIDLE_PATH "/current_driver"
+#define CURRENT_GOVERNOR CPUIDLE_PATH "/current_governor"
+#define CURRENT_GOVERNOR_RO CPUIDLE_PATH "/current_governor_ro"
+

testcases/kernel/power_management/cpuidle01.c line 37

Quoted 10 lines
testcases/kernel/power_management/cpuidle01.c new file +10 -0
+static void verify_readable(const char *path)
+{
+     int ret;
+     char buf[32];
+
+     int fd = open(path, O_RDONLY);
+
+     if (fd < 0) {
+             if (errno == ENOENT)
+                     tst_res(TCONF, "%s is not available", path);

While this works, we have .save_restore, you would use it with TST_SR_TCONF_MISSING
https://linux-test-project.readthedocs.io/en/latest/developers/api_c_tests.html#saving-and-restoring-proc-sys-values

Quoted 5 lines

But because that would skip whole testing if one of them is missing, maybe instead each test function should check with tst_sys_conf_save().

@Jan Or something else would be more appropriate than lib/tst_sys_conf.c to just detect path existence?

tst_path_exists() + FILE_SCANF() perhaps, and you report again errors from FILE_SCANF() as TFAIL

Quoted 4 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp