1#!/usr/local/bin/bash -l 2# 3# Copyright (C) 2005-2009 Heiko Appel, David Strubbe 4# 5# Originally GPL, dual-licensed under BerkeleyGW license by permission of these authors. 6# 7# Based on Octopus file: 8# $Id: oct-run_testsuite 2730 2007-02-28 20:57:45Z xavier $ 9 10 11# Paths. 12#prefix=/global/home/users/dstrubbe/octopus 13#pkgdatadir=${prefix}/share/octopus 14#testsuite="$pkgdatadir/testsuite" 15testsuite="." 16 17# Failure reporting. 18failed_tests=0 19skipped_tests=0 20passed_tests=0 21total_tests=0 22failure_report="" 23 24 25# Usage. 26function usage() { 27 cat <<EOF 28 29 Copyright (C) 2005-2009 by Heiko Appel, David Strubbe 30 31Usage: run_testsuite [options] 32 33 -h this message 34 -n dry-run mode (show what would be executed) 35 -g LIST comma-separated list of test groups to run 36 -q query testfiles for the given groups (no tests are run) 37 -b DIR directory where to look for the binary files [default: ../bin] 38 -d DIR directory where to look for the testsuite 39 -l local run 40 -p PREFIX installation prefix [default: /usr] 41 -w without MPI tests (do not run parallel tests) 42 -c delete all .log files and work directories after the run 43 44Report bugs to <BerkeleyGW@civet.berkeley.edu>. 45EOF 46 exit 0; 47} 48 49 50# Find tests to run. Takes as argument the string passed to the 51# -g command line option. 52function find_tests() { 53 groups="$1" 54 if [ -n "$groups" ]; then 55 groups_pat=`echo "$groups" | sed 's/ *, */|/'` 56 groups_pat="^TestGroups *:.*($groups_pat)" 57 else # No groups given defaults to all tests. 58 groups_pat="." 59 fi 60 testfiles=`find $testsuite -name "*.test" | \ 61 xargs grep -l -E "$groups_pat" | sort -u` 62 echo "$testfiles" 63} 64 65 66# Run all tests. Takes as first argument a list of testfile names. 67function run_testsuite() { 68 69tests="$1" 70 71# Check for 'preserve working directories' flag. 72if [ "$cleanup" == "yes" ]; then 73 preserve_opt="" 74else 75 preserve_opt="-p" 76fi 77 78for y in $tests; do 79 total_tests=$((total_tests + 1)) 80 ybase=`basename $y` 81 xybase=${ybase%.test} 82# if [ "${local_run}" == "yes" ]; then 83# bin_directory=`pwd`/../src/main 84# runtest_directory=$testsuite 85# else 86# bin_directory=$prefix/bin 87# runtest_directory=$bin_directory 88# fi 89# if [ -n "${exec_suffix}" ]; then 90# suffix_opt="-s ${exec_suffix}" 91# else 92# suffix_opt="" 93# fi 94 if [ -d "${bin_directory}" ]; then 95 ./run_regression_test.pl -l $opt_n \ 96 $preserve_opt -D $bin_directory -f $y $serial_opt | \ 97 tee ${xybase}.log 98 # Look for failed/passed/skipped testcases and add 99 # to failure summary. 100 failures=${PIPESTATUS[0]} 101 if [ "${failures}" -eq 0 ]; then 102 passed_tests=$((passed_tests + 1)) 103 elif [ ${failures} -eq 254 ]; then 104 skipped_tests=$((skipped_tests + 1)) 105 else 106 failed_tests=$((failed_tests + 1)) 107 test_name=`echo $y | sed "s|$testsuite/||"` 108 name_length=`echo -n $test_name | wc -m` 109 space_length=$((50 - name_length)) 110 spaces=`for((i = 1; i <= space_length; i++)); do echo -n ' '; done` 111 failure_report="$failure_report $test_name$spaces$failures\n" 112 fi 113 fi 114 [ -e out.log ] && mv out.log ${xybase}.out.log 115done 116} 117 118 119# Parse command line. 120 121# Some default settings. 122query="no" 123cleanup="yes" 124test_groups="" 125dry_run="no" 126bin_directory="../bin" 127 128# default is yes 129# environment variable can set to no 130if [ "x$SAVETESTDIRS" == "xyes" ]; then 131 cleanup="no"; 132fi 133 134while getopts "hnlg:qwd:b:" opt ; do 135 case "$opt" in 136 h) usage;; 137 n) dry_run="yes";; 138# p) prefix="$OPTARG"; testsuite=$prefix/share/octopus/testsuite;; 139# e) exec_suffix="$OPTARG";; 140 l) local_run="yes";; 141 g) test_groups="$OPTARG";; 142 q) query="yes";; 143 w) serial_opt="-s";; 144 d) directory="$OPTARG";; 145 b) bin_directory="$OPTARG";; 146# c) cleanup="yes";; 147 ?) echo "Error parsing arguments"; exit 1;; 148 esac 149done 150shift $[ OPTIND - 1 ] 151 152 153# Find testfiles. 154if [ -n "$directory" ]; then 155 testsuite="$directory" 156else 157 [ "$local_run" == "yes" ] && testsuite=$(pwd) 158fi 159 160testfiles=`find_tests "$test_groups"` 161 162 163# Query mode? If so, list files and exit. 164if [ "$query" == "yes" ]; then 165 echo "Testfiles for groups $test_groups:" 166 echo "" 167 for f in $testfiles; do 168 echo ${f##$testsuite/} 169 done 170 exit 0 171fi 172 173 174# No testfiles found, abort. 175if [ -z "$testfiles" ]; then 176 echo "No testfiles for group(s) $test_groups found." 177 178# Otherwise, start the whole machinery. 179else 180 # Get epoch seconds at testsuite start. 181 testsuite_start=$(date +%s) 182 183 if [ "$dry_run" == "yes" ]; then 184 opt_n="-n" 185 else 186 opt_n="" 187 fi 188 189 # Run testsuite. 190 run_testsuite "$testfiles" 191 192 # Failure reporting to STDOUT. 193 echo -e " Passed: $passed_tests / $total_tests" 194 echo -e " Skipped: $skipped_tests / $total_tests" 195 if [ $failed_tests -gt 0 ]; then 196 echo " Failed: $failed_tests / $total_tests" 197 echo 198 echo " testfile # failed testcases" 199 echo " --------------------------------------------------------------------" 200 echo -e "$failure_report" 201 else 202 if [ $passed_tests -gt 0 ]; then 203 echo -e "\nEverything seems to be OK" 204 else 205 echo -e "\nAll tests were skipped." 206 # make sure a failure will be reported by the exit status 207 failed_tests=100 208 fi 209 fi 210 echo 211 212 # Clean up. 213 [ "$cleanup" == "yes" ] && rm -f *.log 214 215 # Get epoch seconds after we are done and compute time difference. 216 testsuite_end=$(date +%s) 217 timediff_sec=$[ testsuite_end - testsuite_start ] 218 219 RUNTIME="Total run-time of the testsuite: \ 220 $(printf '%02d:%02d:%02d' $[timediff_sec / 3600] \ 221 $[(timediff_sec % 3600) / 60 ] $[timediff_sec % 60])" 222 223 echo $RUNTIME 224 echo "" 225fi 226 227exit $failed_tests 228 229 230# Local Variables: 231# mode: shell-script 232# coding: utf-8 233# End: 234