[LTP] [PATCH] tst_test: Add needs_cpu_vendor to struct tst_test
Cyril Hrubis
chrubis@suse.cz
Tue Jun 9 16:32:37 CEST 2026
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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
CC: Piotr Kubaj <piotr.kubaj@intel.com>
---
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
diff --git a/include/tst_cpu.h b/include/tst_cpu.h
index 0724975f0..31222a3e1 100644
--- a/include/tst_cpu.h
+++ b/include/tst_cpu.h
@@ -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__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index 9bc67cf6a..c69362485 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -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;
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 1586e0ad6..b85163824 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -71,3 +71,4 @@ test_brk_parent
test_brk_pass
test_brk_variant
test_fail_variant
+test_cpu_vendor
diff --git a/lib/newlib_tests/test_cpu_vendor.c b/lib/newlib_tests/test_cpu_vendor.c
new file mode 100644
index 000000000..10b473b7e
--- /dev/null
+++ b/lib/newlib_tests/test_cpu_vendor.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#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",
+};
diff --git a/lib/tst_cpu.c b/lib/tst_cpu.c
index faffcba91..177661c82 100644
--- a/lib/tst_cpu.c
+++ b/lib/tst_cpu.c
@@ -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;
+}
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 0bebb0a3e..5f7156403 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -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
More information about the ltp
mailing list