aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiraku Toyooka <hiraku.toyooka.gu@hitachi.com>2015-10-02 07:46:39 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2015-10-15 22:00:32 -0400
commitcc04a46f11ea046ed53e2c832ae29e4790f7e35f (patch)
tree3fab5306041e631eca14a0d4f50d887f223cac77
parentbe14484be0a88574cf913bdf957ee91a8fafb0f8 (diff)
selftests/pstore: add pstore test script for pre-reboot
The pstore_tests script includes test cases which check pstore's behavior before crash (and reboot). The test cases are currently following. - Check pstore backend is registered - Check pstore console is registered - Check /dev/pmsg0 exists - Write unique string to /dev/pmsg0 The unique string written to /dev/pmsg includes UUID. The UUID is also left in 'uuid' file in order to enable us to check if the pmsg keeps the string correctly after reboot. Example usage is following. # cd /path/to/selftests # make run_tests -C pstore (or just .pstore/pstore_tests) make: Entering directory '/path/to/selftests/pstore' === Pstore unit tests (pstore_tests) === UUID=b49b02cf-b0c2-4309-be43-b08c3971e37f 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 Checking pstore console is registered ... ok Checking /dev/pmsg0 exists ... ok Writing unique string to /dev/pmsg0 ... ok selftests: pstore_tests [PASS] make: Leaving directory '/path/to/selftests/pstore' We can also see test logs later. # cat pstore/logs/20151001-072718_b49b02cf-b0c2-4309-be43-b08c3971e37f/pstore_tests.log Thu Oct 1 07:27:18 UTC 2015 === Pstore unit tests (pstore_tests) === UUID=b49b02cf-b0c2-4309-be43-b08c3971e37f 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 Checking pstore console is registered ... ok Checking /dev/pmsg0 exists ... ok Writing unique string to /dev/pmsg0 ... ok 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/Makefile1
-rw-r--r--tools/testing/selftests/pstore/Makefile12
-rwxr-xr-xtools/testing/selftests/pstore/common_tests55
-rwxr-xr-xtools/testing/selftests/pstore/pstore_tests30
4 files changed, 98 insertions, 0 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index cfe121353eec..1a8fb99c4fa8 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -13,6 +13,7 @@ TARGETS += mount
13TARGETS += mqueue 13TARGETS += mqueue
14TARGETS += net 14TARGETS += net
15TARGETS += powerpc 15TARGETS += powerpc
16TARGETS += pstore
16TARGETS += ptrace 17TARGETS += ptrace
17TARGETS += seccomp 18TARGETS += seccomp
18TARGETS += size 19TARGETS += size
diff --git a/tools/testing/selftests/pstore/Makefile b/tools/testing/selftests/pstore/Makefile
new file mode 100644
index 000000000000..48623f77a66f
--- /dev/null
+++ b/tools/testing/selftests/pstore/Makefile
@@ -0,0 +1,12 @@
1# Makefile for pstore selftests.
2# Expects pstore backend is registered.
3
4all:
5
6TEST_PROGS := pstore_tests
7TEST_FILES := common_tests
8
9include ../lib.mk
10
11clean:
12 rm -rf logs/* *uuid
diff --git a/tools/testing/selftests/pstore/common_tests b/tools/testing/selftests/pstore/common_tests
new file mode 100755
index 000000000000..b1c3757cdc0c
--- /dev/null
+++ b/tools/testing/selftests/pstore/common_tests
@@ -0,0 +1,55 @@
1#!/bin/sh
2
3# common_tests - Shell script commonly used by pstore test scripts
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# Utilities
11errexit() { # message
12 echo "Error: $1" 1>&2
13 exit 1
14}
15
16absdir() { # file_path
17 (cd `dirname $1`; pwd)
18}
19
20show_result() { # result_value
21 if [ $1 -eq 0 ]; then
22 prlog "ok"
23 else
24 prlog "FAIL"
25 rc=1
26 fi
27}
28
29# Parameters
30TEST_STRING_PATTERN="Testing pstore: uuid="
31UUID=`cat /proc/sys/kernel/random/uuid`
32TOP_DIR=`absdir $0`
33LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
34
35# Preparing logs
36LOG_FILE=$LOG_DIR/`basename $0`.log
37mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
38date > $LOG_FILE
39prlog() { # messages
40 /bin/echo "$@" | tee -a $LOG_FILE
41}
42
43# Starting tests
44rc=0
45prlog "=== Pstore unit tests (`basename $0`) ==="
46prlog "UUID="$UUID
47
48prlog -n "Checking pstore backend is registered ... "
49backend=`cat /sys/module/pstore/parameters/backend`
50show_result $?
51prlog -e "\tbackend=${backend}"
52prlog -e "\tcmdline=`cat /proc/cmdline`"
53if [ $rc -ne 0 ]; then
54 exit 1
55fi
diff --git a/tools/testing/selftests/pstore/pstore_tests b/tools/testing/selftests/pstore/pstore_tests
new file mode 100755
index 000000000000..f25d2a349a60
--- /dev/null
+++ b/tools/testing/selftests/pstore/pstore_tests
@@ -0,0 +1,30 @@
1#!/bin/sh
2
3# pstore_tests - Check pstore's behavior before 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
12prlog -n "Checking pstore console is registered ... "
13dmesg | grep -q "console \[pstore"
14show_result $?
15
16prlog -n "Checking /dev/pmsg0 exists ... "
17test -e /dev/pmsg0
18show_result $?
19
20prlog -n "Writing unique string to /dev/pmsg0 ... "
21if [ -e "/dev/pmsg0" ]; then
22 echo "${TEST_STRING_PATTERN}""$UUID" > /dev/pmsg0
23 show_result $?
24 echo "$UUID" > $TOP_DIR/uuid
25else
26 prlog "FAIL"
27 rc=1
28fi
29
30exit $rc