[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH0uvohbwWM9Xhe4SzfF85S0qe3bnka0ULO-mX-whBd5s5yMNA@mail.gmail.com>
Date: Wed, 19 Jun 2024 02:00:01 +0800
From: Howard Chu <howardchu95@...il.com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Jiri Olsa <jolsa@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v1 5/5] perf trace: Add test for enum augmentation
Thank you Arnaldo, on it.
Thanks,
Howard
On Wed, Jun 19, 2024 at 1:56 AM Arnaldo Carvalho de Melo
<acme@...nel.org> wrote:
>
> On Tue, Jun 18, 2024 at 11:26:52PM +0800, Howard Chu wrote:
> > Check for vmlinux's existence in sysfs as prerequisite.
>
> That is good, well done, but then we need to check if gcc is installed,
> and it may not be and we want to test this feature even so.
>
> So please take a look at git log tools/perf/tests/workloads/, then add a
> tools/perf/tests/workloads/landlock_add_rule.c and finally you'll be
> able to replace the inline landlock .c file + gcc to build it and
> instead use:
>
> perf test -w landlock_add_rule
>
> As your workload.
>
> Then you update the last patch in your series, test it all and resend
> the whole series with a v2, with the description of v1 and v2 in the
> cover letter.
>
> Thanks,
>
> - Arnaldo
>
> > 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@...il.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
> >
Powered by blists - more mailing lists