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 # runit: Executes go_setup, runtests control script
  28 # to run the tests, and go_cleanup scripts.
  29 #
  30 
  31 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  32 
  33 NAME=`basename $0`
  34 DIR=`dirname $0`
  35 
  36 function usage {
  37 echo "usage: runit <test subdir> [-t loop-time, default=1]" 
  38 echo "          -a=all tests listed below"
  39 echo "          -t=number of times to loop the tests, except '-r'"
  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 "          -r=recovery"
  46 echo "          -s=srv_namespc"
  47 exit 1
  48 }
  49 
  50 # Execute the tests; LOOPIT is set to run
  51 # once by default. To modify number of times  
  52 # to loop tests, user must specify using
  53 # "-t <# to loop tests>" option in runit.
  54 LOOPIT=1
  55 ARGS=""
  56 while getopts "ablnmorst:" options
  57 do
  58         case $options in
  59                 a) ARGS="$ARGS -a";;
  60                 b) ARGS="$ARGS -b";;
  61                 l) ARGS="$ARGS -l";;
  62                 n) ARGS="$ARGS -n";;
  63                 m) ARGS="$ARGS -m";;
  64                 o) ARGS="$ARGS -o";;
  65                 r) ARGS="$ARGS -r";;
  66                 s) ARGS="$ARGS -s";;
  67                 t) LOOPIT=$OPTARG;;
  68                 *) usage;;
  69         esac
  70 done
  71 shift `expr $OPTIND - 1`
  72 
  73 [ $# -eq 0 ] && [ -z "$ARGS" ] && usage
  74 
  75 recovery=0
  76 # run all options?
  77 res=`echo $ARGS | grep 'a' 2>&1`
  78 if [ $? -eq 0 ]; then
  79         recovery=1
  80         # NOTE, these "blnmos" are the current options different from recovery
  81         #       this list need to be updated if any other option is added
  82         #       or if any option letter is changed
  83         ARGS="-blnmos"
  84 fi
  85 
  86 # run recovery tests independently from the rest 
  87 res=`echo $ARGS | grep 'r' 2>&1`
  88 if [ $? -eq 0 ]; then
  89         recovery=1
  90         ARGS=`echo $ARGS | sed 's/-r//g'`
  91 fi
  92 
  93 #Sourcing framework Global environment variables
  94 ENVFILE="./nfs4test.env"
  95 if [ ! -f $ENVFILE ]; then
  96         echo "$NAME: ENVFILE[$ENVFILE] not found;"
  97         echo "\texit UNINITIATED."
  98         exit 6 
  99 fi
 100 . $ENVFILE
 101 
 102 # This is where we want the logs to go
 103 if [ ! -d ${LOGDIR} ]; then
 104         mkdir -m 777 -p $LOGDIR > /dev/null 2>&1
 105         if (( $? != 0 )); then
 106                 echo "WARNING: unable to create $LOGDIR"
 107                 exit 6
 108         fi
 109 fi
 110 
 111 # Go setup the server with exported filesystem and 
 112 # files/directories for testing purposes.
 113 JOURNAL_SETUP=$LOGDIR/journal.setup
 114 JOURNAL_CLEANUP=$LOGDIR/journal.cleanup
 115 echo "Setting up test systems CLIENT<$(uname -n)> & SERVER<$SERVER>," 
 116 echo "\tit could take a few minutes..." 
 117 > $JOURNAL_SETUP
 118 su root -c "./go_setup" >> $JOURNAL_SETUP 2>&1
 119 if [ $? -ne 0 ]; then
 120         cat $JOURNAL_SETUP
 121         echo "ERROR: go_setup failed to setup systems"
 122         echo "\ttrying to cleanup the partial setup" 
 123         > $JOURNAL_CLEANUP
 124         su root -c "./go_cleanup" >> $JOURNAL_CLEANUP 2>&1
 125         [ -n "$DEBUG" ] && [ "$DEBUG" = "1" ] && \ 
 126                 cat $JOURNAL_CLEANUP
 127         exit 1
 128 fi
 129 cat $JOURNAL_SETUP
 130 
 131 LOOPF=0
 132 # Execute any requested tests other than recovery
 133 if [ $LOOPIT -gt 1 ]; then
 134         [ "$recovery" = "1" ] && echo \
 135             "Recovery tests will be executed only once, the rest $LOOPIT times"
 136         LOOPF=1
 137 fi
 138 
 139 if [ -n "$ARGS" ];then 
 140         i=1
 141         while : 
 142         do
 143                 echo Runtests pass $i
 144                 [ "$LOOPF" -eq 1 ] && export RUNIT_LOOP=$i
 145                 ./runtests $ARGS "$@"
 146                 if [ $i -eq $LOOPIT ]; then
 147                         break;
 148                 fi
 149                 i=`expr $i + 1`
 150         done
 151 fi
 152 
 153 [ "$recovery" = "1" ] && ./runtests -r "$@"
 154 
 155 # sourcing framework global environment variables created after go_setup
 156 # and for this purpose only this file should be sourced
 157 if [[ ! -f $CONFIGFILE ]]; then
 158         echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
 159         echo "\texit UNINITIATED."
 160         exit 6
 161 fi
 162 . $CONFIGFILE
 163 
 164 # Go cleanup server files/directories, and unshare $BASEDIR
 165 # If NOCLEANUP is set to non-zero, DONNOT run go_cleanup
 166 if [ -z "$NOCLEANUP" -o "$NOCLEANUP" = "0" ]; then
 167         echo "Journal for cleanup is at: $JOURNAL_CLEANUP"
 168         > $JOURNAL_CLEANUP
 169         su root -c "./go_cleanup" >> $JOURNAL_CLEANUP 2>&1
 170         if [ $? -ne 0 ]; then
 171                 echo "ERROR: go_cleanup failed to cleanup $SERVER"
 172                 cat $JOURNAL_CLEANUP
 173                 exit 1
 174         fi
 175         cat $JOURNAL_CLEANUP
 176 fi