• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	if [ -e tracing_max_latency ]; then
104		echo 0 > tracing_max_latency
105	fi
106
107	if [ -e tracing_cpumask ]; then
108		echo $old_tracing_cpumask > tracing_cpumask
109	fi
110
111	if [ -e trace_clock ]; then
112		echo local > trace_clock
113	fi
114
115	if [ -e "function_pofile_enabled" ]; then
116		echo $old_profile_enabled > function_profile_enabled
117	fi
118
119	if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then
120		echo $old_ftrace_enabled > /proc/sys/kernel/ftrace_enabled
121	fi
122
123	if [ -e stack_max_size ]; then
124		echo $old_stack_tracer_enabled > /proc/sys/kernel/stack_tracer_enabled
125		echo 0 > stack_max_size
126	fi
127
128	echo $old_buffer_size > buffer_size_kb
129	echo $old_tracing_on > tracing_on
130
131	if [ -e tracing_enabled ];then
132		echo $old_tracing_enabled > tracing_enabled
133	fi
134
135	for option in $old_trace_options
136	do
137		echo $option > trace_options 2> /dev/null
138	done
139
140	echo > trace
141
142	if [ -f set_ftrace_filter ]; then
143		echo  > set_ftrace_filter
144	fi
145
146	cd - > /dev/null
147}
148
149clean_up_mount()
150{
151	if [ ! "$debugfs_def_mounted" = "1" ]; then
152		umount $DEBUGFS_PATH
153		rmdir $DEBUGFS_PATH
154	fi
155}
156
157clean_up()
158{
159	restore_old_setting
160	clean_up_mount
161}
162
163clean_up_exit()
164{
165	restore_old_setting
166	clean_up_mount
167	exit 1
168}
169
170test_begin()
171{
172	start_time=`date +%s`
173}
174
175test_wait()
176{
177	# run the test for $test_interval secs
178	tst_sleep ${test_interval}s
179}
180
181ftrace_test_init
182