Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1435163rdb; Mon, 4 Sep 2023 14:06:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7cgEIfulMWGPgJvCsTJhu5T/LM0hxwZciKV9P+mMMA7BNqdswU3cxWGQ6WDfTa1q+RIOk X-Received: by 2002:a17:902:c412:b0:1c3:3dae:5869 with SMTP id k18-20020a170902c41200b001c33dae5869mr4027792plk.63.1693861592349; Mon, 04 Sep 2023 14:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693861592; cv=none; d=google.com; s=arc-20160816; b=lfJcX/cy2+8yqcapo+SPY7fDlcWtSzdcpXpagqcJDSO4pb2khqmNOrwxd+i6mPN5O5 8RAoo5xuB8RS1tfd7l0r9RyKhFjSjq3HYaCnvvWv5JcqQ2nC3zqDYYNQmBqt+3LWvm2W lo8pe+kVC4DAMxuOtA75pmT+0QM9GZ63EbPUGaTFfrzfty7UEzGg37/v8gaUthBKPGzl e910d2x2mYqIsZpqZIha85Aes4VFdNbFTXNYaWTol77yKdcuLTBlIGxUd4R5cJ+zXGDz f4QoR8Dhs4VbawV2ueNj4LY7NGs3LdEjLosdTWT2DVRG8beOP1t47onCOMaK2SBMpvjP oUyA== 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=LLcRv0W9ehJuAzrSZuXrLJNCC8PWFLPklhsX9H9BHzI=; fh=v2hp+ajopg+aEBvDbqX80Ysctn2jAXWeaxJHXHVR728=; b=KiVlQqD7PYSZIszZyaWmVAy8O0gqMJHmW0FEbS5uRjhNibE8sbdOkV57ulG+sZ9ezq SCQg6/l0YQO2OYn2N/MxjM9m9XXR44vpdIDrW+YUAygUfD+U07YgtElHkuYoXJazYy1I jE6Xy2tZHtTeI90+2rL6qKIw747YCS9OsA6aGBZNgpsZbIgr+Va86Ga9+5bViH2PCCIS lICIQCHjrQcYUa7Gu7V12j9O7NJyEfuQqVrQhGm413kSwu2/cvTe72Q6tnB2ZQoCoDLT sgcgnsLLdmu04DzQ++3p4g4udpcvuJQfYwJH6VDE3M0c1JqcRoK14gsR0BNxVeDCQ1k5 jl+g== 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 44-20020a17090a09af00b00262e3c1c1efsi8373020pjo.79.2023.09.04.14.06.19; Mon, 04 Sep 2023 14:06:32 -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 S1352693AbjIDJxL (ORCPT + 99 others); Mon, 4 Sep 2023 05:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352702AbjIDJxK (ORCPT ); Mon, 4 Sep 2023 05:53:10 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E84BE5D; Mon, 4 Sep 2023 02:53:04 -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 495AC1042; Mon, 4 Sep 2023 02:53:42 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F3A513F793; Mon, 4 Sep 2023 02:53:00 -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 , Kan Liang , Haixin Yu , Jing Zhang , Kajol Jain , Madhavan Srinivasan , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Chen Zhongjin , Liam Howlett , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 4/7] perf test: Add a test for strcmp_cpuid_str() expression Date: Mon, 4 Sep 2023 10:50:46 +0100 Message-Id: <20230904095104.1162928-5-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230904095104.1162928-1-james.clark@arm.com> References: <20230904095104.1162928-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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". Reviewed-by: Ian Rogers 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