[LTP] [PATCH V3-2 8/9] ftrace_stress: add two new tests for ftrace_filter and tracing_cpu_mask

Chunyu Hu chuhu@redhat.com
Wed May 11 13:36:30 CEST 2016


V3:
    Fix code comment.
    Remove the ';' in 'i=0's
    Use tst_random directly
    simplify the reset of set_ftrace_filter
    Get the cpumask value using $(( a | $(( 1 << b)))) instead of
    $(( a | ( 1 << b))), as this is a bashism issue found by
    checkbashisms.pl

V2:
    Use tst_random to get random integer.
    Fix bashism code.
    Simplify the get of cpu mask, make it work with nr_cpu > 32.
    Update the set_ftrace_filter, use awk instead sed.small fix moddule filter.
    Use ltp lib.

V1:
    add ftrace_tracing_cpumask.sh.
    add ftrace_set_ftrace_filter.sh.

Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
 testcases/kernel/tracing/ftrace_test/ftrace_lib.sh |  13 +++
 .../ftrace_stress/ftrace_set_ftrace_filter.sh      | 119 +++++++++++++++++++++
 .../ftrace_stress/ftrace_tracing_cpumask.sh        |  91 ++++++++++++++++
 .../tracing/ftrace_test/ftrace_stress_test.sh      |   3 +-
 4 files changed, 225 insertions(+), 1 deletion(-)
 create mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
 create mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh

diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh b/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
index c131827..c4a28ad 100755
--- a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
@@ -63,6 +63,11 @@ save_old_setting()
 	old_trace_options=( `cat trace_options` )
 	old_tracing_on=`cat tracing_on`
 	old_buffer_size=`cat buffer_size_kb`
+	old_tracing_cpumask=`cat tracing_cpumask`
+
+	if [ -e tracing_cpumask ]; then
+		old_tracing_cpumask=`cat tracing_cpumask`
+	fi
 
 	if [ -e tracing_enabled ]; then
 		old_tracing_enabled=`cat tracing_enabled`
@@ -97,6 +102,10 @@ restore_old_setting()
 	echo 0 > events/enable
 	echo 0 > tracing_max_latency 2> /dev/null
 
+	if [ -e tracing_cpumask ]; then
+		echo $old_tracing_cpumask > tracing_cpumask
+	fi
+
 	if [ -e trace_clock ]; then
 		echo local > trace_clock
 	fi
@@ -128,6 +137,10 @@ restore_old_setting()
 
 	echo > trace
 
