common_tests 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. # common_tests - Shell script commonly used by pstore test scripts
  3. #
  4. # Copyright (C) Hitachi Ltd., 2015
  5. # Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
  6. #
  7. # Released under the terms of the GPL v2.
  8. # Utilities
  9. errexit() { # message
  10. echo "Error: $1" 1>&2
  11. exit 1
  12. }
  13. absdir() { # file_path
  14. (cd `dirname $1`; pwd)
  15. }
  16. show_result() { # result_value
  17. if [ $1 -eq 0 ]; then
  18. prlog "ok"
  19. else
  20. prlog "FAIL"
  21. rc=1
  22. fi
  23. }
  24. check_files_exist() { # type of pstorefs file
  25. if [ -e ${1}-${backend}-0 ]; then
  26. prlog "ok"
  27. for f in `ls ${1}-${backend}-*`; do
  28. prlog -e "\t${f}"
  29. done
  30. else
  31. prlog "FAIL"
  32. rc=1
  33. fi
  34. }
  35. operate_files() { # tested value, files, operation
  36. if [ $1 -eq 0 ]; then
  37. prlog
  38. for f in $2; do
  39. prlog -ne "\t${f} ... "
  40. # execute operation
  41. $3 $f
  42. show_result $?
  43. done
  44. else
  45. prlog " ... FAIL"
  46. rc=1
  47. fi
  48. }
  49. # Parameters
  50. TEST_STRING_PATTERN="Testing pstore: uuid="
  51. UUID=`cat /proc/sys/kernel/random/uuid`
  52. TOP_DIR=`absdir $0`
  53. LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
  54. REBOOT_FLAG=$TOP_DIR/reboot_flag
  55. # Preparing logs
  56. LOG_FILE=$LOG_DIR/`basename $0`.log
  57. mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
  58. date > $LOG_FILE
  59. prlog() { # messages
  60. /bin/echo "$@" | tee -a $LOG_FILE
  61. }
  62. # Starting tests
  63. rc=0
  64. prlog "=== Pstore unit tests (`basename $0`) ==="
  65. prlog "UUID="$UUID
  66. prlog -n "Checking pstore backend is registered ... "
  67. backend=`cat /sys/module/pstore/parameters/backend`
  68. show_result $?
  69. prlog -e "\tbackend=${backend}"
  70. prlog -e "\tcmdline=`cat /proc/cmdline`"
  71. if [ $rc -ne 0 ]; then
  72. exit 1
  73. fi