1#!/usr/local/bin/bash 2 3test_home=`dirname $0` 4valgrind="" 5verbose="" 6tests="" 7 8if [ "$test_home" = "." ]; then 9 test_home="$PWD" 10fi 11 12function info() { 13 printf "$*\n" 14} 15 16function error() { 17 printf " * ERROR: $*\n" 18} 19 20function run_as_root() { 21 CMD="$1" 22 shift 23 ARGS="$@" 24 25 # Test might not be executable if run from source directory 26 chmod a+x $CMD 27 28 CMD="$CMD $ARGS $verbose" 29 30 if [ $EUID -eq 0 ]; then 31 $CMD 32 33 elif [ -z $TRAVIS ]; then 34 # sudo doesn't work in buildbot, su doesn't work in travis 35 echo "Enter the root password..." 36 su root -c "$CMD" 37 38 else 39 echo "Enter the root password if prompted..." 40 sudo -- $CMD 41 fi 42} 43 44info "Test home is:\t$test_home" 45 46while true ; do 47 case "$1" in 48 all) tests="$tests pengine cli lrmd fencing"; shift;; 49 pengine|lrmd|pacemaker_remote|fencing|cli) tests="$tests $1"; shift;; 50 -V|--verbose) verbose="-V"; shift;; 51 -v|--valgrind) valgrind="-v"; shift;; 52 --) shift ; break ;; 53 "") break;; 54 *) echo "unknown option: $1"; exit 1;; 55 esac 56done 57 58if [ -z "$tests" ]; then 59 tests="pengine cli lrmd" 60fi 61 62failed="" 63for t in $tests; do 64 info "Executing the $t regression tests" 65 info "============================================================" 66 if [ -e $test_home/$t/regression.py ]; then 67 # fencing, lrmd need root access 68 run_as_root $test_home/$t/regression.py 69 rc=$? 70 71 elif [ $t == "pacemaker_remote" ] && [ -e $test_home/lrmd/regression.py ]; then 72 # pacemaker_remote 73 run_as_root $test_home/lrmd/regression.py -R 74 rc=$? 75 76 elif [ -e $test_home/$t/regression.sh ]; then 77 # pengine, cli 78 $test_home/$t/regression.sh $verbose $valgrind 79 rc=$? 80 81 elif [ $t = cli -a -e $test_home/tools ]; then 82 # cli when run from the source tree 83 t=tools 84 $test_home/$t/regression.sh $verbose $valgrind 85 rc=$? 86 87 else 88 error "Cannot find $t test in $test_home" 89 rc=1 90 fi 91 92 if [ $rc != 0 ]; then 93 info "$t regression tests failed: $rc" 94 failed="$failed $t" 95 fi 96 97 info "============================================================" 98 info "" 99 info "" 100done 101 102if [ -z "$failed" ]; then 103 exit 0 104fi 105 106error "regression tests for $failed failed" 107exit 1 108