From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
Marco Elver <elver@google.com>, Song Liu <songliubraving@fb.com>
Subject: [PATCH v2] perf test: Skip sigtrap test on old kernels
Date: Tue, 6 Sep 2022 22:04:07 -0700 [thread overview]
Message-ID: <20220907050407.2711513-1-namhyung@kernel.org> (raw)
If it runs on an old kernel, perf_event_open would fail because of the
new fields sigtrap and sig_data. Just skipping the test could miss an
actual bug in the kernel.
Let's check BTF if it has the perf_event_attr.sigtrap field.
Cc: Marco Elver <elver@google.com>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
index e32ece90e164..32f08ce0f2b0 100644
--- a/tools/perf/tests/sigtrap.c
+++ b/tools/perf/tests/sigtrap.c
@@ -16,6 +16,8 @@
#include <sys/syscall.h>
#include <unistd.h>
+#include <bpf/btf.h>
+
#include "cloexec.h"
#include "debug.h"
#include "event.h"
@@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
return attr;
}
+static bool attr_has_sigtrap(void)
+{
+ bool ret = false;
+
+#ifdef HAVE_BPF_SKEL
+
+ struct btf *btf;
+ const struct btf_type *t;
+ const struct btf_member *m;
+ const char *name;
+ int i, id;
+
+ /* just assume it doesn't have the field */
+ btf = btf__load_vmlinux_btf();
+ if (btf == NULL)
+ return false;
+
+ id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
+ if (id < 0)
+ goto out;
+
+ t = btf__type_by_id(btf, id);
+ for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
+ name = btf__name_by_offset(btf, m->name_off);
+ if (!strcmp(name, "sigtrap")) {
+ ret = true;
+ break;
+ }
+ }
+out:
+ btf__free(btf);
+#endif
+
+ return ret;
+}
+
static void
sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
{
@@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
if (fd < 0) {
- pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
+ if (attr_has_sigtrap()) {
+ pr_debug("FAILED sys_perf_event_open(): %s\n",
+ str_error_r(errno, sbuf, sizeof(sbuf)));
+ } else {
+ pr_debug("perf_event_attr doesn't have sigtrap\n");
+ ret = TEST_SKIP;
+ }
goto out_restore_sigaction;
}
--
2.37.2.789.g6183377224-goog
next reply other threads:[~2022-09-07 5:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 5:04 Namhyung Kim [this message]
2022-09-07 5:58 ` [PATCH v2] perf test: Skip sigtrap test on old kernels Song Liu
2022-09-07 6:58 ` Namhyung Kim
2022-09-07 8:32 ` Jiri Olsa
2022-09-07 17:50 ` Namhyung Kim
2022-09-07 18:05 ` Namhyung Kim
2022-09-08 18:31 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220907050407.2711513-1-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=elver@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox