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 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # runtests.ksh
  28 #     The file is the control program for uidmapping tests. It does some
  29 #     initial setup common to all testscripts, which includes:
  30 #       1) check server side mapid domain is not null
  31 #       2) mount shared directory
  32 #     Then it reads test script filelist and executes them one by one.
  33 #
  34 
  35 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  36 
  37 trap "cleanup" EXIT
  38 trap "exit 1" HUP INT QUIT PIPE TERM
  39 
  40 NAME=`basename $0`
  41 UIDMAPENV="./uid_proc"
  42 UNINITIATED=6
  43 
  44 # set up initial running environment
  45 if [ ! -f $UIDMAPENV ]; then
  46         echo "$NAME: UIDMAPENV[$UIDMAPENV] not found; test UNINITIATED."
  47         exit $UNINITIATED
  48 fi
  49 . $UIDMAPENV
  50 
  51 # setup
  52 #     the function first checks server side mapid domain and then mounts 
  53 #     shared directory from server
  54 # usage:
  55 #     setup
  56 # return value:
  57 #     0 on success; 1 on error
  58 
  59 function setup
  60 {
  61         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  62 
  63         # NFSmapid domain should be the same in both client and server
  64         # which is set in $TESTROOT/go_setup
  65         Cdomain=$(cat /var/run/nfs4_domain)
  66         Sdomain=$Cdomain
  67         export Sdomain Cdomain 
  68 
  69         # Create mount point directory
  70         mkdir -p "$TESTDIR" 2>$ERRLOG
  71         ckreturn $? "could not make mount point directory." $ERRLOG "ERROR" \
  72            || return 1
  73 
  74         # Mount file system
  75         mountit "$SERVER" "$ROOTDIR" "$TESTDIR" 4 1>$ERRLOG 2>&1
  76         ckreturn $? "could not mount directory." $ERRLOG "ERROR" || return 1
  77 
  78         rm $ERRLOG
  79 }
  80 
  81 # cleanup 
  82 #     the function restores the original environment changed by call of 
  83 #     setup(). It unmounts mounted directory from server.
  84 # usage:
  85 #     cleanup
  86 # return value:
  87 #     (it doesn't matter at all)
  88 
  89 function cleanup
  90 {
  91         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  92 
  93         # Unmount file system if it is mounted
  94         if grep $TESTDIR /etc/mnttab >/dev/null; then
  95                 # Unmount it
  96                 umountit "$TESTDIR" 1>$ERRLOG 2>&1
  97                 ckreturn $? "could not unmount $TESTDIR" $ERRLOG "WARNING"
  98 
  99                 if [ $? -ne 0 ]; then
 100                         # try again to forcibly unmount it
 101                         umount -f "$TESTDIR" 1>$ERRLOG  2>&1
 102                         ckreturn $? "could not unmount $TESTDIR forcibly" \
 103                             $ERRLOG "WARNING"
 104                 fi
 105         fi
 106 
 107         # Remove mount point if file system has been umounted
 108         if ! grep $TESTDIR /etc/mnttab >/dev/null; then
 109                 rm -fr "$TESTDIR" 1>$ERRLOG 2>&1
 110                 ckreturn $? "could not remove $TESTDIR" $ERRLOG "WARNING"
 111         fi
 112 
 113         # remove log file
 114         rm -f $ERRLOG
 115         ckreturn $? "could not remove $ERRLOG" /dev/null "WARNING"
 116 }
 117 
 118 # must run as root
 119 EXEC=""
 120 id | grep "0(root)" > /dev/null 2>&1
 121 if [ $? -ne 0 ]; then
 122         EXEC="/suexec"
 123 fi
 124 
 125 # mount shared directory
 126 setup || exit $UNINITIATED
 127 
 128 # Get lists of TCL and kornshell scripts
 129 TESTLIST=${TESTLIST:-$(egrep -v "^#|^  *$" uidmapping.flist)}
 130 TESTLIST_TCL=""
 131 TESTLIST_SH=""
 132 for t in $TESTLIST
 133 do
 134         grep "^#\!.*bin/ksh" $t > /dev/null 2>&1
 135         if [ $? -ne 0 ]; then
 136                 TESTLIST_TCL="$TESTLIST_TCL $t"
 137         else
 138                 TESTLIST_SH="$TESTLIST_SH $t"
 139         fi
 140 done
 141 
 142 # Start the tests with some information
 143 echo " "
 144 echo "Testing at CLIENT=[`uname -n`] to SERVER=[$SERVER]"
 145 echo "Started UID MAPPING tests at [`date`] ..."
 146 echo " "
 147 
 148 # run TCL scripts
 149 for t in $TESTLIST_TCL
 150 do 
 151         ${EXEC} ${TESTROOT}/nfsh $t
 152         st=$?
 153         if (( (st != PASS) && (st != FAIL) )); then
 154                 echo "\n$t{remaining_tests}: unexpected tests termination"
 155                 echo \
 156                   "\tTest $(rc2str $st): test $t terminated with status $st\n"
 157         fi
 158 done
 159 
 160 # run shell scripts
 161 for t in $TESTLIST_SH
 162 do 
 163         ${EXEC} ./$t
 164         st=$?
 165         if (( (st != PASS) && (st != FAIL) )); then
 166                 echo "\n$t{remaining_tests}: unexpected tests termination"
 167                 echo \
 168                   "\tTest $(rc2str $st): test $t terminated with status $st\n"
 169         fi
 170 done
 171 
 172 echo " "
 173 echo "Testing ends at [`date`]."
 174 echo " "
 175 
 176 exit 0