From patchwork Sat Sep 7 05:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13795086 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 228BDE6FE47 for ; Sat, 7 Sep 2024 05:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V/Ar3dUi50U5MkQ1SlyAwk/I3yarddmL36DdZBmDzV4=; b=bWBoKtsj7WQIpO5Sr0U95DvsYh iGKqOwKwgxrVffhmZSb3Os0ooNW6Lwaa3lvppzKRYo9lxYnUZjI7h3m/IO0S4Y2xnM7moIGEEmRSp bDLwx9kFUNGSujnqYJT04pJ4tJhSbJr+jknv6+3EsntlJ6YpOJ01nPBJSPgTRJvQy5E3TVPPQ3O1F pXb5haJWm/5sJLiLjicrqdR2G4RSOeXg7H9XNnCQkv9qaO+gOaIEnJCAlQJadmj7xRn5XpH62z5FE 73ey2yaquaAWZUbThkEhCh3wnTgrqEbPXFaJaJwpP8ZKPWy4OFn8tK8GmFBsT08m2RFUAjwxYNl+H O+lHRAfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smnuD-0000000EOSQ-0vV8; Sat, 07 Sep 2024 05:22:41 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smnh9-0000000EMPZ-1cZA for linux-arm-kernel@lists.infradead.org; Sat, 07 Sep 2024 05:09:12 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e1ce98dcafaso5884536276.0 for ; Fri, 06 Sep 2024 22:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685750; x=1726290550; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=V/Ar3dUi50U5MkQ1SlyAwk/I3yarddmL36DdZBmDzV4=; b=gGSUTpSjqwGHZcUPty8pzcHysajd3+rZOKS4e7EYvJxjNtPnhhJK0582YIwkFh2yEp JIgYyJ+l06hY8j3mPnUP5BMiLaHkfeuNjjuLS+9DcORLMi9maKOPN1D17DO2ZC4h1FBU /bAEs2Gfnm6/V66HS49pnp9DE++gRQpzVN7hkT5M+javZ5Bm3lOj+sQgTKJ91G6f+mvR OOWsE7MyjrogazdXqhEujx9ThuEDeGkv5hGyv2cNVvRiwfXXF6YL0b0I89E5UxH0Lpp+ m/atCAgKWdrKkTcuVHOSHkHI+0j6Msd7scNhNpd8tQK+AQviz4DeBsBKrz6dZrDl64MM 5vsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685750; x=1726290550; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V/Ar3dUi50U5MkQ1SlyAwk/I3yarddmL36DdZBmDzV4=; b=J9VT7NIBGxUzMiLJP77tPCO02XaN1YjBpZOpvXedsk1DurOTaUah7Q4YpOayEB03Lg 6yyWKaYk0BG0mKI840ouNRTfUcukchByyTfrqBuBz8eE2Fa7TJR2tZ+c1uGsYs6SYrkB 4kpXQquo1swqm3O2NT/mao5sTew4ElQ93mDu+UqZu0hGj3OEiwPyu4CyxCux5CQ5VC1l MyyMkbbMCJPoRuiqOwAge8CtPEanASeeqQBkiXYKm+bSrjAcFmvASnTLhRE7ovyHtP5O vnvpgStlnqJ7YO+YVJuGHEpZxmqQhNVwoKCX5u7OWqgKLLj4d//Rlmx7xKtdtQkHus+h OumA== X-Forwarded-Encrypted: i=1; AJvYcCVy6P0vbb1ZeZ6CcO7zXYV7zL/JPGl5d7ETIlyNcdRYZnkOuvEDFJZzyqsr3Co2Na4p5bUtstr314PH0ov6E59z@lists.infradead.org X-Gm-Message-State: AOJu0YypA0BOOA5UZPBjWpWDOnlZUHShpSe/DQHp9wz7w1j997ngoqJE o7D7AzKZfTI+c7ZH0ZYh1wCoOEm8MKme9lzBAdHjMS0UWdPzR98ySVSHGwrrt4QGr8RC2PARkFP 0wdMR7Q== X-Google-Smtp-Source: AGHT+IE8fHd4LfbapRE/tIEDY9qTS5Fj2ijGjPzlTc2FTO6xmYM62oDetj4uPSv3jpaKIE4fx+/hRNzhtD5i X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a5b:c0c:0:b0:e11:5f87:1e3c with SMTP id 3f1490d57ef6-e1d34a7f845mr40886276.11.1725685749881; Fri, 06 Sep 2024 22:09:09 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:28 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-14-irogers@google.com> Mime-Version: 1.0 References: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 13/15] perf tests: Add tool PMU test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_220911_483338_81C10701 X-CRM114-Status: GOOD ( 19.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ensure parsing with and without PMU creates events with the expected config values. This ensures the tool.json doesn't get out of sync with tool_pmu_event enum. Signed-off-by: Ian Rogers --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + tools/perf/tests/tool_pmu.c | 111 ++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tools/perf/tests/tool_pmu.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 5671ee530019..a771e4928247 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -67,6 +67,7 @@ perf-test-y += sigtrap.o perf-test-y += event_groups.o perf-test-y += symbols.o perf-test-y += util.o +perf-test-y += tool_pmu.o ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) perf-test-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 470a9709427d..3b30f258c395 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -73,6 +73,7 @@ static struct test_suite *generic_tests[] = { &suite__PERF_RECORD, &suite__pmu, &suite__pmu_events, + &suite__tool_pmu, &suite__dso_data, &suite__perf_evsel__roundtrip_name_test, #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 6ea2be86b7bf..1ed76d4156b6 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -83,6 +83,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test); DECLARE_SUITE(syscall_openat_tp_fields); DECLARE_SUITE(pmu); DECLARE_SUITE(pmu_events); +DECLARE_SUITE(tool_pmu); DECLARE_SUITE(attr); DECLARE_SUITE(dso_data); DECLARE_SUITE(dso_data_cache); diff --git a/tools/perf/tests/tool_pmu.c b/tools/perf/tests/tool_pmu.c new file mode 100644 index 000000000000..94d0dd8fd3cb --- /dev/null +++ b/tools/perf/tests/tool_pmu.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "tests.h" +#include "tool_pmu.h" + +static int do_test(enum tool_pmu_event ev, bool with_pmu) +{ + struct evlist *evlist = evlist__new(); + struct evsel *evsel; + struct parse_events_error err; + int ret; + char str[128]; + bool found = false; + + if (!evlist) { + pr_err("evlist allocation failed\n"); + return TEST_FAIL; + } + + if (with_pmu) + snprintf(str, sizeof(str), "tool/%s/", tool_pmu__event_to_str(ev)); + else + strncpy(str, tool_pmu__event_to_str(ev), sizeof(str)); + + parse_events_error__init(&err); + ret = parse_events(evlist, str, &err); + if (ret) { + evlist__delete(evlist); + if (tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + ret = TEST_OK; + goto out; + } + + pr_debug("FAILED %s:%d failed to parse event '%s', err %d\n", + __FILE__, __LINE__, str, ret); + parse_events_error__print(&err, str); + ret = TEST_FAIL; + goto out; + } + + ret = TEST_OK; + if (with_pmu ? (evlist->core.nr_entries != 1) : (evlist->core.nr_entries < 1)) { + pr_debug("FAILED %s:%d Unexpected number of events for '%s' of %d\n", + __FILE__, __LINE__, str, evlist->core.nr_entries); + ret = TEST_FAIL; + goto out; + } + + evlist__for_each_entry(evlist, evsel) { + if (perf_pmu__is_tool(evsel->pmu)) { + if (evsel->core.attr.config != ev) { + pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %d\n", + __FILE__, __LINE__, str, evsel->core.attr.config, ev); + ret = TEST_FAIL; + goto out; + } + found = true; + } + } + + if (!found && !tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + pr_debug("FAILED %s:%d Didn't find tool event '%s' in parsed evsels\n", + __FILE__, __LINE__, str); + ret = TEST_FAIL; + } + +out: + evlist__delete(evlist); + return ret; +} + +static int test__tool_pmu_without_pmu(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret = do_test(i, /*with_pmu=*/false); + + if (ret != TEST_OK) + return ret; + } + return TEST_OK; +} + +static int test__tool_pmu_with_pmu(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret = do_test(i, /*with_pmu=*/true); + + if (ret != TEST_OK) + return ret; + } + return TEST_OK; +} + +static struct test_case tests__tool_pmu[] = { + TEST_CASE("Parsing without PMU name", tool_pmu_without_pmu), + TEST_CASE("Parsing with PMU name", tool_pmu_with_pmu), + { .name = NULL, } +}; + +struct test_suite suite__tool_pmu = { + .desc = "Tool PMU", + .test_cases = tests__tool_pmu, +};