[PATCH v1 12/41] perf test: Add CPUID matching tests for other architectures

From: Ian Rogers

Date: Tue Nov 03 2026 - 18:49:49 EST


Test strcmp_cpuid_str() for the ELF machines other than arm64: exact
matching of the test and common tables, x86 stepping specific and
stepping optional matching, PowerPC PVR matching, conversion of x86
and PowerPC HEADER_CPUID strings, and regular expression matching for
RISC-V and s390 CPUIDs, where RISC-V's hyphens don't imply an x86
stepping.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/tests/cpuid-match.c | 79 ++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)

diff --git a/tools/perf/tests/cpuid-match.c b/tools/perf/tests/cpuid-match.c
index e3d4a349f393..826380241a0f 100644
--- a/tools/perf/tests/cpuid-match.c
+++ b/tools/perf/tests/cpuid-match.c
@@ -36,8 +36,87 @@ static int test__cpuid_match_arm64(struct test_suite *test __maybe_unused,
return 0;
}

+static int test__cpuid_match_exact(struct test_suite *test __maybe_unused,
+ int subtest __maybe_unused)
+{
+ /* The test and common tables are compared exactly. */
+ TEST_ASSERT_VAL("same", !strcmp_cpuid_str(EM_NONE, "testcpu", "testcpu"));
+ TEST_ASSERT_VAL("different", strcmp_cpuid_str(EM_NONE, "common", "testcpu"));
+ TEST_ASSERT_VAL("no regex", strcmp_cpuid_str(EM_NONE, "test.*", "testcpu"));
+ return 0;
+}
+
+static int test__cpuid_match_x86(struct test_suite *test __maybe_unused,
+ int subtest __maybe_unused)
+{
+ const char *zen3 = "AuthenticAMD-25-([245][[:xdigit:]]|[[:xdigit:]])";
+
+ /* Stepping specific entries. */
+ TEST_ASSERT_VAL("stepping match",
+ !strcmp_cpuid_str(EM_X86_64, "GenuineIntel-6-55-[01234]",
+ "GenuineIntel-6-55-4"));
+ TEST_ASSERT_VAL("stepping mismatch",
+ strcmp_cpuid_str(EM_X86_64, "GenuineIntel-6-55-[56789ABCDEF]",
+ "GenuineIntel-6-55-4"));
+ /* The stepping is ignored when the entry isn't stepping specific. */
+ TEST_ASSERT_VAL("ignore stepping",
+ !strcmp_cpuid_str(EM_X86_64, "GenuineIntel-6-(97|9A|B7|BA|BF)",
+ "GenuineIntel-6-B7-1"));
+ TEST_ASSERT_VAL("model mismatch",
+ strcmp_cpuid_str(EM_X86_64, "GenuineIntel-6-(97|9A|B7|BA|BF)",
+ "GenuineIntel-6-55-4"));
+ /* HEADER_CPUID is "vendor,family,model,step" in decimal, model 85 is 0x55. */
+ TEST_ASSERT_VAL("header stepping match",
+ !strcmp_cpuid_str(EM_X86_64, "GenuineIntel-6-55-[01234]",
+ "GenuineIntel,6,85,4"));
+ TEST_ASSERT_VAL("header ignore stepping",
+ !strcmp_cpuid_str(EM_X86_64, zen3, "AuthenticAMD,25,33,2"));
+ /* 32-bit x86 uses the same comparison. */
+ TEST_ASSERT_VAL("i386", !strcmp_cpuid_str(EM_386, "GenuineIntel-6-55-[01234]",
+ "GenuineIntel-6-55-4"));
+ return 0;
+}
+
+static int test__cpuid_match_powerpc(struct test_suite *test __maybe_unused,
+ int subtest __maybe_unused)
+{
+ TEST_ASSERT_VAL("pvr match",
+ !strcmp_cpuid_str(EM_PPC64, "0x004e[[:xdigit:]]{4}", "0x004e0200"));
+ TEST_ASSERT_VAL("pvr mismatch",
+ strcmp_cpuid_str(EM_PPC64, "0x0080[[:xdigit:]]{4}", "0x004e0200"));
+ /* HEADER_CPUID is "pvr_ver,pvr_rev" in decimal. */
+ TEST_ASSERT_VAL("header pvr match",
+ !strcmp_cpuid_str(EM_PPC64, "0x004e[[:xdigit:]]{4}", "78,512"));
+ TEST_ASSERT_VAL("header pvr mismatch",
+ strcmp_cpuid_str(EM_PPC64, "0x0080[[:xdigit:]]{4}", "78,512"));
+ return 0;
+}
+
+static int test__cpuid_match_regex(struct test_suite *test __maybe_unused,
+ int subtest __maybe_unused)
+{
+ /* Three hyphens in a RISC-V CPUID don't imply an x86 stepping. */
+ TEST_ASSERT_VAL("riscv match",
+ !strcmp_cpuid_str(EM_RISCV, "0x489-0x8000000000000007-0x[[:xdigit:]]+",
+ "0x489-0x8000000000000007-0x0000000000000001"));
+ TEST_ASSERT_VAL("riscv mismatch",
+ strcmp_cpuid_str(EM_RISCV, "0x489-0x8000000000000008-0x[[:xdigit:]]+",
+ "0x489-0x8000000000000007-0x0000000000000001"));
+ TEST_ASSERT_VAL("s390 match",
+ !strcmp_cpuid_str(EM_S390, "^IBM.209[78].*[13]\\.[1-5].[[:xdigit:]]+$",
+ "IBM,2097,705,T01,1.3,002f"));
+ /* The whole CPUID must match. */
+ TEST_ASSERT_VAL("partial match",
+ strcmp_cpuid_str(EM_S390, "IBM,2097", "IBM,2097,705,T01,1.3,002f"));
+ return 0;
+}
+
static struct test_case tests__cpuid_match[] = {
TEST_CASE("arm64 MIDR", cpuid_match_arm64),
+ TEST_CASE("Exact test and common tables", cpuid_match_exact),
+ TEST_CASE("x86", cpuid_match_x86),
+ TEST_CASE("PowerPC", cpuid_match_powerpc),
+ TEST_CASE("Regular expression", cpuid_match_regex),
{ .name = NULL, }
};

--
2.56.0.385.gac671c819a-goog