* [LTP] [PATCH v7] power_management: rewrite runpwtests04.sh in C
@ 2026-07-29 11:29 Jinseok Kim
2026-07-30 13:02 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 2+ messages in thread
From: Jinseok Kim @ 2026-07-29 11:29 UTC (permalink / raw)
To: ltp
As part of the ongoing effort to reduce shell-based tests in LTP,
rewrite the cpuidle sysfs smoke test in C using the modern LTP test API.
The new implementation preserves the original test semantics while
removing shell dependencies.
Signed-off-by: Jinseok Kim <always.starving0@gmail.com>
---
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/20260707150920.6489-1-always.starving0@gmail.com
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/20260612171415.988-1-always.starving0@gmail.com
Changes in v5:
- Remove runpwtests04.sh
- Link to v4: https://lore.kernel.org/ltp/20260612122045.14962-1-always.starving0@gmail.com
Changes in v4:
- Fix patch application failure reported by CI.
- Link to v3: https://lore.kernel.org/ltp/20260611145911.3752-1-always.starving0@gmail.com
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/20260524154221.2064-1-always.starving0@gmail.com
Changes in v2:
- Update runtest entry
- Clarify commit message
- Link to v1: https://lore.kernel.org/ltp/20260516200015.12689-1-always.starving0@gmail.com
---
runtest/power_management_tests | 2 +-
testcases/kernel/power_management/.gitignore | 1 +
testcases/kernel/power_management/cpuidle01.c | 107 ++++++++++++++++++
.../kernel/power_management/runpwtests04.sh | 58 ----------
4 files changed, 109 insertions(+), 59 deletions(-)
create mode 100644 testcases/kernel/power_management/cpuidle01.c
delete mode 100755 testcases/kernel/power_management/runpwtests04.sh
diff --git a/runtest/power_management_tests b/runtest/power_management_tests
index 4da57ee72..0f2656b52 100644
--- a/runtest/power_management_tests
+++ b/runtest/power_management_tests
@@ -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
diff --git a/testcases/kernel/power_management/.gitignore b/testcases/kernel/power_management/.gitignore
index 03f0c83e4..e237df1c8 100644
--- a/testcases/kernel/power_management/.gitignore
+++ b/testcases/kernel/power_management/.gitignore
@@ -1 +1,2 @@
high_freq_hwp_cap_cppc
+cpuidle01
diff --git a/testcases/kernel/power_management/cpuidle01.c b/testcases/kernel/power_management/cpuidle01.c
new file mode 100644
index 000000000..abbf507a0
--- /dev/null
+++ b/testcases/kernel/power_management/cpuidle01.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com>
+ */
+
+/*\
+ * 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 and to save
+ * and restore its original value.
+ */
+
+#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"
+
+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);
+ else
+ tst_res(TFAIL | TERRNO, "open(%s) failed", path);
+ return;
+ }
+
+ ret = read(fd, buf, sizeof(buf));
+
+ if (ret < 0)
+ tst_res(TFAIL | TERRNO, "%s read() failed", path);
+ else if (ret == 0)
+ tst_res(TFAIL, "%s read() returned 0", path);
+ else
+ tst_res(TPASS, "%s read() successfully", path);
+
+ SAFE_CLOSE(fd);
+}
+
+static void check_available_governors(void)
+{
+ verify_readable(AVAILABLE_GOVERNORS);
+}
+
+static void check_current_driver(void)
+{
+ verify_readable(CURRENT_DRIVER);
+}
+
+static void check_current_governor_ro(void)
+{
+ verify_readable(CURRENT_GOVERNOR_RO);
+}
+
+static void check_current_governor(void)
+{
+ int fd;
+
+ verify_readable(CURRENT_GOVERNOR);
+
+ fd = open(CURRENT_GOVERNOR, O_WRONLY);
+
+ if (fd < 0) {
+ if (errno == ENOENT)
+ tst_res(TCONF, "%s is not available", CURRENT_GOVERNOR);
+ else
+ tst_res(TFAIL | TERRNO, "open(%s) failed", CURRENT_GOVERNOR);
+ return;
+ }
+
+ TST_EXP_FAIL2(write(fd, "invalid_governor", 16), EINVAL);
+
+ SAFE_CLOSE(fd);
+}
+
+static void run(void)
+{
+ check_available_governors();
+ check_current_driver();
+ check_current_governor();
+ check_current_governor_ro();
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_root = 1,
+ .save_restore = (const struct tst_path_val[]) {
+ { CPUIDLE_PATH "/current_governor", NULL, TST_SR_TCONF },
+ {}
+ },
+};
diff --git a/testcases/kernel/power_management/runpwtests04.sh b/testcases/kernel/power_management/runpwtests04.sh
deleted file mode 100755
index 6565320d2..000000000
--- a/testcases/kernel/power_management/runpwtests04.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#! /bin/sh
-#
-# Copyright (c) International Business Machines Corp., 2001
-# Author: Nageswara R Sastry <nasastry@in.ibm.com>
-#
-# This program is free software; you can redistribute it and#or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-export TCID="Power_Management04"
-export TST_TOTAL=1
-
-. test.sh
-. pm_include.sh
-
-check_cpuidle_sysfs_files() {
- RC=0
- if [ -d /sys/devices/system/cpu/cpuidle ] ; then
- for files in current_governor_ro current_driver
- do
- cat /sys/devices/system/cpu/cpuidle/${files} \
- >/dev/null 2>&1
- if [ $? -ne 0 ] ; then
- echo "${0}: FAIL: cat ${files}"
- RC=1
- fi
- done
- fi
- if [ ${RC} -eq 0 ] ; then
- echo "${0}: PASS: Checking cpu idle sysfs files"
- else
- echo "${0}: FAIL: Checking cpu idle sysfs files"
- fi
- return $RC
-}
-
-# Checking test environment
-check_arch
-
-# Checking cpuidle sysfs interface files
-if check_cpuidle_sysfs_files ; then
- tst_resm TPASS "CPUIDLE sysfs tests passed"
-else
- tst_resm TFAIL "CPUIDLE sysfs tests failed"
-fi
-
-tst_exit
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [LTP] power_management: rewrite runpwtests04.sh in C
2026-07-29 11:29 [LTP] [PATCH v7] power_management: rewrite runpwtests04.sh in C Jinseok Kim
@ 2026-07-30 13:02 ` linuxtestproject.agent
0 siblings, 0 replies; 2+ messages in thread
From: linuxtestproject.agent @ 2026-07-30 13:02 UTC (permalink / raw)
To: Jinseok Kim; +Cc: ltp
Hi Jinseok,
On Wed, Jul 29, 2026, Jinseok Kim wrote:
> power_management: rewrite runpwtests04.sh in C
> The new implementation preserves the original test semantics while
> removing shell dependencies.
The C version does more than the shell test: it also reads
available_governors and current_governor and adds an invalid-governor
write-rejection check, whereas runpwtests04.sh only read
current_governor_ro and current_driver. Could the commit message be
reworded to reflect the added coverage rather than "preserves the
original test semantics"?
> +++ b/testcases/kernel/power_management/.gitignore
> @@ -1 +1,2 @@
> high_freq_hwp_cap_cppc
> +cpuidle01
Should the entries stay sorted? Appending cpuidle01 after
high_freq_hwp_cap_cppc leaves the file out of alphabetical order
(c before h). Leaf-directory entries are also normally anchored with a
leading '/' (e.g. /cpuidle01), though the existing entry is unanchored
too.
> +static struct tst_test test = {
> + .test_all = run,
> + .needs_root = 1,
> + .save_restore = (const struct tst_path_val[]) {
> + { CPUIDLE_PATH "/current_governor", NULL, TST_SR_TCONF },
> + {}
> + },
> +};
TST_SR_TCONF expands to TST_SR_TCONF_MISSING | TST_SR_TCONF_RO, so
tst_sys_conf_save() ends the whole test with TCONF at setup when
current_governor is missing or read-only. On a system that exposes only
current_governor_ro, the readable checks for current_governor_ro and
current_driver (which the shell test still ran) would be skipped
entirely. Is gating the full test on current_governor intended, or would
TST_SR_SKIP / a per-file check keep the other checks running?
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-30 13:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29 11:29 [LTP] [PATCH v7] power_management: rewrite runpwtests04.sh in C Jinseok Kim
2026-07-30 13:02 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox