#include <math.h>
 #include <stdlib.h>
 #include <string.h>
+#include <string2.h>
 #include <linux/zalloc.h>
 
 static int test_ids_union(void)
        int ret;
        struct expr_parse_ctx *ctx;
        bool is_intel = false;
-       char buf[128];
+       char strcmp_cpuid_buf[256];
+       struct perf_pmu *pmu = pmu__find_core_pmu();
+       char *cpuid = perf_pmu__getcpuid(pmu);
+       char *escaped_cpuid1, *escaped_cpuid2;
 
-       if (!get_cpuid(buf, sizeof(buf)))
-               is_intel = strstr(buf, "Intel") != NULL;
+       TEST_ASSERT_VAL("get_cpuid", cpuid);
+       is_intel = strstr(cpuid, "Intel") != NULL;
 
        TEST_ASSERT_EQUAL("ids_union", test_ids_union(), 0);
 
        TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1);
        TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr));
 
+
+       /* Test no cpuid match */
+       ret = test(ctx, "strcmp_cpuid_str(0x0)", 0);
+
+       /*
+        * Test cpuid match with current cpuid. Special chars have to be
+        * escaped.
+        */
+       escaped_cpuid1 = strreplace_chars('-', cpuid, "\\-");
+       free(cpuid);
+       escaped_cpuid2 = strreplace_chars(',', escaped_cpuid1, "\\,");
+       free(escaped_cpuid1);
+       escaped_cpuid1 = strreplace_chars('=', escaped_cpuid2, "\\=");
+       free(escaped_cpuid2);
+       scnprintf(strcmp_cpuid_buf, sizeof(strcmp_cpuid_buf),
+                 "strcmp_cpuid_str(%s)", escaped_cpuid1);
+       free(escaped_cpuid1);
+       ret |= test(ctx, strcmp_cpuid_buf, 1);
+
        /* has_event returns 1 when an event exists. */
        expr__add_id_val(ctx, strdup("cycles"), 2);
-       ret = test(ctx, "has_event(cycles)", 1);
+       ret |= test(ctx, "has_event(cycles)", 1);
 
        expr__ctx_free(ctx);