tst_test: Add needs_cpu_vendor to struct tst_test
PATCH 1/1 tst_test: Add needs_cpu_vendor to struct tst_test
This adds a generic implementaiton of needs_cpu_vendor to the tst_test structure that is based on parsing /proc/cpuinfo. It does not likely work for non-x86 CPUs since the /proc/cpuinfo format is different, but we do not care at the moment. For arm we would have to look at the implementer field instead, we will add that if/once needed.
--- include/tst_cpu.h | 9 +++++++++ include/tst_test.h | 5 +++++ lib/newlib_tests/.gitignore | 1 + lib/newlib_tests/test_cpu_vendor.c | 16 ++++++++++++++++ lib/tst_cpu.c | 18 ++++++++++++++++++ lib/tst_test.c | 5 +++++ 6 files changed, 54 insertions(+) create mode 100644 lib/newlib_tests/test_cpu_vendor.c
include/tst_cpu.h +9 -0
@@ -10,6 +10,13 @@ long tst_ncpus_conf(void);long tst_ncpus_max (void );long tst_ncpus_available (void ); +/** +* tst_cpu_vendor() - Returns CPU vendor. +* +* Return: A CPU vendor e.g. "GenuineIntel" or "AuthenticAMD". +*/ +const char *tst_cpu_vendor (void ); +#define VIRT_ANY 0/* catch-all argument for tst_is_virt() */ #define VIRT_XEN 1/* xen dom0/domU */ #define VIRT_KVM 2/* only default virtual CPU */
@@ -21,4 +28,6 @@ long tst_ncpus_available(void);int tst_is_virt (int virt_type); + +#endif /* TST_CPU_H__ */
include/tst_test.h +5 -0
@@ -391,6 +391,9 @@ struct tst_fs {* * @min_cpus: Minimal number of online CPUs the test needs to run. * +* @needs_cpu_vendor: The test needs a specific CPU vendor e.g. "GenuineIntel" +* or "AuthenticAMD". +* * @min_mem_avail: Minimal amount of available RAM memory in megabytes required * for the test to run. *
@@ -581,6 +584,8 @@ struct tst_fs {const char *const *skip_filesystems;unsigned long min_cpus; +const char *needs_cpu_vendor; +unsigned long min_mem_avail;unsigned long min_swap_avail;
lib/newlib_tests/.gitignore +1 -0
@@ -71,3 +71,4 @@ test_brk_parent test_brk_pass test_brk_variant test_fail_variant +test_cpu_vendor
lib/newlib_tests/test_cpu_vendor.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Cyril Hrubis <[email protected]> +*/ + +#include "tst_test.h" + +static void do_test (void ) +{ +tst_res (TPASS ,"Test passed!" ); +} + +static struct tst_test test = { + .test_all = do_test, + .needs_cpu_vendor ="Nonexistent" , +};
lib/tst_cpu.c +18 -0
@@ -23,6 +23,7 @@#include <unistd.h> #include "test.h" #include "tso_safe_macros.h" +#include "tso_safe_file_ops.h" long tst_ncpus (void ) {
@@ -97,3 +98,20 @@ long tst_ncpus_available(void)return tst_ncpus ();#endif } + +const char *tst_cpu_vendor (void ) +{ +static char cpu_vendor[16 ]; +int ret; + +if (cpu_vendor[0 ]) +return cpu_vendor; + + ret =FILE_LINES_SCANF (NULL ,"/proc/cpuinfo" ,"vendor_id : %16s[^\n]" , cpu_vendor); +if (ret) +strcpy (cpu_vendor,"Unknown" ); + +tst_resm (TDEBUG ,"CPU vendor '%s'" , cpu_vendor); + +return cpu_vendor; +}
lib/tst_test.c +5 -0
@@ -1416,6 +1416,11 @@ static void do_setup(int argc, char *argv[])if (tst_test->supported_archs && !tst_is_on_arch (tst_test->supported_archs))tst_brk (TCONF ,"This arch '%s' is not supported for test!" , tst_arch.name); +if (tst_test->needs_cpu_vendor &&strcmp (tst_test->needs_cpu_vendor,tst_cpu_vendor ())) { +tst_brk (TCONF ,"Tests needs '%s' CPU to continue have '%s'" , + tst_test->needs_cpu_vendor,tst_cpu_vendor ()); + } +if (tst_test->sample) tst_test =tst_timer_test_setup (tst_test);
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines · Cyril Hrubis
This adds a generic implementaiton of
needs_cpu_vendorto thetst_teststructure that is based on parsing/proc/cpuinfo. It does not likely work for non-x86 CPUs since the/proc/cpuinfoformat is different, but we do not care at the moment. For arm we would have to look at the implementer field instead, we will add that if/once needed.Signed-off-by Cyril Hrubis <[email protected]>CC Piotr Kubaj <[email protected]>
I'm curios what test needs it.
Quoted 145 lines
--- include/tst_cpu.h | 9 +++++++++ include/tst_test.h | 5 +++++ lib/newlib_tests/.gitignore | 1 + lib/newlib_tests/test_cpu_vendor.c | 16 ++++++++++++++++ lib/tst_cpu.c | 18 ++++++++++++++++++ lib/tst_test.c | 5 +++++ 6 files changed, 54 insertions(+) create mode 100644 lib/newlib_tests/test_cpu_vendor.cinclude/tst_cpu.h +9
-0@@ -10,6 +10,13 @@ long tst_ncpus_conf(void);long tst_ncpus_max (void );long tst_ncpus_available (void ); +/** +* tst_cpu_vendor() - Returns CPU vendor. +* +* Return: A CPU vendor e.g. "GenuineIntel" or "AuthenticAMD". +*/ +const char *tst_cpu_vendor (void ); +#define VIRT_ANY 0/* catch-all argument for tst_is_virt() */ #define VIRT_XEN 1/* xen dom0/domU */ #define VIRT_KVM 2/* only default virtual CPU */ @@ -21,4 +28,6 @@ long tst_ncpus_available(void);int tst_is_virt (int virt_type); + +#endif /* TST_CPU_H__ */ include/tst_test.h +5
-0@@ -391,6 +391,9 @@ struct tst_fs {* * @min_cpus: Minimal number of online CPUs the test needs to run. * +* @needs_cpu_vendor: The test needs a specific CPU vendor e.g. "GenuineIntel" +* or "AuthenticAMD". +* * @min_mem_avail: Minimal amount of available RAM memory in megabytes required * for the test to run. * @@ -581,6 +584,8 @@ struct tst_fs {const char *const *skip_filesystems;unsigned long min_cpus; +const char *needs_cpu_vendor; +unsigned long min_mem_avail;unsigned long min_swap_avail;lib/newlib_tests/.gitignore +1
-0@@ -71,3 +71,4 @@ test_brk_parent test_brk_pass test_brk_variant test_fail_variant +test_cpu_vendorlib/newlib_tests/test_cpu_vendor.c new file +16
-0@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Cyril Hrubis <[email protected]> +*/ + +#include "tst_test.h" + +static void do_test (void ) +{ +tst_res (TPASS ,"Test passed!" ); +} + +static struct tst_test test = { + .test_all = do_test, + .needs_cpu_vendor ="Nonexistent" , +};lib/tst_cpu.c +18
-0@@ -23,6 +23,7 @@#include <unistd.h> #include "test.h" #include "tso_safe_macros.h" +#include "tso_safe_file_ops.h" long tst_ncpus (void ) {@@ -97,3 +98,20 @@ long tst_ncpus_available(void)return tst_ncpus ();#endif } + +const char *tst_cpu_vendor (void ) +{ +static char cpu_vendor[16 ]; +int ret; + +if (cpu_vendor[0 ]) +return cpu_vendor; + + ret =FILE_LINES_SCANF (NULL ,"/proc/cpuinfo" ,"vendor_id : %16s[^\n]" , cpu_vendor); +if (ret) +strcpy (cpu_vendor,"Unknown" ); + +tst_resm (TDEBUG ,"CPU vendor '%s'" , cpu_vendor); + +return cpu_vendor; +}lib/tst_test.c +5
-1@@ -1416,6 +1416,11 @@ static void do_setup(int argc, char *argv[])if (tst_test->supported_archs && !tst_is_on_arch (tst_test->supported_archs))tst_brk (TCONF ,"This arch '%s' is not supported for test!" , tst_arch.name); +if (tst_test->needs_cpu_vendor &&strcmp (tst_test->needs_cpu_vendor,tst_cpu_vendor ())) { +tst_brk (TCONF ,"Tests needs '%s' CPU to continue have '%s'" , + tst_test->needs_cpu_vendor,tst_cpu_vendor ()); + } +if (tst_test->sample) tst_test =tst_timer_test_setup (tst_test); --2.53.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 6 lines
Quoted 6 lines
This adds a generic implementaiton of
needs_cpu_vendorto thetst_teststructure that is based on parsing/proc/cpuinfo. It does not likely work for non-x86 CPUs since the/proc/cpuinfoformat is different, but we do not care at the moment. For arm we would have to look at the implementer field instead, we will add that if/once needed.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Cyril Hrubis <[email protected]>CC Piotr Kubaj <[email protected]>Acked-by Jan Stancek <[email protected]>I'm curios what test needs it.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 4 lines
Quoted 2 lines
Signed-off-by Cyril Hrubis <[email protected]>CC Piotr Kubaj <[email protected]>Acked-by Jan Stancek <[email protected]>
I've fixed the issues reported by the ltp-agent and pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Quoted 3 lines · Cyril Hrubis
tst_test: Addneeds_cpu_vendorto structtst_testThis adds a generic implementaiton of
needs_cpu_vendorto thetst_test
Typo: "implementaiton" -> "implementation".
lib/tst_cpu.c long tst_ncpus_available(void) · line 110
Quoted 5 lines
lib/tst_cpu.c +4
-0+const char *tst_cpu_vendor (void ) +{ +static char cpu_vendor[16 ]; + ret =FILE_LINES_SCANF (NULL ,"/proc/cpuinfo" ,"vendor_id : %16s[^\n]" , cpu_vendor);
Two issues with the scanf format:
1) The width specifier %16s allows writing up to 16 characters plus a NUL terminator into a 16-byte buffer, which is a one-byte overflow. Should be %15s.
2) The [^\n] after %16s is treated as literal text to match, not as a scanset. It is effectively dead and does not do what it looks like it should. Either drop it, or if the intent was to match characters including spaces use %15[^\n] as the conversion specifier (but vendor_id values are single words so %15s should be fine).
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1422
Quoted 4 lines
lib/tst_test.c +4
-0+if (tst_test->needs_cpu_vendor &&strcmp (tst_test->needs_cpu_vendor,tst_cpu_vendor ())) { +tst_brk (TCONF ,"Tests needs '%s' CPU to continue have '%s'" , + tst_test->needs_cpu_vendor,tst_cpu_vendor ()); + }
The message has a grammar issue. Something like "Test needs '%s' CPU, have '%s'" would read better.
include/tst_cpu.h long tst_ncpus_available(void); · line 33
Quoted 6 lines
include/tst_cpu.h +3
-0+ + +#endif /* TST_CPU_H__ */
Two extra blank lines were added before #endif.
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