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