1#!/bin/sh 2 3########################################################################### 4## ## 5## Copyright (c) 2010 FUJITSU LIMITED ## 6## ## 7## This program is free software: you can redistribute it and/or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation, either version 3 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, ## 13## but WITHOUT ANY WARRANTY; without even the implied warranty of ## 14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## 15## GNU General Public License for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program. If not, see <http://www.gnu.org/licenses/>. ## 19## ## 20## Author: Li Zefan <lizf@cn.fujitsu.com> ## 21## ## 22########################################################################### 23 24. test.sh 25 26ftrace_test_init() 27{ 28 export TPATH="$PWD" 29 export SPATH="$TPATH/ftrace_stress" 30 31 if grep -q debugfs /proc/mounts; then 32 export DEBUGFS_PATH=/sys/kernel/debug/ 33 export TRACING_PATH="$DEBUGFS_PATH/tracing" 34 debugfs_def_mounted=1 35 else 36 tst_tmpdir 37 export DEBUGFS_PATH="$PWD/debugfs" 38 export TRACING_PATH="$PWD/debugfs/tracing" 39 mkdir $DEBUGFS_PATH 40 mount -t debugfs xxx $DEBUGFS_PATH 41 fi 42 43 TST_CLEANUP=clean_up 44 45 trap clean_up_exit INT 46 47 tst_require_root 48 49 # Check to see tracing feature is supported or not 50 if [ ! -d $TRACING_PATH ]; then 51 tst_brkm TCONF "Tracing is not supported. Skip the test..." 52 fi 53 54 save_old_setting 55} 56 57test_interval=$1 58 59save_old_setting() 60{ 61 cd $TRACING_PATH 62 63 old_trace_options=( `cat trace_options` ) 64 old_tracing_on=`cat tracing_on` 65 old_buffer_size=`cat buffer_size_kb` 66 old_tracing_cpumask=`cat tracing_cpumask` 67 68 if [ -e tracing_cpumask ]; then 69 old_tracing_cpumask=`cat tracing_cpumask` 70 fi 71 72 if [ -e tracing_enabled ]; then 73 old_tracing_enabled=`cat tracing_enabled` 74 fi 75 76 if [ -e stack_max_size ]; then 77 old_stack_tracer_enabled=`cat /proc/sys/kernel/stack_tracer_enabled` 78 fi 79 80 if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then 81 old_ftrace_enabled=`cat /proc/sys/kernel/ftrace_enabled` 82 fi 83 84 if [ -e "function_profile_enabled" ]; then 85 old_profile_enabled=`cat function_profile_enabled` 86 fi 87 88 setting_saved=1 89 90 cd - > /dev/null 91} 92 93restore_old_setting() 94{ 95 if [ ! "$setting_saved" = 1 ]; then 96 return 97 fi 98 99 cd $TRACING_PATH 100 101 echo nop > current_tracer 102 echo 0 > events/enable 103 echo 0 > tracing_max_latency 2> /dev/null 104 105 if [ -e tracing_cpumask ]; then 106 echo $old_tracing_cpumask > tracing_cpumask 107 fi 108 109 if [ -e trace_clock ]; then 110 echo local > trace_clock 111 fi 112 113 if [ -e "function_pofile_enabled" ]; then 114 echo $old_profile_enabled > function_profile_enabled 115 fi 116 117 if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then 118 echo $old_ftrace_enabled > /proc/sys/kernel/ftrace_enabled 119 fi 120 121 if [ -e stack_max_size ]; then 122 echo $old_stack_tracer_enabled > /proc/sys/kernel/stack_tracer_enabled 123 echo 0 > stack_max_size 124 fi 125 126 echo $old_buffer_size > buffer_size_kb 127 echo $old_tracing_on > tracing_on 128 129 if [ -e tracing_enabled ];then 130 echo $old_tracing_enabled > tracing_enabled 131 fi 132 133 for option in $old_trace_options 134 do 135 echo $option > trace_options 2> /dev/null 136 done 137 138 echo > trace 139 140 if [ -f set_ftrace_filter ]; then 141 echo > set_ftrace_filter 142 fi 143 144 cd - > /dev/null 145} 146 147clean_up_mount() 148{ 149 if [ ! "$debugfs_def_mounted" = "1" ]; then 150 umount $DEBUGFS_PATH 151 rmdir $DEBUGFS_PATH 152 fi 153} 154 155clean_up() 156{ 157 restore_old_setting 158 clean_up_mount 159} 160 161clean_up_exit() 162{ 163 restore_old_setting 164 clean_up_mount 165 exit 1 166} 167 168test_begin() 169{ 170 start_time=`date +%s` 171} 172 173test_wait() 174{ 175 # run the test for $test_interval secs 176 tst_sleep ${test_interval}s 177} 178 179ftrace_test_init 180