Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Howard Chu <howardchu95@gmail.com>
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: Re: [PATCH v1 5/5] perf trace: Add test for enum augmentation
Date: Tue, 18 Jun 2024 14:56:08 -0300	[thread overview]
Message-ID: <ZnHKOKFgJSaJA9UI@x1> (raw)
In-Reply-To: <20240618152652.3446472-6-howardchu95@gmail.com>

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@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
> 

  reply	other threads:[~2024-06-18 17:56 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 ` [PATCH v1 5/5] perf trace: Add test for enum augmentation Howard Chu
2024-06-18 17:56   ` Arnaldo Carvalho de Melo [this message]
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=ZnHKOKFgJSaJA9UI@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=howardchu95@gmail.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