linux-perf-users.vger.kernel.org archive mirror
 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 v2 5/5] perf trace: Add test for enum augmentation
Date: Wed, 19 Jun 2024 10:51:38 -0300	[thread overview]
Message-ID: <ZnLianWCCEF6ydVO@x1> (raw)
In-Reply-To: <20240619082042.4173621-6-howardchu95@gmail.com>

On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> Check for vmlinux's existence in sysfs as prerequisite.
> 
> Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> 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.
> 
> Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> Signed-off-by: Howard Chu <howardchu95@gmail.com>
> ---
>  tools/perf/tests/builtin-test.c               |  1 +
>  tools/perf/tests/shell/trace_btf_enum.sh      | 57 +++++++++++++++++++
>  tools/perf/tests/tests.h                      |  1 +
>  tools/perf/tests/workloads/Build              |  1 +
>  .../perf/tests/workloads/landlock_add_rule.c  | 32 +++++++++++
>  5 files changed, 92 insertions(+)
>  create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
>  create mode 100644 tools/perf/tests/workloads/landlock_add_rule.c
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index c3d84b67ca8e..e83200415ad1 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
>  	&workload__sqrtloop,
>  	&workload__brstack,
>  	&workload__datasym,
> +	&workload__landlock_add_rule,
>  };
>  
>  static int num_subtests(const struct test_suite *t)
> 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..4861983553ab
> --- /dev/null
> +++ b/tools/perf/tests/shell/trace_btf_enum.sh
> @@ -0,0 +1,57 @@
> +#!/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"
> +
> +TESTPROG="perf test -w landlock_add_rule"
> +
> +. "$(dirname $0)"/lib/probe.sh
> +skip_if_no_perf_trace || exit 2
> +
> +check_vmlinux() {
> +  echo "Checking if vmlinux exists"
> +  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
> +  then
> +    echo "trace+enum test [Skipped missing vmlinux BTF support]"
> +    err=2
> +  fi
> +}
> +
> +trace_landlock() {
> +  echo "Tracing syscall ${syscall}"
> +  if perf trace -e $syscall $TESTPROG 2>&1 | \
> +     grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -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
> +}
> +
> +check_vmlinux
> +
> +if [ $err = 0 ]; then
> +  trace_landlock
> +fi
> +
> +if [ $err = 0 ]; then
> +  trace_non_syscall
> +fi
> +
> +exit $err
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index 3aa7701ee0e9..69126299bb08 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -205,6 +205,7 @@ DECLARE_WORKLOAD(leafloop);
>  DECLARE_WORKLOAD(sqrtloop);
>  DECLARE_WORKLOAD(brstack);
>  DECLARE_WORKLOAD(datasym);
> +DECLARE_WORKLOAD(landlock_add_rule);
>  
>  extern const char *dso_to_test;
>  extern const char *test_objdump_path;
> diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
> index a1f34d5861e3..5b12b93ecffa 100644
> --- a/tools/perf/tests/workloads/Build
> +++ b/tools/perf/tests/workloads/Build
> @@ -6,6 +6,7 @@ perf-y += leafloop.o
>  perf-y += sqrtloop.o
>  perf-y += brstack.o
>  perf-y += datasym.o
> +perf-y += landlock_add_rule.o
>  
>  CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE
>  CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
> diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> new file mode 100644
> index 000000000000..529b5f1ea5a7
> --- /dev/null
> +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <linux/compiler.h>
> +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> +#include <unistd.h>
> +#include <linux/landlock.h>

This file was introduced on linux in 2021, unsure if it will be present
in some of the older distros we test, I'll check with my container test
suite.

Maybe we'll have to just define those LANDLOCK_ACCESS_FS_READ_FILE,
LANDLOCK_ACCESS_NET_CONNECT_TCP, etc as plain #define to make sure it
builds ok with uCLibc, musl libc and older glibc.

- Arnaldo

> +#include "../tests.h"
> +
> +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> +{
> +	int fd = 11;
> +	int flags = 45;
> +
> +	struct landlock_path_beneath_attr path_beneath_attr = {
> +	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> +	    .parent_fd = 14,
> +	};
> +
> +	struct landlock_net_port_attr net_port_attr = {
> +	    .port = 19,
> +	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> +	};
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> +		&path_beneath_attr, flags);
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> +		&net_port_attr, flags);
> +
> +	return 0;
> +}
> +
> +DEFINE_WORKLOAD(landlock_add_rule);
> -- 
> 2.45.2
> 

  reply	other threads:[~2024-06-19 13:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  8:20 [PATCH v2 0/5] perf trace: Augment enum arguments with BTF Howard Chu
2024-06-19  8:20 ` [PATCH v2 1/5] perf trace: Fix iteration of syscall ids in syscalltbl->entries Howard Chu
2024-06-19  8:20 ` [PATCH v2 2/5] perf trace: Augment enum syscall arguments with BTF Howard Chu
2024-06-19 13:44   ` Arnaldo Carvalho de Melo
2024-06-19 17:59     ` Howard Chu
2024-06-20 16:34       ` Howard Chu
2024-06-20 19:16         ` Howard Chu
2024-06-21 13:40           ` Arnaldo Carvalho de Melo
2024-06-21 16:18             ` Howard Chu
2024-06-22 18:28               ` Arnaldo Carvalho de Melo
2024-06-23 11:34                 ` Howard Chu
2024-06-21 18:03       ` Arnaldo Carvalho de Melo
2024-06-19  8:20 ` [PATCH v2 3/5] perf trace: Augment enum tracepoint " Howard Chu
2024-06-19 13:46   ` Arnaldo Carvalho de Melo
2024-06-19 18:00     ` Howard Chu
2024-06-19  8:20 ` [PATCH v2 4/5] perf trace: Filter enum arguments with enum names Howard Chu
2024-06-19 13:48   ` Arnaldo Carvalho de Melo
2024-06-19 18:18     ` Howard Chu
2024-06-19  8:20 ` [PATCH v2 5/5] perf trace: Add test for enum augmentation Howard Chu
2024-06-19 13:51   ` Arnaldo Carvalho de Melo [this message]
2024-06-19 14:36     ` Namhyung Kim
2024-06-19 18:26       ` Howard Chu
2024-06-21 16:07   ` Namhyung Kim
2024-06-21 16:43     ` Howard Chu
2024-06-21 17:15       ` Namhyung Kim
2024-06-28  6:37   ` kernel test robot
2024-06-19 13:55 ` [PATCH v2 0/5] perf trace: Augment enum arguments with BTF Arnaldo Carvalho de Melo
2024-06-19 18:19   ` Namhyung Kim
2024-06-19 18:25     ` Howard Chu
2024-06-20 19:12       ` 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=ZnLianWCCEF6ydVO@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;
as well as URLs for NNTP newsgroup(s).