From: Cyril Hrubis <chrubis@suse.cz>
To: lufei <lufei@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] Add case about arch_prctl syscall.
Date: Mon, 6 May 2024 11:53:44 +0200 [thread overview]
Message-ID: <ZjioqEwx22mjFYux@yuki> (raw)
In-Reply-To: <20240506070336.2711930-2-lufei@uniontech.com>
Hi!
> +static void run(unsigned int index)
> +{
> + FILE *fd;
Please do not call FILE * pointer fd, that is confusing since fd is
usually a file descriptor. FILE * pointer is usually just call f.
> + char needed_flag[] = "cpuid_fault";
I would include the space before flag name just to be extra careful we
do not match anything that has this as a substring. E.g. if in the
future they add something that would be named "no_cpuid_fault" this
would still match strstr(line, "cpuid_fault") but not
strstr(line, " cpuid_fault"); Ideally we would check that there is a
space after the string, but we can't just do that with strstr() since
the flag may be actually last in the list. So the only posibility would
be using the pointer from strstr() and checking that the character after
the matched string is also a space.
> + char *line = NULL;
> + size_t len = 0;
> + bool tag = 0;
> +
> + fd = SAFE_FOPEN("/proc/cpuinfo", "r");
> +
> + while (getline(&line, &len, fd) != -1) {
> + if (strncmp(line, "flag", strlen("flag")) == 0 &&
^
why not just whole "flags" ?
> + strstr(line, needed_flag) != NULL) {
> + tag = 1;
> + break;
> + }
> + }
This whole check for flag should be done in the test setup so that we do
not parse the /proc/cpuinfo on each test iteration (-i command line
option).
> + if (!tag)
> + tst_brk(TCONF, "CPU need %s flag.", needed_flag);
Why don't we check that the prctl() returns ENODEV when the flag is not
present. That is a valid testcase as well.
> + // index == 0 for disable cpuid, 1 for enable cpuid.
> + TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
> +
> + TEST(arch_prctl_get(ARCH_GET_CPUID));
> +
> + if (TST_RET == index)
> + tst_res(TPASS, "get cpuid succeed.");
> + else
> + tst_res(TFAIL, "get cpuid failed.");
> +}
> +
> +static struct tst_test test = {
> + .test = run,
> + .tcnt = 2,
> + .min_kver = "4.12",
> + .supported_archs = (const char *const []){"x86_64", "x86", NULL}
> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> --
> 2.39.3
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-05-06 9:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-19 15:46 ` Cyril Hrubis
2024-04-21 6:25 ` lufei
2024-04-21 7:15 ` [LTP] (no subject) lufei
2024-04-21 7:15 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-26 8:36 ` [LTP] (no subject) Cyril Hrubis
2024-04-26 9:42 ` 路斐
2024-04-26 10:28 ` Cyril Hrubis
2024-04-26 12:27 ` 路斐
2024-04-26 12:47 ` Jan Stancek
2024-04-23 1:05 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-28 7:44 ` [LTP] (no subject) lufei
2024-04-28 7:44 ` [LTP] [PATCH] Add case about arch_prctl syscall lufei
2024-04-29 15:02 ` Cyril Hrubis
[not found] ` <20240506070336.2711930-1-lufei@uniontech.com>
2024-05-06 7:03 ` lufei
2024-05-06 9:53 ` Cyril Hrubis [this message]
[not found] ` <20240507043235.1692-1-lufei@uniontech.com>
2024-05-07 4:32 ` lufei
2024-05-07 12:50 ` Cyril Hrubis
2024-05-08 2:29 ` 路斐
[not found] ` <20240508015852.3362-1-lufei@uniontech.com>
2024-05-08 1:58 ` lufei
2024-05-09 10:27 ` Cyril Hrubis
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=ZjioqEwx22mjFYux@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=lufei@uniontech.com \
/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