From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v6 4/4] fw_load: add fw_load02 for custom firmware path
Date: Mon, 15 Jun 2026 13:49:27 +0200 [thread overview]
Message-ID: <ai_mxxup2GUblbHn@yuki.lan> (raw)
In-Reply-To: <20260611-fw_load-v6-4-c2aec79a7ed7@suse.com>
Hi!
> +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];
> +
> + 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.
> +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);
> + 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.
> +}
> +
> +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},
> + {},
> + },
> +};
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-06-15 11:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 13:44 [LTP] [PATCH v6 0/4] Rewrite fw_load test using new API Andrea Cervesato
2026-06-11 13:44 ` [LTP] [PATCH v6 1/4] fw_load: Modernize ltp_fw_load kernel module Andrea Cervesato
2026-06-11 14:44 ` [LTP] " linuxtestproject.agent
2026-06-15 11:03 ` [LTP] [PATCH v6 1/4] " Cyril Hrubis
2026-06-11 13:44 ` [LTP] [PATCH v6 2/4] fw_load: rewrite test using new LTP API Andrea Cervesato
2026-06-15 11:33 ` Cyril Hrubis
2026-06-15 11:50 ` Andrea Cervesato via ltp
2026-06-11 13:44 ` [LTP] [PATCH v6 3/4] fw_load: merge module and test into fw_load folder Andrea Cervesato
2026-06-11 13:44 ` [LTP] [PATCH v6 4/4] fw_load: add fw_load02 for custom firmware path Andrea Cervesato
2026-06-15 11:49 ` Cyril Hrubis [this message]
2026-06-15 12:01 ` Andrea Cervesato via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ai_mxxup2GUblbHn@yuki.lan \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox