From: Howard Chu <howardchu95@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 5/5] perf trace: Add test for enum augmentation
Date: Tue, 18 Jun 2024 23:26:52 +0800 [thread overview]
Message-ID: <20240618152652.3446472-6-howardchu95@gmail.com> (raw)
In-Reply-To: <20240618152652.3446472-1-howardchu95@gmail.com>
Check for vmlinux's existence in sysfs as prerequisite.
Compile and run a script which calls landlock_add_rule syscall,
trace the syscall to judge if the output is desirable.
Trace the non-syscall tracepoint 'timer:hrtimer_init' and
'timer:hrtimer_start', see if the 'mode' argument is augmented,
the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
in its name.
Signed-off-by: Howard Chu <howardchu95@gmail.com>
---
tools/perf/tests/shell/trace_btf_enum.sh | 104 +++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
new file mode 100755
index 000000000000..14c73b0b594d
--- /dev/null
+++ b/tools/perf/tests/shell/trace_btf_enum.sh
@@ -0,0 +1,104 @@
+#!/bin/sh
+# perf trace enum augmentation tests
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+set -e
+
+syscall="landlock_add_rule"
+non_syscall="timer:hrtimer_init,timer:hrtimer_start"
+
+landlock_script=$(mktemp /tmp/landlock-XXXXX.c)
+landlock_ex=$(echo $landlock_script | sed -E 's/(.*).c$/\1/g')
+
+landlock_fd=24
+landlock_flags=25
+
+. "$(dirname $0)"/lib/probe.sh
+skip_if_no_perf_trace || exit 2
+
+enum_aug_prereq() {
+ echo "Checking perf trace enum augmentation prerequisites"
+ if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
+ then
+ echo "trace+enum test [Skipped missing vmlinux BTF support]"
+ err=2
+ return
+ fi
+}
+
+prepare_landlock_script() {
+ echo "Preparing script for ${syscall} syscall"
+
+ cat > $landlock_script << EOF
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <linux/landlock.h>
+#include <sys/syscall.h>
+
+int main()
+{
+ int fd = ${landlock_fd};
+ int flags = ${landlock_flags};
+ struct landlock_path_beneath_attr path_beneath_attr = {
+ .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
+ };
+ struct landlock_net_port_attr net_port_attr = {
+ .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
+ .port = 443,
+ };
+
+ syscall(SYS_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
+ &path_beneath_attr, flags);
+
+ syscall(SYS_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
+ &net_port_attr, flags);
+
+ return 0;
+}
+EOF
+
+ gcc $landlock_script -o $landlock_ex
+}
+
+trace_landlock() {
+ echo "Tracing syscall ${syscall}"
+ if perf trace -e $syscall $landlock_ex 2>&1 | \
+ grep -q -E ".*landlock_add_rule\(ruleset_fd: ${landlock_fd}, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: ${landlock_flags}\) = -1.*"
+ then
+ err=0
+ else
+ err=1
+ fi
+}
+
+trace_non_syscall() {
+ echo "Tracing non-syscall tracepoint ${non-syscall}"
+ if perf trace -e $non_syscall --max-events=1 2>&1 | \
+ grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
+ then
+ err=0
+ else
+ err=1
+ fi
+}
+
+cleanup() {
+ rm -f $landlock_script $landlock_ex
+}
+
+enum_aug_prereq
+
+prepare_landlock_script
+
+if [ $err = 0 ]; then
+ trace_landlock
+fi
+
+if [ $err = 0 ]; then
+ trace_non_syscall
+fi
+
+cleanup
+
+exit $err
--
2.45.2
next prev parent reply other threads:[~2024-06-18 15:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 15:26 [PATCH v1 0/5] perf trace: Augment enum arguments with BTF Howard Chu
2024-06-18 15:26 ` [PATCH v1 1/5] perf trace: Fix iteration of syscall ids in syscalltbl->entries Howard Chu
2024-06-18 15:26 ` [PATCH v1 2/5] perf trace: Augment enum syscall arguments with BTF Howard Chu
2024-06-18 15:26 ` [PATCH v1 3/5] perf trace: Augment enum tracepoint " Howard Chu
2024-06-18 15:26 ` [PATCH v1 4/5] perf trace: Filter enum arguments with enum names Howard Chu
2024-06-18 15:26 ` Howard Chu [this message]
2024-06-18 17:56 ` [PATCH v1 5/5] perf trace: Add test for enum augmentation Arnaldo Carvalho de Melo
2024-06-18 18:00 ` Howard Chu
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=20240618152652.3446472-6-howardchu95@gmail.com \
--to=howardchu95@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).