diff mbox series

power_management: rewrite runpwtests04.sh in C

Message ID 20260516200015.12689-1-always.starving0@gmail.com
State Changes Requested
Headers show
Series power_management: rewrite runpwtests04.sh in C | expand

Checks

Context Check Description
ltpci/copilot-review warning Needs revision

Commit Message

Jinseok Kim May 16, 2026, 8 p.m. UTC
Convert the cpuidle sysfs smoke test from shell to 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>
---
 testcases/kernel/power_management/.gitignore  |  1 +
 testcases/kernel/power_management/cpuidle01.c | 52 +++++++++++++++++
 .../kernel/power_management/runpwtests04.sh   | 58 -------------------
 3 files changed, 53 insertions(+), 58 deletions(-)
 create mode 100644 testcases/kernel/power_management/.gitignore
 create mode 100644 testcases/kernel/power_management/cpuidle01.c
 delete mode 100755 testcases/kernel/power_management/runpwtests04.sh

--
2.43.0

Comments

linuxtestproject.agent@gmail.com May 17, 2026, 5:13 p.m. UTC | #1
Hi Jinseok,

On Sun, 17 May 2026 05:00:12 +0900, Jinseok Kim wrote:
> power_management: rewrite runpwtests04.sh in C
>
> Convert the cpuidle sysfs smoke test from shell to C using the modern
> LTP test API.
>
> The new implementation preserves the original test semantics
> while removing shell dependencies.

The commit body needs a sentence on *why* the conversion is being done
now — what problem or goal motivates it (e.g. old API retirement, CI
coverage gap, etc.).

[...]

> +static void setup(void)
> +{
> +	if (access(CPUIDLE_PATH, R_OK))
> +		tst_brk(TCONF, "%s is not available", CPUIDLE_PATH);
> +}

The runtest file was not updated. `runpwtests04 runpwtests04.sh` in
runtest/power_management_tests still points to the deleted shell script.
Replace it with `cpuidle01 cpuidle01`.

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25997280181

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
diff mbox series

Patch

diff --git a/testcases/kernel/power_management/.gitignore b/testcases/kernel/power_management/.gitignore
new file mode 100644
index 000000000..48c0938dd
--- /dev/null
+++ b/testcases/kernel/power_management/.gitignore
@@ -0,0 +1 @@ 
+/cpuidle01
diff --git a/testcases/kernel/power_management/cpuidle01.c b/testcases/kernel/power_management/cpuidle01.c
new file mode 100644
index 000000000..90d05ee05
--- /dev/null
+++ b/testcases/kernel/power_management/cpuidle01.c
@@ -0,0 +1,52 @@ 
+// 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.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+
+#define CPUIDLE_PATH "/sys/devices/system/cpu/cpuidle"
+
+static struct tcases {
+	const char *name;
+} tcases[] = {
+	{ "current_governor_ro" },
+	{ "current_driver" },
+};
+
+static void verify_cpuidle(unsigned int i)
+{
+	int fd;
+	char path[PATH_MAX];
+	char buf[32];
+
+	snprintf(path, sizeof(path), "%s/%s", CPUIDLE_PATH, tcases[i].name);
+
+	fd = SAFE_OPEN(path, O_RDONLY);
+
+	SAFE_READ(0, fd, buf, sizeof(buf));
+	SAFE_CLOSE(fd);
+
+	tst_res(TPASS, "%s read successfully", path);
+}
+
+static void setup(void)
+{
+	if (access(CPUIDLE_PATH, R_OK))
+		tst_brk(TCONF, "%s is not available", CPUIDLE_PATH);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_cpuidle,
+};
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