xref: /linux/tools/perf/tests/shell/trace_btf_enum.sh (revision 22c55fb9eb92395d999b8404d73e58540d11bdd8)
1#!/bin/bash
2# perf trace enum augmentation tests
3# SPDX-License-Identifier: GPL-2.0
4
5err=0
6
7syscall="landlock_add_rule"
8non_syscall="timer:hrtimer_start"
9
10TESTPROG="perf test -w landlock"
11
12# shellcheck source=lib/probe.sh
13. "$(dirname $0)"/lib/probe.sh
14skip_if_no_perf_trace || exit 2
15[ "$(id -u)" = 0 ] || exit 2
16
17check_vmlinux() {
18  echo "Checking if vmlinux exists"
19  if [ ! -f /sys/kernel/btf/vmlinux ]
20  then
21    echo "trace+enum test [Skipped missing vmlinux BTF support]"
22    err=2
23  fi
24}
25
26trace_landlock() {
27  echo "Tracing syscall ${syscall}"
28
29  # test flight just to see if landlock_add_rule is available
30  if ! perf trace $TESTPROG 2>&1 | grep -q landlock
31  then
32    echo "No landlock system call found, skipping to non-syscall tracing."
33    return
34  fi
35
36  output="$(perf trace -e $syscall $TESTPROG 2>&1)"
37  if echo "$output" | 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.*"
38  then
39    err=0
40  else
41	printf "[syscall failure] Failed to trace syscall $syscall, output:\n$output\n"
42    err=1
43  fi
44}
45
46trace_non_syscall() {
47  echo "Tracing non-syscall tracepoint ${non_syscall}"
48  output="$(perf trace -e $non_syscall --max-events=1 2>&1)"
49  if echo "$output" | grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
50  then
51    err=0
52  else
53	printf "[tracepoint failure] Failed to trace tracepoint $non_syscall, output:\n$output\n"
54    err=1
55  fi
56}
57
58check_vmlinux
59
60if [ $err = 0 ]; then
61  trace_landlock
62fi
63
64if [ $err = 0 ]; then
65  trace_non_syscall
66fi
67
68exit $err
69