xref: /linux/tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc (revision e9f0878c4b2004ac19581274c1ae4c61ae3ca70e)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Register/unregister many kprobe events
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7# ftrace fentry skip size depends on the machine architecture.
8# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le
9case `uname -m` in
10  x86_64|i[3456]86) OFFS=5;;
11  ppc64le) OFFS=8;;
12  *) OFFS=0;;
13esac
14
15if [ -d events/kprobes ]; then
16  echo 0 > events/kprobes/enable
17  echo > kprobe_events
18fi
19
20N=0
21echo "Setup up kprobes on first available 256 text symbols"
22grep -i " t " /proc/kallsyms | cut -f3 -d" " | grep -v .*\\..* | \
23while read i; do
24  echo p ${i}+${OFFS} >> kprobe_events && N=$((N+1)) ||:
25  test $N -eq 256 && break
26done
27
28L=`wc -l kprobe_events`
29if [ $L -ne $N ]; then
30  echo "The number of kprobes events ($L) is not $N"
31  exit_fail
32fi
33
34echo 1 > events/kprobes/enable
35echo 0 > events/kprobes/enable
36echo > kprobe_events
37echo "Waiting for unoptimizing & freeing"
38sleep 5
39echo "Done"
40