b1c3757cdc0cfd0818f68442d5ea39d19775d8f1
[cascardo/linux.git] / tools / testing / selftests / pstore / common_tests
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
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