Skip to content

Commit cc04a46

Browse files
toyookaShuah Khan
authored andcommitted
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 <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Tony Luck <[email protected]> Cc: Anton Vorontsov <[email protected]> Cc: Colin Cross <[email protected]> Cc: Kees Cook <[email protected]> Cc: Mark Salyzyn <[email protected]> Cc: Seiji Aguchi <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Shuah Khan <[email protected]>
1 parent be14484 commit cc04a46

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ TARGETS += mount
1313
TARGETS += mqueue
1414
TARGETS += net
1515
TARGETS += powerpc
16+
TARGETS += pstore
1617
TARGETS += ptrace
1718
TARGETS += seccomp
1819
TARGETS += size
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Makefile for pstore selftests.
2+
# Expects pstore backend is registered.
3+
4+
all:
5+
6+
TEST_PROGS := pstore_tests
7+
TEST_FILES := common_tests
8+
9+
include ../lib.mk
10+
11+
clean:
12+
rm -rf logs/* *uuid
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>
7+
#
8+
# Released under the terms of the GPL v2.
9+
10+
# Utilities
11+
errexit() { # message
12+
echo "Error: $1" 1>&2
13+
exit 1
14+
}
15+
16+
absdir() { # file_path
17+
(cd `dirname $1`; pwd)
18+
}
19+
20+
show_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
30+
TEST_STRING_PATTERN="Testing pstore: uuid="
31+
UUID=`cat /proc/sys/kernel/random/uuid`
32+
TOP_DIR=`absdir $0`
33+
LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
34+
35+
# Preparing logs
36+
LOG_FILE=$LOG_DIR/`basename $0`.log
37+
mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
38+
date > $LOG_FILE
39+
prlog() { # messages
40+
/bin/echo "$@" | tee -a $LOG_FILE
41+
}
42+
43+
# Starting tests
44+
rc=0
45+
prlog "=== Pstore unit tests (`basename $0`) ==="
46+
prlog "UUID="$UUID
47+
48+
prlog -n "Checking pstore backend is registered ... "
49+
backend=`cat /sys/module/pstore/parameters/backend`
50+
show_result $?
51+
prlog -e "\tbackend=${backend}"
52+
prlog -e "\tcmdline=`cat /proc/cmdline`"
53+
if [ $rc -ne 0 ]; then
54+
exit 1
55+
fi
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>
7+
#
8+
# Released under the terms of the GPL v2.
9+
10+
. ./common_tests
11+
12+
prlog -n "Checking pstore console is registered ... "
13+
dmesg | grep -q "console \[pstore"
14+
show_result $?
15+
16+
prlog -n "Checking /dev/pmsg0 exists ... "
17+
test -e /dev/pmsg0
18+
show_result $?
19+
20+
prlog -n "Writing unique string to /dev/pmsg0 ... "
21+
if [ -e "/dev/pmsg0" ]; then
22+
echo "${TEST_STRING_PATTERN}""$UUID" > /dev/pmsg0
23+
show_result $?
24+
echo "$UUID" > $TOP_DIR/uuid
25+
else
26+
prlog "FAIL"
27+
rc=1
28+
fi
29+
30+
exit $rc

0 commit comments

Comments
 (0)