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