• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Copyright (C) 2017 Red Hat, Inc.
4#
5# This program is free software;  you can redistribute it and#or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13# for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, see <http://www.gnu.org/licenses/>.
17#
18#
19# Test description: Test functionality of dynamic debug feature by enabling
20#                   and disabling traces with available flags. Check that these
21#                   settings don't cause issues by searching dmesg.
22#
23#                   This test handles changes of dynamic debug interface from
24#                   commits 5ca7d2a6 (dynamic_debug: describe_flags with
25#                   '=[pmflt_]*') and 8ba6ebf5 (Dynamic debug: Add more flags)
26#
27# Usage
28# ./dynamic_debug01.sh
29
30TST_TESTFUNC=ddebug_test
31TST_NEEDS_CMDS="awk /bin/echo"
32TST_NEEDS_TMPDIR=1
33TST_NEEDS_ROOT=1
34TST_SETUP=setup
35TST_CLEANUP=cleanup
36
37. tst_test.sh
38
39
40DEBUGFS_WAS_MOUNTED=0
41DEBUGFS_PATH=""
42DEBUGFS_CONTROL=""
43DYNDEBUG_STATEMENTS="./debug_statements"
44EMPTY_FLAG="-"
45NEW_INTERFACE=0
46
47
48mount_debugfs()
49{
50	if grep -q debugfs /proc/mounts ; then
51		DEBUGFS_WAS_MOUNTED=1
52		DEBUGFS_PATH=$(awk '/debugfs/{print $2}' /proc/mounts)
53		tst_res TINFO "debugfs already mounted at $DEBUGFS_PATH"
54	else
55		if ! grep -q debugfs /proc/filesystems ; then
56			tst_res TCONF "debugfs not supported"
57		fi
58		DEBUGFS_PATH="./tst_debug"
59		mkdir "$DEBUGFS_PATH"
60		if mount -t debugfs xxx "$DEBUGFS_PATH" ; then
61			tst_res TINFO "debugfs mounted at $DEBUGFS_PATH"
62		else
63			tst_res TFAIL "Unable to mount debugfs"
64		fi
65	fi
66}
67
68setup()
69{
70	if tst_kvcmp -lt 2.6.30 ; then
71		tst_brk TCONF "Dynamic debug is available since version 2.6.30"
72	fi
73
74	mount_debugfs
75	if [ ! -d "$DEBUGFS_PATH/dynamic_debug" ] ; then
76		tst_brk TBROK "Unable to find $DEBUGFS_PATH/dynamic_debug"
77	fi
78	DEBUGFS_CONTROL="$DEBUGFS_PATH/dynamic_debug/control"
79	if [ ! -e "$DEBUGFS_CONTROL" ] ; then
80		tst_brk TBROK "Unable to find $DEBUGFS_CONTROL"
81	fi
82
83	# Both patches with changes were backported to RHEL6 kernel 2.6.32-547
84	if tst_kvcmp -ge '3.4 RHEL6:2.6.32-547' ; then
85		NEW_INTERFACE=1
86		EMPTY_FLAG="=_"
87	fi
88
89	grep -v "^#" "$DEBUGFS_CONTROL" > "$DYNDEBUG_STATEMENTS"
90}
91
92do_flag()
93{
94	local FLAG="$1"
95	local OPTION_TO_SET="$2"
96	local OPTION_VALUE="$3"
97
98	if ! echo "$OPTION_TO_SET $OPTION_VALUE $FLAG" > \
99		"$DEBUGFS_CONTROL" ; then
100		tst_res TFAIL "Setting '$OPTION_TO_SET $OPTION_VALUE " \
101			"$FLAG' failed with $?!"
102	fi
103}
104
105do_all_flags()
106{
107	OPTION="$1"
108	ALL_INPUTS="$2"
109
110	for INPUT_LINE in $ALL_INPUTS; do
111		do_flag "+p" "$OPTION" "$INPUT_LINE"
112		if tst_kvcmp -ge 3.2 || [ $NEW_INTERFACE -eq 1 ] ; then
113			do_flag "+flmt" "$OPTION" "$INPUT_LINE"
114			do_flag "-flmt" "$OPTION" "$INPUT_LINE"
115		fi
116		do_flag "-p" "$OPTION" "$INPUT_LINE"
117	done
118
119	if awk -v emp="$EMPTY_FLAG" '$3 != emp' "$DEBUGFS_CONTROL" \
120		| grep -v -q "^#" ; then
121		tst_res TFAIL "Failed to remove all set flags"
122	fi
123}
124
125ddebug_test()
126{
127	dmesg > ./dmesg.old
128
129	DD_FUNCS=$(awk -F " |]" '{print $3}' "$DYNDEBUG_STATEMENTS" \
130		| sort | uniq)
131	DD_FILES=$(awk -F " |:" '{print $1}' "$DYNDEBUG_STATEMENTS" \
132		| sort | uniq)
133	DD_LINES=$(awk -F " |:" '{print $2}' "$DYNDEBUG_STATEMENTS" \
134		| sort | uniq)
135	DD_MODULES=$(awk -F [][] '{print $2}' "$DYNDEBUG_STATEMENTS" \
136		| sort | uniq)
137
138	do_all_flags "func" "$DD_FUNCS"
139	do_all_flags "file" "$DD_FILES"
140	do_all_flags "line" "$DD_LINES"
141	do_all_flags "module" "$DD_MODULES"
142
143	dmesg > ./dmesg.new
144	sed -i -e 1,`wc -l < ./dmesg.old`d ./dmesg.new
145	if grep -q -e "Kernel panic" -e "Oops" -e "general protection fault" \
146		-e "general protection handler: wrong gs" -e "\(XEN\) Panic" \
147		-e "fault" -e "warn" -e "BUG" ./dmesg.new ; then
148		tst_res TFAIL "Issues found in dmesg!"
149	else
150		tst_res TPASS "Dynamic debug OK"
151	fi
152}
153
154cleanup()
155{
156	if [ -e "$DYNDEBUG_STATEMENTS" ]; then
157		FLAGS_SET=$(awk -v emp="$EMPTY_FLAG" '$3 != emp' $DYNDEBUG_STATEMENTS)
158	fi
159	if [ "$FLAGS_SET" ] ; then
160		FLAG_PREFIX=$([ $NEW_INTERFACE -eq 1 ] && echo "" || echo "+")
161		/bin/echo "$FLAGS_SET" | while read -r FLAG_LINE ; do
162			/bin/echo -n "$FLAG_LINE" \
163				| awk -v prf="$FLAG_PREFIX" -F " |:" \
164				'{print "file "$1" line "$2" "prf $4}' \
165				> "$DEBUGFS_CONTROL"
166		done
167	fi
168	if [ $DEBUGFS_WAS_MOUNTED -eq 0 -a -n "$DEBUGFS_PATH" ] ; then
169		tst_umount "$DEBUGFS_PATH"
170	fi
171}
172
173tst_run
174