1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: ftrace - test for function event triggers 4# flags: instance 5# 6# Ftrace allows to add triggers to functions, such as enabling or disabling 7# tracing, enabling or disabling trace events, or recording a stack trace 8# within the ring buffer. 9# 10# This test is designed to test event triggers 11# 12 13# The triggers are set within the set_ftrace_filter file 14if [ ! -f set_ftrace_filter ]; then 15 echo "set_ftrace_filter not found? Is dynamic ftrace not set?" 16 exit_unsupported 17fi 18 19do_reset() { 20 reset_ftrace_filter 21 reset_tracer 22 disable_events 23 clear_trace 24 enable_tracing 25} 26 27fail() { # mesg 28 echo $1 29 exit_fail 30} 31 32SLEEP_TIME=".1" 33 34echo "Testing function probes with events:" 35 36EVENT="sched:sched_switch" 37EVENT_ENABLE="events/sched/sched_switch/enable" 38 39cnt_trace() { 40 grep -v '^#' trace | wc -l 41} 42 43test_event_enabled() { 44 val=$1 45 46 e=`cat $EVENT_ENABLE` 47 if [ "$e" != $val ]; then 48 fail "Expected $val but found $e" 49 fi 50} 51 52run_enable_disable() { 53 enable=$1 # enable 54 Enable=$2 # Enable 55 check_disable=$3 # 0 56 check_enable_star=$4 # 1* 57 check_disable_star=$5 # 0* 58 59 cnt=`cnt_trace` 60 if [ $cnt -ne 0 ]; then 61 fail "Found junk in trace file" 62 fi 63 64 echo "$Enable event all the time" 65 66 echo $check_disable > $EVENT_ENABLE 67 sleep $SLEEP_TIME 68 69 test_event_enabled $check_disable 70 71 echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter 72 if [ -d ../../instances ]; then # Check instances 73 cur=`cat set_ftrace_filter` 74 top=`cat ../../set_ftrace_filter` 75 if [ "$cur" = "$top" ]; then 76 echo "This kernel is too old to support per instance filter" 77 reset_ftrace_filter 78 exit_unsupported 79 fi 80 fi 81 82 echo " make sure it works 5 times" 83 84 for i in `seq 5`; do 85 sleep $SLEEP_TIME 86 echo " test $i" 87 test_event_enabled $check_enable_star 88 89 echo $check_disable > $EVENT_ENABLE 90 done 91 sleep $SLEEP_TIME 92 echo " make sure it's still works" 93 test_event_enabled $check_enable_star 94 95 reset_ftrace_filter 96 97 echo " make sure it only works 3 times" 98 99 echo $check_disable > $EVENT_ENABLE 100 sleep $SLEEP_TIME 101 102 echo "schedule:${enable}_event:$EVENT:3" > set_ftrace_filter 103 104 for i in `seq 3`; do 105 sleep $SLEEP_TIME 106 echo " test $i" 107 test_event_enabled $check_enable_star 108 109 echo $check_disable > $EVENT_ENABLE 110 done 111 112 sleep $SLEEP_TIME 113 echo " make sure it stop working" 114 test_event_enabled $check_disable_star 115 116 do_reset 117} 118 119run_enable_disable enable Enable 0 "1*" "0*" 120run_enable_disable disable Disable 1 "0*" "1*" 121