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 26check_permissions() { 27 if perf trace -e $syscall $TESTPROG 2>&1 | grep -q "Operation not permitted" 28 then 29 echo "trace+enum test [Skipped permissions]" 30 err=2 31 fi 32} 33 34trace_landlock() { 35 echo "Tracing syscall ${syscall}" 36 37 # test flight just to see if landlock_add_rule is available 38 if ! perf trace $TESTPROG 2>&1 | grep -q landlock 39 then 40 echo "No landlock system call found, skipping to non-syscall tracing." 41 return 42 fi 43 44 output="$(perf trace -e $syscall $TESTPROG 2>&1)" 45 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.*" 46 then 47 err=0 48 else 49 printf "[syscall failure] Failed to trace syscall $syscall, output:\n$output\n" 50 err=1 51 fi 52} 53 54trace_non_syscall() { 55 echo "Tracing non-syscall tracepoint ${non_syscall}" 56 output="$(perf trace -e $non_syscall --max-events=1 2>&1)" 57 if echo "$output" | grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$' 58 then 59 err=0 60 else 61 printf "[tracepoint failure] Failed to trace tracepoint $non_syscall, output:\n$output\n" 62 err=1 63 fi 64} 65 66check_vmlinux 67if [ $err = 0 ]; then 68 check_permissions 69fi 70 71if [ $err = 0 ]; then 72 trace_landlock 73fi 74 75if [ $err = 0 ]; then 76 trace_non_syscall 77fi 78 79exit $err 80