Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp296978rdb; Thu, 31 Aug 2023 09:34:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoW56r2f6/QhkiQiPAkUJYTwySW7iwIdHHwDgYGOQ8X6/L7nqc4r11voYnEzqRYPzsaKoM X-Received: by 2002:a05:6402:1287:b0:521:e502:baf8 with SMTP id w7-20020a056402128700b00521e502baf8mr84725edv.11.1693499697373; Thu, 31 Aug 2023 09:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693499697; cv=none; d=google.com; s=arc-20160816; b=QzhqmlRnpcfh7pr3QThssDdziTJAhWjIZiff7etWdM/HcaN7i8JPWEUNlAkgBobGdn Ww3SnlJvJHDuTf08xIankUgKFX3CgsZLNKl8p5t0UVDWqJDyQuhgFEMLMLtAT9DQO0Ox fCmFPYbapRV3BeG3sGD160/6MEEChjL1zxZ9+nRGPYfJGRY8vsEq38WDqPsPZopfUV99 5pFluZrq4sstgz1IW9U9ci2ZNiQONkCCaK3gqiNn8zhX1dNLEL/tkKJuoswKPRw7+s7+ zqNcPER0WCdG8DrVcWFphOs0no5GqiTeOJjncI7KASv+gM314GQIyk9SHGQe4GQTXFZT WU8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3NzBVDXdPK9k6IG2c3tJsbET6zNw0Iga6PDzJxhQeVs=; fh=MZfRW7sh34lusVQTwxTd+WYgDSOm2jte0vD3GL0+T1A=; b=bNrc+ZPbbE8pKTi+NvpzrDzmwc2dll0sTwkwrqrfzdhDxxaAEg5psaV8friWuHrBhI W7fnSFPvCQpDCaBxM6eY5JtMpfSm9iAO5BzpHjr3yEs71fF2xe25IIMfgLUmed11neaa fKZ5t5yssp4GAXRdVYAdxznVdxhyEcVXtcnzKQwrqVCNfa3ki3iTh5nL6ATFLNIbjzg2 dlvpDJL07bNHpB6ahPC0Py0RKcQYB3YAZj1u7FGyZY6GFWT3Bq5IVGOZJ+1UcTg5l/un /I3TwZqMAj3EcFpKPY/2QUmtt8lErEXQ6LGE1Q2Ec3YpMHMiqIbR1Zd6mDarzXLJSgbN vVTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020aa7de05000000b005233d0a02absi1216582edv.29.2023.08.31.09.34.28; Thu, 31 Aug 2023 09:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345434AbjHaPSD (ORCPT + 99 others); Thu, 31 Aug 2023 11:18:03 -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: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 static int test_ids_union(void) @@ -74,10 +75,13 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u 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); @@ -257,9 +261,28 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u 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); -- 2.34.1