1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: Test ftrace direct functions against kprobes 4 5rmmod ftrace-direct ||: 6if ! modprobe ftrace-direct ; then 7 echo "No ftrace-direct sample module - please build with CONFIG_SAMPLE_FTRACE_DIRECT=m" 8 exit_unresolved; 9fi 10 11if [ ! -f kprobe_events ]; then 12 echo "No kprobe_events file -please build CONFIG_KPROBE_EVENTS" 13 exit_unresolved; 14fi 15 16echo "Let the module run a little" 17sleep 1 18 19grep -q "my_direct_func: waking up" trace 20 21rmmod ftrace-direct 22 23echo 'p:kwake wake_up_process task=$arg1' > kprobe_events 24 25start_direct() { 26 echo > trace 27 modprobe ftrace-direct 28 sleep 1 29 grep -q "my_direct_func: waking up" trace 30} 31 32stop_direct() { 33 rmmod ftrace-direct 34} 35 36enable_probe() { 37 echo > trace 38 echo 1 > events/kprobes/kwake/enable 39 sleep 1 40 grep -q "kwake:" trace 41} 42 43disable_probe() { 44 echo 0 > events/kprobes/kwake/enable 45} 46 47test_kprobes() { 48 # probe -> direct -> no direct > no probe 49 enable_probe 50 start_direct 51 stop_direct 52 disable_probe 53 54 # probe -> direct -> no probe > no direct 55 enable_probe 56 start_direct 57 disable_probe 58 stop_direct 59 60 # direct -> probe -> no probe > no direct 61 start_direct 62 enable_probe 63 disable_probe 64 stop_direct 65 66 # direct -> probe -> no direct > no noprobe 67 start_direct 68 enable_probe 69 stop_direct 70 disable_probe 71} 72 73test_kprobes 74 75# Now do this with a second registered direct function 76echo "Running with another ftrace direct function" 77 78modprobe ftrace-direct-too 79 80test_kprobes 81 82rmmod ftrace-direct-too 83 84echo > kprobe_events 85