+	if [ -f set_ftrace_filter ]; then
+		echo  > set_ftrace_filter
+	fi
+
 	cd - > /dev/null
 }
 
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
new file mode 100755
index 0000000..af6ec9f
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
@@ -0,0 +1,119 @@
+#! /bin/sh
+###########################################################################
+##                                                                       ##
+## Copyright (c) 2015, Red Hat Inc.                                      ##
+##                                                                       ##
+## This program is free software: you can redistribute it and/or modify  ##
+## it under the terms of the GNU General Public License as published by  ##
+## the Free Software Foundation, either version 3 of the License, or     ##
+## (at your option) any later version.                                   ##
+##                                                                       ##
+## This program is distributed in the hope that it will be useful,       ##
+## but WITHOUT ANY WARRANTY; without even the implied warranty of        ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          ##
+## GNU General Public License for more details.                          ##
+##                                                                       ##
+## You should have received a copy of the GNU General Public License     ##
+## along with this program. If not, see <http://www.gnu.org/licenses/>.  ##
+##                                                                       ##
+## Author: Chunyu Hu <chuhu@redhat.com>                                  ##
+##                                                                       ##
+###########################################################################
+
+. test.sh
+
+triggers="traceon traceoff enable_event disable_event snapshot \
+	 dump cpudump stacktrace module function"
+nr_triggers=$(echo ${triggers} | wc -w)
+
+module_pick()
+{
+	nr_module=$(lsmod | wc -l)
+	pick_one=$(tst_random 1 $nr_module)
+	picked_module=$(lsmod | awk "{if (NR == $pick_one) {print \$1}}")
+}
+
+filter_file=$TRACING_PATH/available_filter_functions
+nr_functions=$(awk 'END{print NR}' $filter_file)
+
+function_pick()
+{
+	if [ -f $filter_file ]; then
+		local pick_one=$(tst_random 1 $nr_functions)
+		picked_function=$(awk "{if (NR == $pick_one) {print \$1}}" $filter_file)
+		echo $picked_function
+	else
+		echo "\*sched\*"
+	fi
+}
+
+event_pick()
+{
+	local events_file=$TRACING_PATH/available_events
+	if [ -f $events_file ]; then
+		nr_events=$(awk 'END{print NR}' $events_file)
+		local pick_one=$(tst_random 1 $nr_events)
+		picked_event=$(awk "{if (NR == $pick_one) {print \$0}}" $events_file)
+		echo "$picked_event"
+	else
+		echo "sched:sched_switch"
+	fi
+}
+
+filter_formatter()
+{
+	function_str=$(function_pick)
+	count=$(tst_random 0 2)
+
+	case $1 in
+	traceon|traceoff|snapshot|dump|cpudump|stacktrace)
+		trigger=$1
+		;;
+	enable_event|disable_event)
+		event_sys_name=$(event_pick)
+		trigger=$1:$event_sys_name
+		;;
+	module)
+		module_pick
+		echo ":mod:$picked_module"
+		return
+		;;
+	function)
+		echo "$function_str"
+		return
+		;;
+	*)
+		trigger=$1
+		;;
+	esac
+
+	if [ $count -gt 0 ]; then
+		trigger=$trigger:$count
+	fi
+	echo $function_str:$trigger
+}
+
+signal_handler()
+{
+	tst_exit
+}
+
+trap signal_handler SIGTERM
+
+while true; do
+	# Here try to check if a race caused issue can be hit.
+	cat $TRACING_PATH/set_ftrace_filter > /dev/null
+
+	trigger_index=$(tst_random 1 $nr_triggers)
+	trigger_name=$(echo $triggers | awk "{print \$$trigger_index}")
+	filter_format=$(filter_formatter $trigger_name)
+
+	echo "$filter_format" > $TRACING_PATH/set_ftrace_filter
+	[ $? -ne 0 ] && tst_resm TFAIL "$0: setup filter <$filter_format> failed"
+
+	sleep 2
+
+	echo "!$filter_format" > $TRACING_PATH/set_ftrace_filter
+	[ $? -ne 0 ] && tst_resm TFAIL "$0: remove filter <$filter_format> failed"
+done
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
new file mode 100755
index 0000000..aeb0d92
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
@@ -0,0 +1,91 @@
+#! /bin/sh
+
+###########################################################################
+##                                                                       ##
+## Copyright (c) 2015, Red Hat Inc.                                      ##
+##                                                                       ##
+## This program is free software: you can redistribute it and/or modify  ##
+## it under the terms of the GNU General Public License as published by  ##
+## the Free Software Foundation, either version 3 of the License, or     ##
+## (at your option) any later version.                                   ##
+##                                                                       ##
+## This program is distributed in the hope that it will be useful,       ##
+## but WITHOUT ANY WARRANTY; without even the implied warranty of        ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          ##
+## GNU General Public License for more details.                          ##
+##                                                                       ##
+## You should have received a copy of the GNU General Public License     ##
+## along with this program. If not, see <http://www.gnu.org/licenses/>.  ##
+##                                                                       ##
+## Author: Chunyu Hu <chuhu@redhat.com>                                  ##
+##                                                                       ##
+###########################################################################
+
+. test.sh
+nr_cpus=`tst_ncpus`
+
+# the 32 bit integer count 32 cpus. One integer is not
+# enough to store the cpu mask for nr_cpu > 32.
+if [ $nr_cpus -gt 32 ]; then
+	group_cnt=$((nr_cpus / 32))
+	range=31
+	rem=$((nr_cpus % 32))
+	if [ $rem -ne 0 ]; then
+		range_last=$((rem -1))
+	fi
+else
+	group_cnt=1
+	range=$((nr_cpus - 1))
+fi
+
+get_test_cpumask()
+{
+	mask=""
+
+	local i=0
+	while [ $i -lt $group_cnt ]; do
+		# select count of cpu in one group, include the duplicate.
+		local set_cnt=$(tst_random 1 $((range + 1)))
+
+		local c=0
+		local temp_mask=0
+		while [ $c -lt $set_cnt ]; do
+			local group_cpuid=$(tst_random 1 $range)
+			temp_mask=$((temp_mask | $((1 << $group_cpuid))))
+			c=$((c + 1))
+		done
+
+		if  [ $i = 0 ]; then
+			mask=`echo $temp_mask | awk '{printf "%x",$0}'`
+		else
+			mask=$mask","`echo $temp_mask | awk '{printf "%x",$0}'`
+		fi
+
+		i=$((i + 1))
+	done
+
+	if [ $group_cnt -gt 1  ]; then
+		set_cnt=$(tst_random 1 $((range_last +1)))
+		c=0;
+		temp_mask=0
+		while [ $c -lt $set_cnt ]; do
+			local group_cpuid=$(tst_random 1 $range_last)
+			temp_mask=$((temp_mask | $((1 << $group_cpuid))))
+			c=$((c + 1))
+		done
+		mask=`echo $temp_mask | awk '{printf "%x",$0}'`
+	fi
+
+	echo "$mask"
+}
+
+signal_handler()
+{
+	tst_exit
+}
+
+trap signal_handler SIGTERM SIGKILL
+
+while true; do
+	get_test_cpumask > $TRACING_PATH/tracing_cpumask
+done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
index 514f566..abb7cd1 100755
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
@@ -31,7 +31,8 @@ test_targets=" \
 trace_pipe current_tracer ftrace_enabled function_profile_enabled \
 set_event set_ftrace_pid stack_max_size stack_trace trace trace_clock \
 trace_options trace_stat tracing_enabled tracing_max_latency \
-tracing_on function_profile_enabled buffer_size_kb"
+tracing_on function_profile_enabled buffer_size_kb tracing_cpumask \
+set_ftrace_filter"
 
 get_skip_targets()
 {
-- 
1.8.3.1



More information about the ltp mailing list