mirror of
https://github.com/torvalds/linux.git
synced 2024-11-12 23:23:03 +00:00
09d2056efe
Code cleanup, replace strcmp(evsel__name(evsel, {NAME})) with evsel__name_is() helper. No functional change. Committer notes: Fix this build error: trace.syscalls.events.bpf_output = evlist__last(trace.evlist); - assert(evsel__name_is(trace.syscalls.events.bpf_output), "__augmented_syscalls__"); + assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__")); Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Yang Jihong <yangjihong@bytedance.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240401062724.1006010-3-yangjihong@bytedance.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
105 lines
2.4 KiB
C
105 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "evlist.h"
|
|
#include "evsel.h"
|
|
#include "parse-events.h"
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
#include <linux/kernel.h>
|
|
|
|
static int perf_evsel__roundtrip_cache_name_test(void)
|
|
{
|
|
int ret = TEST_OK;
|
|
|
|
for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
|
|
for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
|
|
/* skip invalid cache type */
|
|
if (!evsel__is_cache_op_valid(type, op))
|
|
continue;
|
|
|
|
for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) {
|
|
char name[128];
|
|
struct evlist *evlist = evlist__new();
|
|
struct evsel *evsel;
|
|
int err;
|
|
|
|
if (evlist == NULL) {
|
|
pr_debug("Failed to alloc evlist");
|
|
return TEST_FAIL;
|
|
}
|
|
__evsel__hw_cache_type_op_res_name(type, op, res,
|
|
name, sizeof(name));
|
|
|
|
err = parse_event(evlist, name);
|
|
if (err) {
|
|
pr_debug("Failure to parse cache event '%s' possibly as PMUs don't support it",
|
|
name);
|
|
evlist__delete(evlist);
|
|
continue;
|
|
}
|
|
evlist__for_each_entry(evlist, evsel) {
|
|
if (!evsel__name_is(evsel, name)) {
|
|
pr_debug("%s != %s\n", evsel__name(evsel), name);
|
|
ret = TEST_FAIL;
|
|
}
|
|
}
|
|
evlist__delete(evlist);
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int perf_evsel__name_array_test(const char *const names[], int nr_names)
|
|
{
|
|
int ret = TEST_OK;
|
|
|
|
for (int i = 0; i < nr_names; ++i) {
|
|
struct evlist *evlist = evlist__new();
|
|
struct evsel *evsel;
|
|
int err;
|
|
|
|
if (evlist == NULL) {
|
|
pr_debug("Failed to alloc evlist");
|
|
return TEST_FAIL;
|
|
}
|
|
err = parse_event(evlist, names[i]);
|
|
if (err) {
|
|
pr_debug("failed to parse event '%s', err %d\n",
|
|
names[i], err);
|
|
evlist__delete(evlist);
|
|
ret = TEST_FAIL;
|
|
continue;
|
|
}
|
|
evlist__for_each_entry(evlist, evsel) {
|
|
if (!evsel__name_is(evsel, names[i])) {
|
|
pr_debug("%s != %s\n", evsel__name(evsel), names[i]);
|
|
ret = TEST_FAIL;
|
|
}
|
|
}
|
|
evlist__delete(evlist);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int test__perf_evsel__roundtrip_name_test(struct test_suite *test __maybe_unused,
|
|
int subtest __maybe_unused)
|
|
{
|
|
int err = 0, ret = TEST_OK;
|
|
|
|
err = perf_evsel__name_array_test(evsel__hw_names, PERF_COUNT_HW_MAX);
|
|
if (err)
|
|
ret = err;
|
|
|
|
err = perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1);
|
|
if (err)
|
|
ret = err;
|
|
|
|
err = perf_evsel__roundtrip_cache_name_test();
|
|
if (err)
|
|
ret = err;
|
|
|
|
return ret;
|
|
}
|
|
|
|
DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test);
|