[PATCH 59/59] libperf: Add parse-events test
From: Jiri Olsa <hidden>
Date: 2021-11-08 13:43:15
Subsystem:
performance events subsystem, the rest · Maintainers:
Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds
Adding parse-events test. Signed-off-by: Jiri Olsa <jolsa@kernel.org> --- tools/lib/perf/tests/Build | 1 + tools/lib/perf/tests/main.c | 1 + tools/lib/perf/tests/test-evlist.c | 2 ++ tools/lib/perf/tests/test-parse-events.c | 41 ++++++++++++++++++++++++ tools/lib/perf/tests/tests.h | 1 + 5 files changed, 46 insertions(+) create mode 100644 tools/lib/perf/tests/test-parse-events.c
diff --git a/tools/lib/perf/tests/Build b/tools/lib/perf/tests/Build
index 56e81378d443..f1d1133d8dae 100644
--- a/tools/lib/perf/tests/Build
+++ b/tools/lib/perf/tests/Build@@ -3,3 +3,4 @@ tests-y += test-evsel.o tests-y += test-evlist.o tests-y += test-cpumap.o tests-y += test-threadmap.o +tests-y += test-parse-events.o
diff --git a/tools/lib/perf/tests/main.c b/tools/lib/perf/tests/main.c
index 56423fd4db19..bfa8ba05c422 100644
--- a/tools/lib/perf/tests/main.c
+++ b/tools/lib/perf/tests/main.c@@ -7,6 +7,7 @@ int tests_verbose; int main(int argc, char **argv) { + __T("test parse_events", !test_parse_events(argc, argv)); __T("test cpumap", !test_cpumap(argc, argv)); __T("test threadmap", !test_threadmap(argc, argv)); __T("test evlist", !test_evlist(argc, argv));
diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c
index ce91a582f0e4..199451a605a1 100644
--- a/tools/lib/perf/tests/test-evlist.c
+++ b/tools/lib/perf/tests/test-evlist.c@@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#ifndef _GNU_SOURCE #define _GNU_SOURCE // needed for sched.h to get sched_[gs]etaffinity and CPU_(ZERO,SET) +#endif #include <sched.h> #include <stdio.h> #include <stdarg.h>
diff --git a/tools/lib/perf/tests/test-parse-events.c b/tools/lib/perf/tests/test-parse-events.c
new file mode 100644
index 000000000000..5f913f82de7f
--- /dev/null
+++ b/tools/lib/perf/tests/test-parse-events.c@@ -0,0 +1,41 @@ +#include <stdio.h> +#include <linux/perf_event.h> +#include <linux/hw_breakpoint.h> +#include <perf/evlist.h> +#include <perf/evsel.h> +#include <internal/evlist.h> +#include <internal/tests.h> +#include "tests.h" + +static int libperf_print(enum libperf_print_level level, + const char *fmt, va_list ap) +{ + return vfprintf(stderr, fmt, ap); +} + +int test_parse_events(int argc, char **argv) +{ + struct perf_evlist *evlist; + struct perf_evsel *evsel; + int err; + + __T_START; + + libperf_init(libperf_print); + + evlist = perf_evlist__new(); + __T("failed to create evlist", evlist); + + err = libperf_parse_events(evlist, "mem:0:rw"); + __T("failed to parse events", !err); + + evsel = perf_evlist__first(evlist); + + __T("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); + __T("wrong config", 0 == evsel->attr.config); + __T("wrong bp_type", (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type); + __T("wrong bp_len", HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); + + __T_END; + return tests_failed == 0 ? 0 : -1; +}
diff --git a/tools/lib/perf/tests/tests.h b/tools/lib/perf/tests/tests.h
index 604838f21b2b..b4f27fc9c46d 100644
--- a/tools/lib/perf/tests/tests.h
+++ b/tools/lib/perf/tests/tests.h@@ -6,5 +6,6 @@ int test_cpumap(int argc, char **argv); int test_threadmap(int argc, char **argv); int test_evlist(int argc, char **argv); int test_evsel(int argc, char **argv); +int test_parse_events(int argc, char **argv); #endif /* TESTS_H */
--
2.31.1