From nobody Fri Dec 19 21:12:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F192C83F2F for ; Thu, 31 Aug 2023 15:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346262AbjHaPSE (ORCPT ); Thu, 31 Aug 2023 11:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233904AbjHaPSD (ORCPT ); Thu, 31 Aug 2023 11:18:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3AE2EE55; Thu, 31 Aug 2023 08:18:00 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3D0CDC15; Thu, 31 Aug 2023 08:18:39 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 77AC53F64C; Thu, 31 Aug 2023 08:17:56 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kajol Jain , Jing Zhang , Haixin Yu , Madhavan Srinivasan , Kan Liang , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Chen Zhongjin , Liam Howlett , Miguel Ojeda , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/7] perf test: Add a test for strcmp_cpuid_str() expression Date: Thu, 31 Aug 2023 16:16:15 +0100 Message-Id: <20230831151632.124985-5-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Test that the new expression builtin returns a match when the current escaped CPU ID is given, and that it doesn't match when "0x0" is given. The CPU ID in test__expr() has to be changed to perf_pmu__getcpuid() which returns the CPU ID string, rather than the raw CPU ID that get_cpuid() returns because that can't be used with strcmp_cpuid_str(). It doesn't affect the is_intel test because both versions contain "Intel". Signed-off-by: James Clark --- tools/perf/tests/expr.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 39be7f3b3a53..78544092ef0c 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -9,6 +9,7 @@ #include #include #include +#include #include =20 static int test_ids_union(void) @@ -74,10 +75,13 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u int ret; struct expr_parse_ctx *ctx; bool is_intel =3D false; - char buf[128]; + char strcmp_cpuid_buf[256]; + struct perf_pmu *pmu =3D pmu__find_core_pmu(); + char *cpuid =3D perf_pmu__getcpuid(pmu); + char *escaped_cpuid1, *escaped_cpuid2; =20 - if (!get_cpuid(buf, sizeof(buf))) - is_intel =3D strstr(buf, "Intel") !=3D NULL; + TEST_ASSERT_VAL("get_cpuid", cpuid); + is_intel =3D strstr(cpuid, "Intel") !=3D NULL; =20 TEST_ASSERT_EQUAL("ids_union", test_ids_union(), 0); =20 @@ -257,9 +261,28 @@ static int test__expr(struct test_suite *t __maybe_unu= sed, int subtest __maybe_u TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) =3D=3D 1); TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_pt= r)); =20 + + /* Test no cpuid match */ + ret =3D test(ctx, "strcmp_cpuid_str(0x0)", 0); + + /* + * Test cpuid match with current cpuid. Special chars have to be + * escaped. + */ + escaped_cpuid1 =3D strreplace_chars('-', cpuid, "\\-"); + free(cpuid); + escaped_cpuid2 =3D strreplace_chars(',', escaped_cpuid1, "\\,"); + free(escaped_cpuid1); + escaped_cpuid1 =3D strreplace_chars('=3D', escaped_cpuid2, "\\=3D"); + free(escaped_cpuid2); + scnprintf(strcmp_cpuid_buf, sizeof(strcmp_cpuid_buf), + "strcmp_cpuid_str(%s)", escaped_cpuid1); + free(escaped_cpuid1); + ret |=3D test(ctx, strcmp_cpuid_buf, 1); + /* has_event returns 1 when an event exists. */ expr__add_id_val(ctx, strdup("cycles"), 2); - ret =3D test(ctx, "has_event(cycles)", 1); + ret |=3D test(ctx, "has_event(cycles)", 1); =20 expr__ctx_free(ctx); =20 --=20 2.34.1