1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: ftrace - test for function traceon/off 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 enabling and disabling tracing 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 19fail() { # mesg 20 echo $1 21 exit_fail 22} 23 24SLEEP_TIME=".1" 25 26echo "Testing function probes with enabling disabling tracing:" 27 28cnt_trace() { 29 grep -v '^#' trace | wc -l 30} 31 32echo '** DISABLE TRACING' 33disable_tracing 34clear_trace 35 36cnt=`cnt_trace` 37if [ $cnt -ne 0 ]; then 38 fail "Found junk in trace" 39fi 40 41 42echo '** ENABLE EVENTS' 43 44echo 1 > events/enable 45 46echo '** ENABLE TRACING' 47enable_tracing 48 49cnt=`cnt_trace` 50if [ $cnt -eq 0 ]; then 51 fail "Nothing found in trace" 52fi 53 54# powerpc uses .schedule 55func="schedule" 56available_file=available_filter_functions 57if [ -d ../../instances -a -f ../../available_filter_functions ]; then 58 available_file=../../available_filter_functions 59fi 60x=`grep '^\.schedule$' available_filter_functions | wc -l` 61if [ "$x" -eq 1 ]; then 62 func=".schedule" 63fi 64 65echo '** SET TRACEOFF' 66 67echo "$func:traceoff" > set_ftrace_filter 68if [ -d ../../instances ]; then # Check instances 69 cur=`cat set_ftrace_filter` 70 top=`cat ../../set_ftrace_filter` 71 if [ "$cur" = "$top" ]; then 72 echo "This kernel is too old to support per instance filter" 73 reset_ftrace_filter 74 exit_unsupported 75 fi 76fi 77 78cnt=`grep schedule set_ftrace_filter | wc -l` 79if [ $cnt -ne 1 ]; then 80 fail "Did not find traceoff trigger" 81fi 82 83cnt=`cnt_trace` 84sleep $SLEEP_TIME 85cnt2=`cnt_trace` 86 87if [ $cnt -ne $cnt2 ]; then 88 fail "Tracing is not stopped" 89fi 90 91on=`cat tracing_on` 92if [ $on != "0" ]; then 93 fail "Tracing is not off" 94fi 95 96csum1=`md5sum trace` 97sleep $SLEEP_TIME 98csum2=`md5sum trace` 99 100if [ "$csum1" != "$csum2" ]; then 101 fail "Tracing file is still changing" 102fi 103 104clear_trace 105 106cnt=`cnt_trace` 107if [ $cnt -ne 0 ]; then 108 fail "Tracing is still happeing" 109fi 110 111echo "!$func:traceoff" >> set_ftrace_filter 112 113cnt=`grep schedule set_ftrace_filter | wc -l` 114if [ $cnt -ne 0 ]; then 115 fail "traceoff trigger still exists" 116fi 117 118on=`cat tracing_on` 119if [ $on != "0" ]; then 120 fail "Tracing is started again" 121fi 122 123echo "$func:traceon" > set_ftrace_filter 124 125cnt=`grep schedule set_ftrace_filter | wc -l` 126if [ $cnt -ne 1 ]; then 127 fail "traceon trigger not found" 128fi 129 130cnt=`cnt_trace` 131if [ $cnt -eq 0 ]; then 132 fail "Tracing did not start" 133fi 134 135on=`cat tracing_on` 136if [ $on != "1" ]; then 137 fail "Tracing was not enabled" 138fi 139 140 141echo "!$func:traceon" >> set_ftrace_filter 142 143cnt=`grep schedule set_ftrace_filter | wc -l` 144if [ $cnt -ne 0 ]; then 145 fail "traceon trigger still exists" 146fi 147 148check_sleep() { 149 val=$1 150 sleep $SLEEP_TIME 151 cat set_ftrace_filter 152 on=`cat tracing_on` 153 if [ $on != "$val" ]; then 154 fail "Expected tracing_on to be $val, but it was $on" 155 fi 156} 157 158 159echo "$func:traceoff:3" > set_ftrace_filter 160check_sleep "0" 161echo 1 > tracing_on 162check_sleep "0" 163echo 1 > tracing_on 164check_sleep "0" 165echo 1 > tracing_on 166check_sleep "1" 167echo "!$func:traceoff:0" > set_ftrace_filter 168 169if grep -e traceon -e traceoff set_ftrace_filter; then 170 fail "Tracing on and off triggers still exist" 171fi 172 173disable_events 174 175exit 0 176