rfim: add new test for verifying RFIM sysfs interface
PATCH 1/1 rfim: add new test for verifying RFIM sysfs interface
Validate presence and permissions of RFIM attributes. The test checks first validity of general RFIM attributes, and then checks either DLVR or FIVR, depending on hardware.
The test works only on Intel platforms with RFIM.
--- runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + testcases/kernel/power_management/rfim.c | 165 +++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 testcases/kernel/power_management/rfim.c
runtest/power_management_tests +1 -0
@@ -1,5 +1,6 @@ #POWER_MANAGEMENT high_freq_hwp_cap_cppc high_freq_hwp_cap_cppc +rfim rfim runpwtests03 runpwtests03.sh runpwtests04 runpwtests04.sh runpwtests06 runpwtests06.sh
testcases/kernel/power_management/.gitignore +1 -0
@@ -1 +1,2 @@ high_freq_hwp_cap_cppc +rfim
testcases/kernel/power_management/rfim.c new file +165 -0
165 lines not on this page · raw message
Signature · 13 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Piotr,
Quoted 7 lines · Piotr Kubaj
rfim: add new test for verifying RFIM sysfs interface
/*\
* Validate presence and permissions of RFIM attributes.
* The test checks first validity of general RFIM attributes,
* and then checks either DLVR or FIVR, depending on hardware. */
The test sets .needs_root = 1 but the doc comment does not explain why root is required. Other tests in the same directory document this (e.g. "The test needs root because reading /dev/cpu/N/msr needs CAP_SYS_RAWIO / root."). Could a line be added explaining that root is needed for write-access checks on sysfs attributes?
Quoted 7 lines
} else if (!stat(RFIM_ROOT"/fivr", &stats)) {
if (S_ISDIR(stats.st_mode))
variant = RFIM_FIVR;
else
tst_brk(TBROK, "%s exists but is not a directory", RFIM_ROOT"/fivr");
} else
tst_brk(TCONF, "Neither %s nor %s exists", RFIM_ROOT"/dlvr", RFIM_ROOT"/fivr");The first two branches of this if/else-if/else chain use braces but the final else does not. Kernel coding style requires braces on all branches when any branch needs them.
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 Piotr,
runtest/power_management_tests line 3
Quoted 8 lines
runtest/power_management_tests +1
-0@@ -1,5 +1,6 @@ #POWER_MANAGEMENT high_freq_hwp_cap_cppc high_freq_hwp_cap_cppc +rfim rfim
Use rfim01 instead. We might want to add more tests in the future.
Quoted 44 lines
runtest/power_management_tests +0
-0runpwtests03 runpwtests03.sh runpwtests04 runpwtests04.sh runpwtests06 runpwtests06.shtestcases/kernel/power_management/.gitignore +1
-0@@ -1 +1,2 @@ high_freq_hwp_cap_cppc +rfimtestcases/kernel/power_management/rfim.c new file +28
-0@@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Piotr Kubaj <[email protected]> +*/ + +/*\ +* Validate presence and permissions of RFIM attributes. +* The test checks first validity of general RFIM attributes, +* and then checks either DLVR or FIVR, depending on hardware. +*/ + +#include "tst_test.h" + +#define RFIM_ROOT "/sys/bus/pci/devices/0000:00:04.0" + +enum rfim_variant { +RFIM_FIVR , +RFIM_DLVR , +}; + +static enum rfim_variant variant; + +static void setup (void ) +{ +struct stat stats; + +if (!stat (RFIM_ROOT "/dlvr" , &stats)) { +if (S_ISDIR (stats.st_mode))
testcases/kernel/power_management/rfim.c line 38
Quoted 10 lines
testcases/kernel/power_management/rfim.c new file +10
-0+ variant =RFIM_DLVR ; + else + tst_brk(TBROK, "%s exists but is not a directory", RFIM_ROOT"/dlvr"); + }else if (!stat (RFIM_ROOT "/fivr" , &stats)) { +if (S_ISDIR (stats.st_mode)) + variant =RFIM_FIVR ; +else +tst_brk (TBROK ,"%s exists but is not a directory" ,RFIM_ROOT "/fivr" ); + }else +tst_brk (TCONF ,"Neither %s nor %s exists" ,RFIM_ROOT "/dlvr" ,RFIM_ROOT "/fivr" );
Avoid too many nesting. Use if() -> TBROK or TCONF, instead of having else everywhere. First, handle the error, then proceed with the test.
Quoted 18 lines
testcases/kernel/power_management/rfim.c new file +18
-0+} + +static void check_read_only (const char *path) +{ +tst_res (TDEBUG ,"Checking whether %s is read-only" , path); + +if (access (path,F_OK )) { +tst_res (TFAIL |TERRNO ,"%s does not exist" , path); +return ; + } + +int fd =open (path,O_RDONLY ); + +if (fd ==-1 ) { +tst_res (TFAIL |TERRNO ,"%s can't be read" , path); +return ; + } +close (fd);
testcases/kernel/power_management/rfim.c line 66
Quoted 10 lines
testcases/kernel/power_management/rfim.c new file +10
-0+ + fd =open (path,O_WRONLY ); +if (fd !=-1 ) { +close (fd); +tst_res (TFAIL ,"%s is writable" , path); +return ; + } + +tst_res (TPASS ,"%s is read-only" , path); +}
This function can be easily replaced by access().
TST_EXP_PASS(access(path, R_OK));TST_EXP_FAIL(access(path, W_OK), ..);
testcases/kernel/power_management/rfim.c line 73
Quoted 7 lines
testcases/kernel/power_management/rfim.c new file +7
-0+ +static void check_read_write (const char *path) +{ +tst_res (TDEBUG ,"Checking whether %s is read-write" , path); + +if (access (path,F_OK )) { +tst_res (TFAIL |TERRNO ,"%s does not exist" , path);
TERRNO already show the message. Either you use TERRNO or you specify a message error by hand, not both. This is valid in general for all other messages as well.
testcases/kernel/power_management/rfim.c line 84
Quoted 11 lines
testcases/kernel/power_management/rfim.c new file +11
-0+return ; + } + +int fd =open (path,O_RDWR ); + +if (fd !=-1 ) { +close (fd); +tst_res (TPASS ,"%s is read-write" , path); + }else +tst_res (TFAIL |TERRNO ,"%s is not read-write" , path); +}
This one as well can be replaced with access().
Quoted 34 lines
testcases/kernel/power_management/rfim.c new file +34
-0+ +static void run (void ) +{ +const char *const fivr_nodes[] = { +RFIM_ROOT "/fivr/vco_ref_code_lo" , +RFIM_ROOT "/fivr/vco_ref_code_hi" , +RFIM_ROOT "/fivr/spread_spectrum_pct" , +RFIM_ROOT "/fivr/spread_spectrum_clk_enable" , +RFIM_ROOT "/fivr/rfi_vco_ref_code" , +RFIM_ROOT "/fivr/fivr_fffc_rev" , +NULL + }; + +const char *const ro_general_nodes[] = { +RFIM_ROOT "/dvfs/ddr_data_rate_point_0" , +RFIM_ROOT "/dvfs/ddr_data_rate_point_1" , +RFIM_ROOT "/dvfs/ddr_data_rate_point_2" , +RFIM_ROOT "/dvfs/ddr_data_rate_point_3" , +NULL + }; + +const char *const ro_dlvr_nodes[] = { +RFIM_ROOT "/dlvr/dlvr_hardware_rev" , +RFIM_ROOT "/dlvr/dlvr_freq_mhz" , +RFIM_ROOT "/dlvr/dlvr_pll_busy" , +NULL + }; + +const char *const rw_dlvr_nodes[] = { +RFIM_ROOT "/dlvr/dlvr_freq_select" , +RFIM_ROOT "/dlvr/dlvr_rfim_enable" , +RFIM_ROOT "/dlvr/dlvr_spread_spectrum_pct" , +RFIM_ROOT "/dlvr/dlvr_control_mode" , +RFIM_ROOT "/dlvr/dlvr_control_lock" ,
testcases/kernel/power_management/rfim.c line 128
Quoted 10 lines
testcases/kernel/power_management/rfim.c new file +10
-0+ NULL + }; + +const char *const rw_general_nodes[] = { +RFIM_ROOT "/dvfs/rfi_restriction_run_busy" , +RFIM_ROOT "/dvfs/rfi_restriction_err_code" , +RFIM_ROOT "/dvfs/rfi_restriction_data_rate_base" , +RFIM_ROOT "/dvfs/rfi_restriction_data_rate" , +NULL + };
Please define them out as static arrays.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 4 lines
This function can be easily replaced by
access().
TST_EXP_PASS(access(path, R_OK));TST_EXP_FAIL(access(path, W_OK), ..);
Thinking twice, this can be even simpler by using stat() and checking for .st_mode in returned struct. In this way you filter out all permissions, not only read or write.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 29 lines
Quoted 16 lines
testcases/kernel/power_management/rfim.c new file +16
-0+static void check_read_only (const char *path) +{ +tst_res (TDEBUG ,"Checking whether %s is read-only" , path); + +if (access (path,F_OK )) { +tst_res (TFAIL |TERRNO ,"%s does not exist" , path); +return ; + } + +int fd =open (path,O_RDONLY ); + +if (fd ==-1 ) { +tst_res (TFAIL |TERRNO ,"%s can't be read" , path); +return ; + } +close (fd);testcases/kernel/power_management/rfim.c line 66
Quoted 10 lines
testcases/kernel/power_management/rfim.c new file +10
-0+ + fd =open (path,O_WRONLY ); +if (fd !=-1 ) { +close (fd); +tst_res (TFAIL ,"%s is writable" , path); +return ; + } + +tst_res (TPASS ,"%s is read-only" , path); +}This function can be easily replaced by
access().
Quoted 2 lines
TST_EXP_PASS(access(path, R_OK));TST_EXP_FAIL(access(path, W_OK), ..);
This depends on where the error from kernel is supposed to be returned from. For files that are generated by kernel such as /sys/ and /proc/ the permission bits can be all enabled but you may still get EPERM when you actually open the file and kernel decides that this file shouldn't be readable in the open() syscall handler for the particular file.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 5 lines
This depends on where the error from kernel is supposed to be returned from. For files that are generated by kernel such as
/sys/and/proc/the permission bits can be all enabled but you may still get EPERM when you actually open the file and kernel decides that this file shouldn't be readable in theopen()syscall handler for the particular file.
Thanks for pointing out. So I guess open() is ok, we can proceed with the initial approach.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp