|
9 | 9 | #include <math.h>
|
10 | 10 | #include <stdlib.h>
|
11 | 11 | #include <string.h>
|
| 12 | +#include <string2.h> |
12 | 13 | #include <linux/zalloc.h>
|
13 | 14 |
|
14 | 15 | static int test_ids_union(void)
|
@@ -74,10 +75,13 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
|
74 | 75 | int ret;
|
75 | 76 | struct expr_parse_ctx *ctx;
|
76 | 77 | bool is_intel = false;
|
77 |
| - char buf[128]; |
| 78 | + char strcmp_cpuid_buf[256]; |
| 79 | + struct perf_pmu *pmu = pmu__find_core_pmu(); |
| 80 | + char *cpuid = perf_pmu__getcpuid(pmu); |
| 81 | + char *escaped_cpuid1, *escaped_cpuid2; |
78 | 82 |
|
79 |
| - if (!get_cpuid(buf, sizeof(buf))) |
80 |
| - is_intel = strstr(buf, "Intel") != NULL; |
| 83 | + TEST_ASSERT_VAL("get_cpuid", cpuid); |
| 84 | + is_intel = strstr(cpuid, "Intel") != NULL; |
81 | 85 |
|
82 | 86 | TEST_ASSERT_EQUAL("ids_union", test_ids_union(), 0);
|
83 | 87 |
|
@@ -257,9 +261,28 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
|
257 | 261 | TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1);
|
258 | 262 | TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr));
|
259 | 263 |
|
| 264 | + |
| 265 | + /* Test no cpuid match */ |
| 266 | + ret = test(ctx, "strcmp_cpuid_str(0x0)", 0); |
| 267 | + |
| 268 | + /* |
| 269 | + * Test cpuid match with current cpuid. Special chars have to be |
| 270 | + * escaped. |
| 271 | + */ |
| 272 | + escaped_cpuid1 = strreplace_chars('-', cpuid, "\\-"); |
| 273 | + free(cpuid); |
| 274 | + escaped_cpuid2 = strreplace_chars(',', escaped_cpuid1, "\\,"); |
| 275 | + free(escaped_cpuid1); |
| 276 | + escaped_cpuid1 = strreplace_chars('=', escaped_cpuid2, "\\="); |
| 277 | + free(escaped_cpuid2); |
| 278 | + scnprintf(strcmp_cpuid_buf, sizeof(strcmp_cpuid_buf), |
| 279 | + "strcmp_cpuid_str(%s)", escaped_cpuid1); |
| 280 | + free(escaped_cpuid1); |
| 281 | + ret |= test(ctx, strcmp_cpuid_buf, 1); |
| 282 | + |
260 | 283 | /* has_event returns 1 when an event exists. */
|
261 | 284 | expr__add_id_val(ctx, strdup("cycles"), 2);
|
262 |
| - ret = test(ctx, "has_event(cycles)", 1); |
| 285 | + ret |= test(ctx, "has_event(cycles)", 1); |
263 | 286 |
|
264 | 287 | expr__ctx_free(ctx);
|
265 | 288 |
|
|
0 commit comments