From cc04a46f11ea046ed53e2c832ae29e4790f7e35f Mon Sep 17 00:00:00 2001 From: Hiraku Toyooka Date: Fri, 2 Oct 2015 20:46:39 +0900 Subject: 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 Cc: Shuah Khan Cc: Tony Luck Cc: Anton Vorontsov Cc: Colin Cross Cc: Kees Cook Cc: Mark Salyzyn Cc: Seiji Aguchi Cc: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org Signed-off-by: Shuah Khan --- tools/testing/selftests/pstore/common_tests | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tools/testing/selftests/pstore/common_tests (limited to 'tools/testing/selftests/pstore/common_tests') 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 @@ +#!/bin/sh + +# common_tests - Shell script commonly used by pstore test scripts +# +# Copyright (C) Hitachi Ltd., 2015 +# Written by Hiraku Toyooka +# +# Released under the terms of the GPL v2. + +# Utilities +errexit() { # message + echo "Error: $1" 1>&2 + exit 1 +} + +absdir() { # file_path + (cd `dirname $1`; pwd) +} + +show_result() { # result_value + if [ $1 -eq 0 ]; then + prlog "ok" + else + prlog "FAIL" + rc=1 + fi +} + +# Parameters +TEST_STRING_PATTERN="Testing pstore: uuid=" +UUID=`cat /proc/sys/kernel/random/uuid` +TOP_DIR=`absdir $0` +LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/ + +# Preparing logs +LOG_FILE=$LOG_DIR/`basename $0`.log +mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" +date > $LOG_FILE +prlog() { # messages + /bin/echo "$@" | tee -a $LOG_FILE +} + +# Starting tests +rc=0 +prlog "=== Pstore unit tests (`basename $0`) ===" +prlog "UUID="$UUID + +prlog -n "Checking pstore backend is registered ... " +backend=`cat /sys/module/pstore/parameters/backend` +show_result $? +prlog -e "\tbackend=${backend}" +prlog -e "\tcmdline=`cat /proc/cmdline`" +if [ $rc -ne 0 ]; then + exit 1 +fi -- cgit v1.2.3