1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # Control script to run all or user specified test suites
  28 #
  29 . $TESTROOT/nfs4test.env
  30 
  31 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  32 
  33 NAME=`basename $0`
  34 DIR=`dirname $0`
  35 
  36 function usage
  37 {
  38         echo "usage: runtests <tests>"
  39         echo "  tests:  -a=all tests listed below"
  40         echo "          -l=acl"
  41         echo "          -b=basic_ops"
  42         echo "          -n=num_attrs"
  43         echo "          -m=named_attrs"
  44         echo "          -o=other_tests"
  45         echo "          -s=srv_namespc"
  46         echo "          -r=recovery"
  47         exit 1
  48 }
  49 
  50 # runtests script requires an arguments to run.
  51 # runtests requires "-a" option to run all tests.
  52 # Or provide the associated option to run
  53 # specific(s) tests. See usage message.
  54 if [ $# -lt 1 ]; then
  55         usage
  56 fi
  57 
  58 # sourcing framework global environment variables created after go_setup
  59 # and for this purpose only this file should be sourced
  60 if [[ ! -f $CONFIGFILE ]]; then
  61         echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
  62         echo "\texit UNINITIATED."
  63         exit 6
  64 fi
  65 . $CONFIGFILE
  66 
  67 # If using runtests script, set TESTDIR to directory
  68 # test framework is installed in for testing purposes.
  69 TESTDIR=`pwd`/../tests
  70 
  71 # This will be expanded to include arguments to select
  72 # new tests developed to test nfsv4
  73 while getopts ablnmosr option
  74 do
  75         case "$option"
  76         in
  77                 a)      dirs="acl basic_ops num_attrs named_attrs \
  78                                 other_tests srv_namespc recovery" ;;
  79                 b)      dirs="$dirs basic_ops"          ;;
  80                 l)      dirs="$dirs acl"                ;;
  81                 n)      dirs="$dirs num_attrs"          ;;
  82                 m)      dirs="$dirs named_attrs"        ;;
  83                 o)      dirs="$dirs other_tests"        ;;
  84                 r)      dirs="$dirs recovery"           ;;
  85                 s)      dirs="$dirs srv_namespc"        ;;
  86                 *)      usage
  87                         exit 1                          ;;
  88         esac
  89 done
  90 
  91 # Set the name of the test driver for all test suites
  92 TDRIVER=`basename $0`
  93 
  94 # This is where we want the logs to go
  95 if [ ! -d ${LOGDIR} ]; then
  96         mkdir -m 777 -p ${LOGDIR} > /dev/null 2>&1
  97         if [ $? -ne 0 ]; then
  98                 echo "WARNING: unable to create $LOGDIR"
  99         fi
 100 fi
 101 
 102 # journal for setup was saved at father dir of LOGDIR
 103 oldjnl=$(dirname $LOGDIR)/$(basename $JOURNAL_SETUP)
 104 if [[ -f $oldjnl && $oldjnl_setup != $JOURNAL_SETUP ]]; then
 105         mv $oldjnl $JOURNAL_SETUP
 106         echo "Journal for setup is at: $JOURNAL_SETUP"
 107 fi
 108 
 109 echo ""
 110 # Start the tests with some information
 111 echo ""
 112 echo "running tests:"
 113 echo "--------------"
 114 echo ""
 115 
 116 # Create a general & summary LOG file for each test suite
 117 function logs
 118 {
 119         echo "  "
 120         echo "SUMMARY LOG :"
 121         echo "  $LOGDIR/${dir}/Summary.log"
 122         echo "Detail journal file is : "
 123         echo "  $LOGDIR/${dir}/journal.${dir}"
 124         echo " "
 125 
 126         cd $LOGDIR/${dir}
 127         # Remove Summary.log file from previous run
 128         rm -rf Summary.log
 129         nawk '
 130 /^[\.\/a-zA-Z0-9\-_\|\+]+{[a-zA-Z0-9\-\+_]+}:[ \t]+/,/^[ \t]+T[eE][sS][tT][ \t]+[A-Z]+$/ {
 131         if ($1 ~ /^[\.\/a-zA-Z0-9\-_\|\+]+{[a-zA-Z0-9\-\+_]+}:/) {
 132                 testname = $1
 133                 sub(":$", "", testname)
 134         }
 135 
 136         if ($0 ~ /^[ \t]+T[eE][sS][tT][ \t]+[A-Z]+/) {
 137                 resname = $2
 138                 sub(":$","",resname)
 139                 testlist[count++] = testname
 140                 results[testname] = resname 
 141                 rescount[resname]++
 142  }
 143 
 144         }
 145         END {
 146         print "\nSummary:"
 147         for (i=0; i < count; i++) {
 148                 testname = testlist[i]
 149                 resname = results[testname]
 150                 print "\t" testname ": " resname
 151         }
 152 
 153                 print "\nResult Total:"
 154                 for (res in rescount) {
 155                         print "\t" res ": " rescount[res]
 156                 }
 157         }' journal.${dir} > Summary.log
 158 
 159         cd $cur_dir
 160 }
 161         
 162 # Keep track of the current directory for cleanup purposes
 163 cur_dir=$TESTDIR
 164 
 165 # run the tests, one by one
 166 for dir in $dirs; do
 167         if [ ! -d "${cur_dir}/${dir}" ]; then
 168                 echo "ERROR: $dirs: no such directory"
 169                 exit 1
 170         fi 
 171 
 172         # first, check to see if test driver there
 173         if [ ! -f ${TESTDIR}/${dir}/${TDRIVER} ]; then
 174                 echo "ERROR: $dir/$TDRIVER not found"
 175                 exit 1
 176         fi
 177 
 178         # create testdir log directory 
 179         if [ ! -d ${LOGDIR}/${dir} ]; then
 180                 mkdir -m 777 -p ${LOGDIR}/${dir} > /dev/null 2>&1
 181                 if [ $? -ne 0 ]; then
 182                         echo "ERROR: unable to create $LOGDIR/${dir}"
 183                         exit 1
 184                 fi
 185         fi
 186 
 187         touch $LOGDIR/${dir}/journal.${dir}
 188         if [ $? -ne 0 ]; then
 189                 # if there's no log, don't bail out, just
 190                 # print an error.  Run the test anyway
 191                 echo "WARNING: could not create log file $LOGDIR/journal.${dir}"
 192         fi
 193 
 194         # run the test
 195         echo "$(date) : <$dir> ..."
 196         cd ${TESTDIR}/${dir}
 197         ./${TDRIVER} > ${LOGDIR}/${dir}/journal.${dir} 2>&1
 198         logs
 199         if [ "0$RUNIT_LOOP" -gt 0 ]; then
 200                 mv ${LOGDIR}/${dir}/journal.${dir} \
 201                         ${LOGDIR}/${dir}/journal.${dir}.${RUNIT_LOOP}
 202                 mv ${LOGDIR}/${dir}/Summary.log \
 203                         ${LOGDIR}/${dir}/Summary.log.${RUNIT_LOOP}
 204         fi
 205 done