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 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 56