aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiraku Toyooka <hiraku.toyooka.gu@hitachi.com>2015-10-02 07:46:41 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2015-10-15 22:00:32 -0400
commitf615e2bb1331c5b9dc7f56f39f679738674a1e1f (patch)
treee12add4817e8685a3974d99363e00c8d6e61939f
parentcc04a46f11ea046ed53e2c832ae29e4790f7e35f (diff)
selftests/pstore: add pstore test scripts going with reboot
To test pstore in earnest, we have to cause kernel crash and check pstore filesystem after reboot. We add two scripts: - pstore_crash_test This script causes kernel crash and reboot. It is executed by 'make run_pstore_crash' in selftests. It can also be used with kdump. - pstore_post_reboot_tests This script includes test cases which check pstore's behavior after crash and reboot. It is executed together with pstore_tests by 'make run_tests [-C pstore]' in selftests. The test cases in pstore_post_reboot_tests are currently following. - Check pstore backend is registered - Mount pstore filesystem - Check dmesg/console/pmsg files exist in pstore filesystem - Check dmesg/console files contain oops end marker - Check pmsg file properly keeps the content written before crash - Remove all files in pstore filesystem Example usage is following. (before reboot) # cd /path/to/selftests # make run_tests -C pstore === Pstore unit tests (pstore_tests) === UUID=b49b02cf-b0c2-4309-be43-b08c3971e37f ... selftests: pstore_tests [PASS] === Pstore unit tests (pstore_post_reboot_tests) === UUID=953eb1bc-8e03-48d7-b27a-6552b24c5b7e Checking pstore backend is registered ... ok backend=ramoops cmdline=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait mem=768M ramoops.mem_address=0x30000000 ramoops.mem_size=0x10000 pstore_crash_test has not been executed yet. we skip further tests. selftests: pstore_post_reboot_tests [PASS] # make run_pstore_crash === Pstore unit tests (pstore_crash_test) === UUID=93c8972d-1466-430b-8c4a-28d8681e74c6 Checking pstore backend is registered ... ok backend=ramoops cmdline=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait mem=768M ramoops.mem_address=0x30000000 ramoops.mem_size=0x10000 Causing kernel crash ... (kernel crash and reboot) ... (after reboot) # make run_tests -C pstore === Pstore unit tests (pstore_tests) === UUID=8e511e77-2285-499f-8bc0-900d9af1fbcc ... selftests: pstore_tests [PASS] === Pstore unit tests (pstore_post_reboot_tests) === UUID=2dcc2132-4f3c-45aa-a38f-3b54bff8cef1 Checking pstore backend is registered ... ok backend=ramoops cmdline=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait mem=768M ramoops.mem_address=0x30000000 ramoops.mem_size=0x10000 Mounting pstore filesystem ... ok Checking dmesg files exist in pstore filesystem ... ok dmesg-ramoops-0 dmesg-ramoops-1 Checking console files exist in pstore filesystem ... ok console-ramoops-0 Checking pmsg files exist in pstore filesystem ... ok pmsg-ramoops-0 Checking dmesg files contain oops end marker dmesg-ramoops-0 ... ok dmesg-ramoops-1 ... ok Checking console file contains oops end marker ... ok Checking pmsg file properly keeps the content written before crash ... ok Removing all files in pstore filesystem console-ramoops-0 ... ok dmesg-ramoops-0 ... ok dmesg-ramoops-1 ... ok pmsg-ramoops-0 ... ok selftests: pstore_post_reboot_tests [PASS] Signed-off-by: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Anton Vorontsov <anton@enomsg.org> Cc: Colin Cross <ccross@android.com> Cc: Kees Cook <keescook@chromium.org> Cc: Mark Salyzyn <salyzyn@android.com> Cc: Seiji Aguchi <seiji.aguchi.tr@hitachi.com> Cc: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
-rw-r--r--tools/testing/selftests/Makefile3
-rw-r--r--tools/testing/selftests/pstore/Makefile7
-rwxr-xr-xtools/testing/selftests/pstore/common_tests28
-rwxr-xr-xtools/testing/selftests/pstore/pstore_crash_test30
-rwxr-xr-xtools/testing/selftests/pstore/pstore_post_reboot_tests77
5 files changed, 143 insertions, 2 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 1a8fb99c4fa8..2458288a8287 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -66,6 +66,9 @@ clean_hotplug:
66 make -C $$TARGET clean; \ 66 make -C $$TARGET clean; \
67 done; 67 done;
68 68
69run_pstore_crash:
70 make -C pstore run_crash
71
69INSTALL_PATH ?= install 72INSTALL_PATH ?= install
70INSTALL_PATH := $(abspath $(INSTALL_PATH)) 73INSTALL_PATH := $(abspath $(INSTALL_PATH))
71ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 74ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
diff --git a/tools/testing/selftests/pstore/Makefile b/tools/testing/selftests/pstore/Makefile
index 48623f77a66f..bd7abe24ea08 100644
--- a/tools/testing/selftests/pstore/Makefile
+++ b/tools/testing/selftests/pstore/Makefile
@@ -3,10 +3,13 @@
3 3
4all: 4all:
5 5
6TEST_PROGS := pstore_tests 6TEST_PROGS := pstore_tests pstore_post_reboot_tests
7TEST_FILES := common_tests 7TEST_FILES := common_tests pstore_crash_test
8 8
9include ../lib.mk 9include ../lib.mk
10 10
11run_crash:
12 @sh pstore_crash_test || { echo "pstore_crash_test: [FAIL]"; exit 1; }
13
11clean: 14clean:
12 rm -rf logs/* *uuid 15 rm -rf logs/* *uuid
diff --git a/tools/testing/selftests/pstore/common_tests b/tools/testing/selftests/pstore/common_tests
index b1c3757cdc0c..3ea64d7cf1cd 100755
--- a/tools/testing/selftests/pstore/common_tests
+++ b/tools/testing/selftests/pstore/common_tests
@@ -26,11 +26,39 @@ show_result() { # result_value
26 fi 26 fi
27} 27}
28 28
29check_files_exist() { # type of pstorefs file
30 if [ -e ${1}-${backend}-0 ]; then
31 prlog "ok"
32 for f in `ls ${1}-${backend}-*`; do
33 prlog -e "\t${f}"
34 done
35 else
36 prlog "FAIL"
37 rc=1
38 fi
39}
40
41operate_files() { # tested value, files, operation
42 if [ $1 -eq 0 ]; then
43 prlog
44 for f in $2; do
45 prlog -ne "\t${f} ... "
46 # execute operation
47 $3 $f
48 show_result $?
49 done
50 else
51 prlog " ... FAIL"
52 rc=1
53 fi
54}
55
29# Parameters 56# Parameters
30TEST_STRING_PATTERN="Testing pstore: uuid=" 57TEST_STRING_PATTERN="Testing pstore: uuid="
31UUID=`cat /proc/sys/kernel/random/uuid` 58UUID=`cat /proc/sys/kernel/random/uuid`
32TOP_DIR=`absdir $0` 59TOP_DIR=`absdir $0`
33LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/ 60LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
61REBOOT_FLAG=$TOP_DIR/reboot_flag
34 62
35# Preparing logs 63# Preparing logs
36LOG_FILE=$LOG_DIR/`basename $0`.log 64LOG_FILE=$LOG_DIR/`basename $0`.log
diff --git a/tools/testing/selftests/pstore/pstore_crash_test b/tools/testing/selftests/pstore/pstore_crash_test
new file mode 100755
index 000000000000..1a4afe5c12b6
--- /dev/null
+++ b/tools/testing/selftests/pstore/pstore_crash_test
@@ -0,0 +1,30 @@
1#!/bin/sh
2
3# pstore_crash_test - Pstore test shell script which causes crash and reboot
4#
5# Copyright (C) Hitachi Ltd., 2015
6# Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
7#
8# Released under the terms of the GPL v2.
9
10# exit if pstore backend is not registered
11. ./common_tests
12
13prlog "Causing kernel crash ..."
14
15# enable all functions triggered by sysrq
16echo 1 > /proc/sys/kernel/sysrq
17# setting to reboot in 3 seconds after panic
18echo 3 > /proc/sys/kernel/panic
19
20# save uuid file by different name because next test execution will replace it.
21mv $TOP_DIR/uuid $TOP_DIR/prev_uuid
22
23# create a file as reboot flag
24touch $REBOOT_FLAG
25sync
26
27# cause crash
28# Note: If you use kdump and want to see kmesg-* files after reboot, you should
29# specify 'crash_kexec_post_notifiers' in 1st kernel's cmdline.
30echo c > /proc/sysrq-trigger
diff --git a/tools/testing/selftests/pstore/pstore_post_reboot_tests b/tools/testing/selftests/pstore/pstore_post_reboot_tests
new file mode 100755
index 000000000000..6ccb154cb4aa
--- /dev/null
+++ b/tools/testing/selftests/pstore/pstore_post_reboot_tests
@@ -0,0 +1,77 @@
1#!/bin/sh
2
3# pstore_post_reboot_tests - Check pstore's behavior after crash/reboot
4#
5# Copyright (C) Hitachi Ltd., 2015
6# Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
7#
8# Released under the terms of the GPL v2.
9
10. ./common_tests
11
12if [ -e $REBOOT_FLAG ]; then
13 rm $REBOOT_FLAG
14else
15 prlog "pstore_crash_test has not been executed yet. we skip further tests."
16 exit 0
17fi
18
19prlog -n "Mounting pstore filesystem ... "
20mount_info=`grep pstore /proc/mounts`
21if [ $? -eq 0 ]; then
22 mount_point=`echo ${mount_info} | cut -d' ' -f2 | head -n1`
23 prlog "ok"
24else
25 mount none /sys/fs/pstore -t pstore
26 if [ $? -eq 0 ]; then
27 mount_point=`grep pstore /proc/mounts | cut -d' ' -f2 | head -n1`
28 prlog "ok"
29 else
30 prlog "FAIL"
31 exit 1
32 fi
33fi
34
35cd ${mount_point}
36
37prlog -n "Checking dmesg files exist in pstore filesystem ... "
38check_files_exist dmesg
39
40prlog -n "Checking console files exist in pstore filesystem ... "
41check_files_exist console
42
43prlog -n "Checking pmsg files exist in pstore filesystem ... "
44check_files_exist pmsg
45
46prlog -n "Checking dmesg files contain oops end marker"
47grep_end_trace() {
48 grep -q "\---\[ end trace" $1
49}
50files=`ls dmesg-${backend}-*`
51operate_files $? "$files" grep_end_trace
52
53prlog -n "Checking console file contains oops end marker ... "
54grep -q "\---\[ end trace" console-${backend}-0
55show_result $?
56
57prlog -n "Checking pmsg file properly keeps the content written before crash ... "
58prev_uuid=`cat $TOP_DIR/prev_uuid`
59if [ $? -eq 0 ]; then
60 nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0`
61 if [ $nr_matched -eq 1 ]; then
62 grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0
63 show_result $?
64 else
65 prlog "FAIL"
66 rc=1
67 fi
68else
69 prlog "FAIL"
70 rc=1
71fi
72
73prlog -n "Removing all files in pstore filesystem "
74files=`ls *-${backend}-*`
75operate_files $? "$files" rm
76
77exit $rc