power_management: rewrite runpwtests04.sh in C
PATCH v2 1/1 power_management: rewrite runpwtests04.sh in C
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.
---
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 | 1 + testcases/kernel/power_management/pwtests01.c | 52 +++++++++++++++++ .../kernel/power_management/runpwtests04.sh | 58 ------------------- 4 files changed, 54 insertions(+), 59 deletions(-) create mode 100644 testcases/kernel/power_management/.gitignore create mode 100644 testcases/kernel/power_management/pwtests01.c delete mode 100755 testcases/kernel/power_management/runpwtests04.sh
runtest/power_management_tests +1 -1
@@ -1,4 +1,4 @@ #POWER_MANAGEMENT +pwtests01 pwtests01 runpwtests03 runpwtests03.sh -runpwtests04 runpwtests04.sh runpwtests06 runpwtests06.sh
testcases/kernel/power_management/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/pwtests01
testcases/kernel/power_management/pwtests01.c new file +52 -0
52 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
Hi Jinseok,
Quoted 1 line · Jinseok Kim
power_management: rewriterunpwtests04.shin C
[...]
testcases/kernel/power_management/pwtests01.c line 34
Quoted 9 lines
testcases/kernel/power_management/pwtests01.c new file +9
-0+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_OPEN() on a non-existent file aborts the test with TBROK. The files current_governor_ro and current_driver may not exist on every system that has a cpuidle directory (e.g. no cpuidle driver loaded, or kernel lacks CONFIG_CPU_IDLE_GOV_*). Use open() directly and convert ENOENT to TCONF:
fd = open(path, O_RDONLY);
if (fd < 0) {
if (errno == ENOENT)
tst_res(TCONF, "%s not available", path);
else
tst_res(TFAIL | TERRNO, "open(%s) failed", path);
return;
}testcases/kernel/power_management/pwtests01.c line 21
Quoted 3 lines
testcases/kernel/power_management/pwtests01.c new file +3
-0+static struct tcases { +const char *name; +} tcases[] = {
Tag and variable share the same name. LTP convention uses the singular for the struct tag: struct tcase { ... } tcases[] = {.
[...]
The new test is named pwtests01 while the shell test it replaces was runpwtests04. The commit message does not explain the rename. If pwtests01 is intentional (e.g. start of a new naming series), please document it briefly.
---
Note:
Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp/actions
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Jinseok,
Quoted 4 lines · Jinseok Kim
power_management: rewriterunpwtests04.shin Ctestcases/kernel/power_management/pwtests01.c new file +2
-0+static void verify_cpuidle (unsigned int i) +{
testcases/kernel/power_management/pwtests01.c line 37
Quoted 10 lines
testcases/kernel/power_management/pwtests01.c new file +10
-0+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);
If SAFE_READ() triggers tst_brk(), execution jumps to cleanup but there is no cleanup registered, so fd is never closed.
The LTP convention is to track file descriptors in a static variable initialized to -1 and close them in a .cleanup handler:
static int fd = -1;
static void verify_cpuidle(unsigned int i)
{
...
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 cleanup(void)
{
if (fd != -1)
SAFE_CLOSE(fd);
}
static struct tst_test test = {
.setup = setup,
.cleanup = cleanup,
...
};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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Jinseok,
thanks for rewriting the test into C API.
The test LGTM, but indeed we should release the file descriptor at cleanup level. Please send v3 with this and I will merge the test.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Jinseok,
for some reasons I didn't receive your [3] in my ML, but I have the CI results and the patch-set needs to be fixed because it doesn't apply:
https://github.com/linux-test-project/ltp/actions/runs/27367707128
Please send v4.
Thanks,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp