Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 
0004 # common_tests - Shell script commonly used by pstore test scripts
0005 #
0006 # Copyright (C) Hitachi Ltd., 2015
0007 #  Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
0008 #
0009 
0010 # Utilities
0011 errexit() { # message
0012     echo "Error: $1" 1>&2
0013     exit 1
0014 }
0015 
0016 absdir() { # file_path
0017     (cd `dirname $1`; pwd)
0018 }
0019 
0020 show_result() { # result_value
0021     if [ $1 -eq 0 ]; then
0022         prlog "ok"
0023     else
0024         prlog "FAIL"
0025         rc=1
0026     fi
0027 }
0028 
0029 check_files_exist() { # type of pstorefs file
0030     if [ -e ${1}-${backend}-0 ]; then
0031         prlog "ok"
0032         for f in `ls ${1}-${backend}-*`; do
0033             prlog -e "\t${f}"
0034         done
0035     else
0036         prlog "FAIL"
0037         rc=1
0038     fi
0039 }
0040 
0041 operate_files() { # tested value, files, operation
0042     if [ $1 -eq 0 ]; then
0043         prlog
0044         for f in $2; do
0045             prlog -ne "\t${f} ... "
0046             # execute operation
0047             $3 $f
0048             show_result $?
0049         done
0050     else
0051         prlog " ... FAIL"
0052         rc=1
0053     fi
0054 }
0055 
0056 # Parameters
0057 TEST_STRING_PATTERN="Testing pstore: uuid="
0058 UUID=`cat /proc/sys/kernel/random/uuid`
0059 TOP_DIR=`absdir $0`
0060 LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
0061 REBOOT_FLAG=$TOP_DIR/reboot_flag
0062 
0063 # Preparing logs
0064 LOG_FILE=$LOG_DIR/`basename $0`.log
0065 mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
0066 date > $LOG_FILE
0067 prlog() { # messages
0068     /bin/echo "$@" | tee -a $LOG_FILE
0069 }
0070 
0071 # Starting tests
0072 rc=0
0073 prlog "=== Pstore unit tests (`basename $0`) ==="
0074 prlog "UUID="$UUID
0075 
0076 prlog -n "Checking pstore backend is registered ... "
0077 backend=`cat /sys/module/pstore/parameters/backend`
0078 show_result $?
0079 prlog -e "\tbackend=${backend}"
0080 prlog -e "\tcmdline=`cat /proc/cmdline`"
0081 if [ $rc -ne 0 ]; then
0082     exit 1
0083 fi