Rewrite fw_load test using new API
v6 cover Rewrite fw_load test using new API
Support immutable distribution by splitting test in two:
- fw_load01 triggers request_firmware on /lib/firmware (read-only on immutable distributions) and it doesn't support read-only filesystems
- fw_load02 triggers request_firmware on custom path (always supported by any distribution)
---
Changes in v6:
- add commit for git mv mergin both test and kernel module into fw_load folder
- fix fw_load02 fw_path setup
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- rebase since apply is failing
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- verify /lib/firmware/update was created by our test
- fix algorithm op order in fw_load02
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- fix bisecting
- fix algorithm op order
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- fix fw_load.h define
- fix Makefile copyright position
- fix year in the firmware file
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (4):
fw_load: Modernize ltp_fw_load kernel module
fw_load: rewrite test using new LTP API
fw_load: merge module and test into fw_load folder
fw_load: add fw_load02 for custom firmware path
runtest/kernel_misc | 3 +-
.../{fw_load_kernel => fw_load}/.gitignore | 2 +
testcases/kernel/firmware/fw_load/Makefile | 25 +++
testcases/kernel/firmware/fw_load/fw_load.h | 18 ++
testcases/kernel/firmware/fw_load/fw_load01.c | 165 ++++++++++++++++
testcases/kernel/firmware/fw_load/fw_load02.c | 138 +++++++++++++
testcases/kernel/firmware/fw_load/ltp_fw_load.c | 178 +++++++++++++++++
testcases/kernel/firmware/fw_load_kernel/Makefile | 35 ----
testcases/kernel/firmware/fw_load_kernel/README | 16 --
.../kernel/firmware/fw_load_kernel/ltp_fw_load.c | 164 ----------------
testcases/kernel/firmware/fw_load_user/.gitignore | 1 -
testcases/kernel/firmware/fw_load_user/Makefile | 20 --
testcases/kernel/firmware/fw_load_user/README | 11 --
testcases/kernel/firmware/fw_load_user/fw_load.c | 213 ---------------------
14 files changed, 528 insertions(+), 461 deletions(-)---
base-commit: c685f1b774fab694c42dfb7522bc42d999904373
change-id: 20260609-fw_load-2882088bec8e
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/4 fw_load: Modernize ltp_fw_load kernel module
From: Andrea Cervesato <[email protected]>
Fix VLA (banned since kernel v4.20), replace sscanf() with kstrtoint(), reset test_result between invocations, make the loop variable local and pass expected data explicitly.
Update license headers, fix brace style, drop obsolete README in favour of the in-source documentation.
--- testcases/kernel/firmware/fw_load_kernel/Makefile | 16 +-- testcases/kernel/firmware/fw_load_kernel/README | 16 --- .../kernel/firmware/fw_load_kernel/ltp_fw_load.c | 114 ++++++++++++--------- 3 files changed, 66 insertions(+), 80 deletions(-)
testcases/kernel/firmware/fw_load_kernel/Makefile +2 -14
@@ -1,18 +1,6 @@ # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. -# -# 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 would 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 the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Copyright (c) Linux Test Project, 2026 +# SPDX-License-Identifier: GPL-2.0-or-later ifneq ($(KERNELRELEASE),)
testcases/kernel/firmware/fw_load_kernel/README deleted +0 -16
@@ -1,16 +0,0 @@ -The aim of the test is to check device firmware loading. Since kernel 3.7 -firmware loading changed to direct loading (by-pass udev). The test consists -of the two parts: - - userspace part - - kernelspace part - -This is a kernel module, which is a part of the device firmware loading test. -It allows to call request_firmware kernel function with specified parameters. -Template firmware file name and expected firmware file's data size are passed -as the insmod command line parameters. Then, the number of firmware test files -should be written to sysfs file 'fwnum' (the maximum number is 32). This write -will initiate request firmware procedure. In the end, results can be read from -'result' device sysfs file. Also, some information regarding module loading, -can be obtained by looking at kernel log file. - -It is automatically used by userspace part of the test.
testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c +64 -50
203 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] fw_load: Modernize ltp_fw_load kernel module
Hi Andrea,
Quoted 1 line · Andrea Cervesato
fw_load: Modernizeltp_fw_loadkernel module
Verdict: Reviewed
---
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
Re: [LTP] [PATCH v6 1/4] fw_load: Modernize ltp_fw_load kernel module
In reply to Andrea CervesatoHi!
Quoted 5 lines
testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c +0
-0
testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c line 6
Quoted 10 lines
testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c +3
-4@@ -1,25 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. +* Author: Alexey Kodanev <[email protected]> * -* 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. +* Copyright (c) 2023 Andrea Cervesato <[email protected]>
^ Shouldn't that be 2026?
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 2/4 fw_load: rewrite test using new LTP API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Remove the obsolete user-helper and create a fw_load.h where to store the firmware support information.
--- testcases/kernel/firmware/fw_load_user/Makefile | 18 +- testcases/kernel/firmware/fw_load_user/README | 11 - testcases/kernel/firmware/fw_load_user/fw_load.c | 286 ++++++++++------------- testcases/kernel/firmware/fw_load_user/fw_load.h | 18 ++ 4 files changed, 140 insertions(+), 193 deletions(-)
testcases/kernel/firmware/fw_load_user/Makefile +3 -15
@@ -1,20 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. -# -# 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 would 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 the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Copyright (c) Linux Test Project, 2026 -top_srcdir ?= ../../../.. +top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/firmware/fw_load_user/README deleted +0 -11
@@ -1,11 +0,0 @@ -The aim of the test is to check device firmware loading. Since kernel 3.7 -firmware loading changed to direct loading (by-pass udev). The test consists -of the two parts: - - userspace part - - kernelspace part - -This is the userspace part, its tasks are: - - create firmware files in the standard firmware paths - - load the module and initiate firmware request procedure - - read device's result file and print final results - - unload the module.
testcases/kernel/firmware/fw_load_user/fw_load.c +119 -167
332 lines not on this page · raw message
testcases/kernel/firmware/fw_load_user/fw_load.h new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef FW_LOAD_H +#define FW_LOAD_H + +#define MNAME_KO "ltp_fw_load.ko" +#define FW_NAME "load_tst.fw" +#define FW_SIZE 0x1000 +#define FW_NUM 5 +#define FW_PATH "/sys/module/firmware_class/parameters/path" +#define DEV_FWNUM "/sys/devices/ltp_fw_load/fwnum" +#define DEV_RESULT "/sys/devices/ltp_fw_load/result" +#define LIB_PATH "/lib/firmware" + +#endif
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/4] fw_load: rewrite test using new LTP API
Hi!
Quoted 25 lines
testcases/kernel/firmware/fw_load_user/fw_load.c +10
-10+static void run (void ) { -setup (argc, argv); +struct fw_data *fw; +int result =0 ; +int fail, offset; -test_run (); +SAFE_FILE_PRINTF (DEV_FWNUM ,"%d" , fw_count); +SAFE_FILE_SCANF (DEV_RESULT ,"%d" , &result); -cleanup (); +for (int i =0 ; i < fw_count; i++) { + fw = &firmware[i]; -tst_exit (); -} + fail = (result & (1 << i)) ==0 && !fw->fake; + offset = fw->dir[0 ] ?strlen (fw->dir) :0 ; -static void help (void ) -{ -printf (" -n x Write x bytes to firmware file, default is %d\n" , - fw_size); -printf (" -s Skip cleanup\n" );
testcases/kernel/firmware/fw_load_user/fw_load.c line 96
Quoted 10 lines
testcases/kernel/firmware/fw_load_user/fw_load.c +9
-1-printf (" -v Verbose\n" ); +if (fw->fake) { +tst_res (result & (1 << i) ?TFAIL :TPASS , +"Firmware '%s' correctly not loaded" , + fw->file + offset); + }else { +tst_res (fail ?TFAIL :TPASS , +"Firmware '%s' loaded" , + fw->file + offset); + }
If you are splitting the tst_res() by the fw->fake then do it right. We should drop the && !fw->fake from the fail above and use a variable only to get the right bit from the result:
int pass = result && (1<<i);
if (fw->fake)
tst_res(pass ? TFAIL : TPASS, ...) else tst_res(pass ? TPASS : TFAIL, ...)
testcases/kernel/firmware/fw_load_user/fw_load.c line 107
Quoted 8 lines
testcases/kernel/firmware/fw_load_user/fw_load.c +2
-3+ } } -void setup (int argc,char *argv[]) +static void setup (void ) { -if (tst_lockdown_enabled () >0 ||tst_secureboot_enabled () >0 ) -tst_brkm (TCONF ,NULL ,"Cannot load unsigned modules in Lockdown/Secure Boot" );
I assume that we dropped this because we have tst_requires_module_signature_disabled() later in the setup() right?
The rest looks good.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/4] fw_load: rewrite test using new LTP API
Hi Cyril,
Quoted 10 lines
If you are splitting the
tst_res()by thefw->fakethen do it right. We should drop the && !fw->fake from the fail above and use a variable only to get the right bit from the result:int pass = result && (1<<i);
if (
fw->fake)tst_res(pass ? TFAIL : TPASS, ...) else tst_res(pass ? TPASS : TFAIL, ...)
Much cleaner indeed, I will fix it.
Quoted 3 lines
I assume that we dropped this because we have
tst_requires_module_signature_disabled()later in thesetup()right?
Exactly.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 3/4 fw_load: merge module and test into fw_load folder
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Rename fw_load test into fw_load01 and move it into the fw_load folder within ltp_fw_load.ko module.
---
runtest/kernel_misc | 2 +-
testcases/kernel/firmware/{fw_load_kernel => fw_load}/.gitignore | 1 +
testcases/kernel/firmware/{fw_load_kernel => fw_load}/Makefile | 8 +++++---
testcases/kernel/firmware/{fw_load_user => fw_load}/fw_load.h | 0
.../firmware/{fw_load_user/fw_load.c => fw_load/fw_load01.c} | 0
.../kernel/firmware/{fw_load_kernel => fw_load}/ltp_fw_load.c | 0
testcases/kernel/firmware/fw_load_user/.gitignore | 1 -
testcases/kernel/firmware/fw_load_user/Makefile | 8 --------
8 files changed, 7 insertions(+), 13 deletions(-)runtest/kernel_misc +1 -1
@@ -1,6 +1,6 @@ cn_pec_sh cn_pec.sh kmsg01 kmsg01 -fw_load fw_load +fw_load01 fw_load01 rtc01 rtc01 rtc02 rtc02 block_dev block_dev
testcases/kernel/firmware/fw_load/.gitignore renamed from testcases/kernel/firmware/fw_load_kernel/.gitignore +1 -0
@@ -5,3 +5,4 @@ /ltp_fw_load.mod.c /.tmp_versions/ modules.livepatch +fw_load01
testcases/kernel/firmware/fw_load/Makefile renamed from testcases/kernel/firmware/fw_load_kernel/Makefile +5 -3
@@ -1,6 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. # Copyright (c) Linux Test Project, 2026 -# SPDX-License-Identifier: GPL-2.0-or-later ifneq ($(KERNELRELEASE),)
@@ -11,11 +11,13 @@ endif else top_srcdir ?= ../../../.. -include $(top_srcdir)/include/mk/env_pre.mk + +include $(top_srcdir)/include/mk/testcases.mk REQ_VERSION_MAJOR := 3 REQ_VERSION_PATCH := 7 -MAKE_TARGETS := ltp_fw_load.ko + +MAKE_TARGETS := fw_load01 ltp_fw_load.ko include $(top_srcdir)/include/mk/module.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/firmware/fw_load/fw_load.h renamed from testcases/kernel/firmware/fw_load_user/fw_load.h +0 -0
testcases/kernel/firmware/fw_load/fw_load01.c renamed from testcases/kernel/firmware/fw_load_user/fw_load.c +0 -0
testcases/kernel/firmware/fw_load/ltp_fw_load.c renamed from testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c +0 -0
testcases/kernel/firmware/fw_load_user/.gitignore deleted +0 -1
@@ -1 +0,0 @@ -/fw_load
testcases/kernel/firmware/fw_load_user/Makefile deleted +0 -8
@@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. -# Copyright (c) Linux Test Project, 2026 - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 4/4 fw_load: add fw_load02 for custom firmware path
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add fw_load02 which points the kernel firmware loader at the writable LTP temporary directory via /sys/module/firmware_class/parameters/path. Unlike fw_load01, it does not rely on a writable /lib/firmware and so works on read-only and immutable root filesystems while still exercising request_firmware() for both successful loads and the not-found case.
--- runtest/kernel_misc | 1 + testcases/kernel/firmware/fw_load/.gitignore | 1 + testcases/kernel/firmware/fw_load/Makefile | 2 +- testcases/kernel/firmware/fw_load/fw_load02.c | 138 ++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-)
runtest/kernel_misc +1 -0
@@ -1,6 +1,7 @@ cn_pec_sh cn_pec.sh kmsg01 kmsg01 fw_load01 fw_load01 +fw_load02 fw_load02 rtc01 rtc01 rtc02 rtc02 block_dev block_dev
testcases/kernel/firmware/fw_load/.gitignore +1 -0
@@ -6,3 +6,4 @@ /.tmp_versions/ modules.livepatch fw_load01 +fw_load02
testcases/kernel/firmware/fw_load/Makefile +1 -1
@@ -17,7 +17,7 @@ include $(top_srcdir)/include/mk/testcases.mk REQ_VERSION_MAJOR := 3 REQ_VERSION_PATCH := 7 -MAKE_TARGETS := fw_load01 ltp_fw_load.ko +MAKE_TARGETS := fw_load01 fw_load02 ltp_fw_load.ko include $(top_srcdir)/include/mk/module.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/firmware/fw_load/fw_load02.c new file +138 -0
138 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 4/4] fw_load: add fw_load02 for custom firmware path
Hi!
Quoted 35 lines
testcases/kernel/firmware/fw_load/fw_load02.c new file +35
-0+static struct fw_data { +char file[PATH_MAX ]; +char name[MAX_NAME ]; +int fake; +} firmware[FW_NUM ]; + +static void create_firmware (const char *dir) +{ +struct fw_data *fw = &firmware[fw_count]; +char buf[FW_SIZE ]; +int fd; + +snprintf (fw->name,sizeof (fw->name),"n%d_%s" , fw_count,FW_NAME ); +snprintf (fw->file,sizeof (fw->file),"%s/n%d_%s" , dir, fw_count,FW_NAME ); +memset (buf, fw_count,FW_SIZE ); + + fd =SAFE_OPEN (fw->file,O_WRONLY |O_CREAT |O_TRUNC ,0644 ); +SAFE_WRITE (SAFE_WRITE_ALL , fd, buf,FW_SIZE ); +SAFE_CLOSE (fd); + + fw_count++; +} + +static void run (void ) +{ +struct fw_data *fw; +int result =0 ; +int fail; + +SAFE_FILE_PRINTF (DEV_FWNUM ,"%d" , fw_count); +SAFE_FILE_SCANF (DEV_RESULT ,"%d" , &result); + +for (int i =0 ; i < fw_count; i++) { + fw = &firmware[i]; +
testcases/kernel/firmware/fw_load/fw_load02.c line 91
Quoted 10 lines
testcases/kernel/firmware/fw_load/fw_load02.c new file +10
-0+if (fw->fake) { +tst_res (result & (1 << i) ?TFAIL :TPASS , +"Firmware '%s' correctly not loaded" , fw->name); + }else { + fail = (result & (1 << i)) ==0 ; +tst_res (fail ?TFAIL :TPASS , +"Firmware '%s' loaded" , fw->name); + } + } +}
These functions are nearly identical to the fw_load01.c maybe we should put them into a header and include it into both tests instead?
I guess that we can have a static inline function do_test() that would take the fw_data and fw_count as an argument and call it from run(). The same for create_firmare(). We can pas sthe fw_data pointer that would be initialized instead of acting on globals and put it into the shared header.
Quoted 13 lines
testcases/kernel/firmware/fw_load/fw_load02.c new file +13
-0+static void setup (void ) +{ +char fw_size_param[32 ]; +char *tmpdir =tst_tmpdir_path (); + +tst_requires_module_signature_disabled (); + +SAFE_FILE_PRINTF (FW_PATH ,"%s" , tmpdir); + +snprintf (fw_size_param,sizeof (fw_size_param),"fw_size=%d" ,FW_SIZE ); +char *const mod_params[] = {fw_size_param,NULL }; + +tst_module_load (MNAME_KO , mod_params);
testcases/kernel/firmware/fw_load/fw_load02.c line 115
Quoted 10 lines
testcases/kernel/firmware/fw_load/fw_load02.c new file +10
-0+ module_loaded =1 ; + +for (int i =0 ; i <FW_NUM -1 ; i++) +create_firmware (tmpdir); + +/* add a fake file that is never created on disk */ +snprintf (firmware[fw_count].name,sizeof (firmware[fw_count].name), +"n%d_%s" , fw_count,FW_NAME ); + firmware[fw_count].fake =1 ; + fw_count++;
And most of the setup code can be shared as well.
Quoted 30 lines
testcases/kernel/firmware/fw_load/fw_load02.c new file +23
-0+} + +static void cleanup (void ) +{ +if (module_loaded) +tst_module_unload (MNAME_KO ); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .needs_tmpdir =1 , + .needs_kconfigs = (const char *[]) { +"CONFIG_FW_LOADER=y|CONFIG_FW_LOADER=m" , +NULL , + }, + .save_restore = (const struct tst_path_val []) { + {FW_PATH ,NULL ,TST_SR_TCONF }, + {}, + }, +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 4/4] fw_load: add fw_load02 for custom firmware path
Hi Cyril,
Quoted 8 lines
These functions are nearly identical to the
fw_load01.cmaybe we should put them into a header and include it into both tests instead?I guess that we can have a static inline function
do_test()that would take thefw_dataandfw_countas an argument and call it fromrun(). The same forcreate_firmare(). We can pas sthefw_datapointer that would be initialized instead of acting on globals and put it into the shared header.
We can simply share a do_test() in the header indeed, but the setup() part should stay like it is now, because only a tiny bit is actually overlapping.
I will send a new patch.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp