• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -xe
2#
3# Kdump test driver: test case will trigger panic, and then crash
4# dump. The test result is collected via dumped vmcore. For more
5# information about kdump dirver please refer to doc/README.kdump.
6#
7# Copyright (C) 2008, Intel Corp.
8#   Author: Huang Ying <ying.huang@intel.com>
9#
10# This file is based on kdump test case in LTP.
11#
12# This file is released under the GPLv2.
13#
14
15sd=$(dirname "$0")
16export ROOT=`(cd $sd/../..; pwd)`
17
18export driver=kdump
19
20. $ROOT/lib/functions.sh
21setup_path
22. $ROOT/lib/dirs.sh
23. $ROOT/lib/mce.sh
24
25setup_crontab ()
26{
27    echo "Setup crontab."
28
29    set +e
30    crontab -r
31    set -e
32
33    # crontab in some distros will not read from STDIN.
34
35    cat <<EOF > $WDIR/kdump.cron
36SHELL=/bin/bash
37PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
38MAILTO=root
39@reboot cd "$(pwd)"; ${0} $conf >> $WDIR/log 2>&1; cat $WDIR/log > /dev/console
40EOF
41
42    crontab $WDIR/kdump.cron
43
44    echo "Enable cron daemon by default."
45
46    if [ -f /etc/init.d/crond ]; then
47        cron=crond
48    else
49        # SUSE
50        cron=cron
51    fi
52
53    # Red Hat and SUSE.
54    if [ -x "/sbin/chkconfig" ]; then
55        /sbin/chkconfig "${cron}" on
56
57    # Debian and Ubuntu.
58    elif [ -x "/sbin/update-rc.d" ]; then
59        /sbin/update-rc.d "${cron}" defaults
60    fi
61}
62
63setup_kdump ()
64{
65    echo "Start kdump daemon."
66
67    if [ -f /etc/init.d/kdump ]; then
68	    daemon=kdump
69    else
70	    #SLE11
71	    daemon=boot.kdump
72    fi
73
74    /etc/init.d/"${daemon}" restart
75
76    echo "Enable kdump daemon by default."
77    # Red Hat and SUSE.
78    if [ -x "/sbin/chkconfig" ]; then
79        /sbin/chkconfig "${daemon}" on
80
81    # Debian and Ubuntu.
82    elif [ -x "/sbin/update-rc.d" ]; then
83        /sbin/update-rc.d "${daemon}" defaults
84    fi
85}
86
87get_klog()
88{
89    klog=$RDIR/$this_case/klog
90    cat <<EOF > $WDIR/get_klog_gdb.cmd
91dump memory $klog log_buf log_buf+log_end
92EOF
93    set +e
94    gdb -batch -batch-silent -x $WDIR/get_klog_gdb.cmd $VMLINUX $vmcore \
95	> /dev/null 2>&1
96    ret=$?
97    set -e
98    if [ $ret -eq 0 -a -s $klog ]; then
99	export klog
100    else
101	echo "  Failed: can not get kernel log"
102	rm -rf $klog
103    fi
104}
105
106dump_gcov()
107{
108    if [ -z "$GCOV" ]; then
109	return
110    fi
111    if ! chk_gcov; then
112	echo "gcov is not supported by kernel or there is no " \
113	    "gcov utility installed"
114	echo "disabling gcov support"
115	unset GCOV
116	return
117    fi
118    if [ -z "$KSRC_DIR" ]; then
119	echo "  Failed: please set KSRC_DIR for GCOV"
120	return
121    else
122	KSRC_DIR=$(set -P && cd "$KSRC_DIR" && pwd)
123	if [ -z "$KSRC_DIR"]; then
124	    echo "  Failed: Invalid KSRC_DIR, please check your setup"
125	    return
126	fi
127    fi
128    export KSRC_DIR
129    local gcov_head_raw=$WDIR/dump_gcov_head_raw
130    cat <<EOF > $WDIR/dump_gcov_gdb.cmd
131dump value $gcov_head_raw (void *)gcov_info_head
132EOF
133    set +e
134    gdb -batch -batch-silent -x $WDIR/dump_gcov_gdb.cmd $VMLINUX $vmcore \
135	> /dev/null 2>&1
136    ret=$?
137    set -e
138    if [ $ret -ne 0 -o ! -s $gcov_head_raw ]; then
139	echo "  Failed: can not get kernel gcov_info_head"
140	return
141    fi
142    wl=$(stat -c '%s' $gcov_head_raw)
143    h=$(echo -n 0x; od -A n -t x$wl $gcov_head_raw | tr -d ' ')
144    if ! gcovdump -g $h $vmcore &> /dev/null; then
145	echo "  Failed: can not dump kernel gcov info"
146	return
147    fi
148cat <<"EOF" > $WDIR/dump_gcov_deskew.sh
149    fn="$1"
150    bfn=$(basename "$fn")
151    dbfn="${bfn##\.tmp_}"
152    if [ -z "$dbfn" ]; then
153        return
154    fi
155    d=$(dirname "$fn")
156    cp $fn "$d/$dbfn"
157EOF
158    chmod +x $WDIR/dump_gcov_deskew.sh
159    find $KSRC_DIR \( -name '*.tmp_*gcno' -o -name '*.tmp_*gcda' \) \
160        -exec $WDIR/dump_gcov_deskew.sh \{\} \;
161
162    export GCOV=dump
163}
164
165get_result ()
166{
167    vmcore=$(ls -t "${COREDIR}"/*/vmcore* 2>/dev/null | head -1)
168
169    if [ -n "$vmcore" -a -f "$vmcore" ]; then
170	export vmcore
171	get_klog
172	dump_gcov
173    else
174	echo "  Failed: can not get vmcore"
175    fi
176
177    export reboot=1
178
179    $CDIR/$case_sh get_result
180}
181
182verify_case ()
183{
184    if [ -z "$vmcore" ]; then
185	echo "  Failed: can not got vmcore"
186    fi
187    $CDIR/$case_sh verify
188}
189
190trigger_case ()
191{
192    # Be careful to define COREDIR.
193    rm -rf "${COREDIR}"/*
194
195    # Save STDIO buffers.
196    sync
197    $CDIR/$case_sh trigger
198}
199
200# Start test.
201if [ $# -lt 1 ]; then
202    die "Usage: $0 <config>"
203fi
204
205conf=$(basename "$1")
206
207. $CONF_DIR/$conf
208
209driver_prepare
210set_tolerant 1
211set_panic_on_oops 0
212
213# Check mandatory variables.
214if [ -z "${COREDIR}" ]; then
215    die "Fail: some mandatory variables are missing from configuration file."
216fi
217
218# Reboot the machine first to take advantage of boot parameter
219# changes.
220if [ ! -f $WDIR/stamps/setupped ]; then
221    echo "Setup test environment."
222
223    setup_crontab
224
225    $SDIR/setup.sh $CONF_DIR/$conf
226
227    echo > $WDIR/stamps/setupped
228
229    echo "System is going to reboot."
230    /sbin/shutdown -r now
231    sleep 60
232    exit -1
233fi
234
235#if mce_inject is a module, it is ensured to have been loaded
236if modinfo mce_inject > /dev/null 2>&1; then
237    if ! lsmod | grep -q mce_inject; then
238        if ! modprobe mce_inject; then
239	    die "module mce_inject isn't supported ?"
240        fi
241    fi
242fi
243
244for case_sh in ${CASES}; do
245    for this_case in $($CDIR/$case_sh enumerate); do
246	export this_case
247	_this_case=$(echo $this_case | tr '/' '_')
248
249	if [ -f $WDIR/stamps/${_this_case}_done ]; then
250	    continue
251	fi
252
253        # First Test.
254	if [ ! -f $WDIR/stamps/first_test_checked ]; then
255            echo "First test..."
256            echo "Verify Boot Loader."
257            if ! grep 'crashkernel=' /proc/cmdline; then
258		die "Fail: error changing Boot Loader, no crashkernel=."
259            fi
260            setup_kdump
261	    echo > $WDIR/stamps/first_test_checked
262	fi
263
264	if [ ! -f $WDIR/stamps/${_this_case}_triggered ]; then
265	    echo > $WDIR/stamps/${_this_case}_triggered
266
267	    mkdir -p $RDIR/$this_case
268	    rm -rf $RDIR/$this_case/*
269	    echo -e "\n$this_case:" | tee -a $RDIR/result
270
271	    echo "Running current test $this_case."
272
273	    trigger_case | tee -a $RDIR/result
274
275	    triggering=1
276	fi
277
278	sleep 5
279
280	if [ -z "$triggering" ]; then
281            (get_result; verify_case) | tee -a $RDIR/result
282	else
283	    echo "  Failed: Failed to trigger kdump" | tee -a $RDIR/result
284	fi
285	echo > $WDIR/stamps/${_this_case}_done
286
287        # Wait for system to fully boot and leave a chance for user to
288        # stop test
289	sleep 55
290    done
291done
292
293echo "Test run complete" | tee -a $RDIR/result
294
295# We are done.
296# Reset.
297crontab -r
298
299exit 0
300