1 #! /usr/bin/ksh 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 28 #pragma ident "@(#)testbind.ksh 1.1 09/07/12 SMI" 29 30 31 ######################################################################## 32 # setup 33 # 34 # First, set up the environment and make the binaries. Then attempt to 35 # run this shell script again as root with a 'subshell' argument, which 36 # tells us whether or not we're in the subshell. If we are, then the 37 # build part is skipped and root runs the tests and will return 38 # RC_TESTS_WERE_RUN to indicate that the tests were run. 39 # 40 ######################################################################## 41 42 export START_DIR=$PWD 43 export RC_TESTS_WERE_RUN=100 44 45 # if in subshell, skip the make 46 if [[ $1 != 'subshell' ]]; then 47 # user must provide source tree root 48 if [[ -z $SFW_ROOT ]]; then 49 echo "please define SFW_ROOT as the pathname of the workspace" 50 echo " e.g. export SFW_ROOT=/export/sfwnv" 51 exit 1 52 elif [[ ! -d $SFW_ROOT ]]; then 53 print -u2 "Directory defined in SFW_ROOT does not exist!" 54 exit 1 55 fi 56 57 # user must provide a script for bldenv 58 if [[ -z $OPENSOLARIS_SH ]] ; then 59 echo "please define OPENSOLARIS_SH as a path to bldenv script." 60 echo " e.g. export OPENSOLARIS_SH=$SFW_ROOT/opensolaris.sh" 61 exit 1 62 elif [[ ! -f $OPENSOLARIS_SH ]]; then 63 print -u2 "File defined in $OPENSOLARIS_SH does not exist!" 64 exit 1 65 fi 66 67 # check that bldenv is in the path 68 export BLDENV=`which bldenv` 69 if [[ -z $BLDENV ]] ; then 70 echo "please put .../onbld/bin in your path first" 71 exit 1 72 fi 73 74 export BIND_DIR=$SFW_ROOT/usr/src/cmd/bind 75 export PKGDEFS=$SFW_ROOT/usr/src/pkgdefs 76 export SUNWBIND_DIR=$PKGDEFS/SUNWbind 77 export SUNWBINDC_DIR=$PKGDEFS/SUNWbindc 78 79 # Obtain version to be tested 80 if [[ -z $VER ]]; then 81 cd $BIND_DIR 82 TAR_GZ_FILE=`ls *.tar.gz` 83 VER=${TAR_GZ_FILE%.tar.gz} 84 fi 85 86 # make named 87 echo "$BLDENV $OPENSOLARIS_SH 'make -f Makefile.sfw install'" 88 cd $BIND_DIR 89 $BLDENV $OPENSOLARIS_SH 'make -f Makefile.sfw install' 90 if [[ $? != 0 ]] ; then 91 echo "failed to build named" 92 exit 1 93 fi 94 95 # Make the packages, note awk_pkginfo and audit_pkg are pre-req's 96 cd $PKGDEFS 97 $BLDENV $OPENSOLARIS_SH 'make awk_pkginfo audit_pkg' 98 99 cd $PKGDEFS/SUNWbind 100 echo "$BLDENV $OPENSOLARIS_SH 'make pkg'" 101 $BLDENV $OPENSOLARIS_SH 'make pkg' 102 if [[ $? != 0 ]] ; then 103 echo "failed to build SUNWbind" 104 exit 1 105 fi 106 cd $PKGDEFS/SUNWbindc 107 echo "$BLDENV $OPENSOLARIS_SH 'make pkg'" 108 $BLDENV $OPENSOLARIS_SH 'make pkg' 109 if [[ $? != 0 ]] ; then 110 echo "failed to build SUNWbindc" 111 exit 1 112 fi 113 114 # Execute ourselves as root if we are not root already. 115 if [[ $(id) != "uid=0(root)"* ]]; then 116 export BINDDIR VER 117 echo ' 118 Some BIND tests require setting up network interfaces using ifconfig. 119 This requires running as root so enter the root password below. 120 To skip these tests, just hit enter' 121 cd $START_DIR 122 su root -c "$0 subshell" 123 SU_SUCCEEDED=$? 124 fi 125 126 127 fi # subshell check 128 129 130 ######################################################################## 131 # run the tests 132 # 133 # these will either run as root, or as the user who ran this script 134 # initially. If root runs the tests in a subshell, this will be 135 # communicated back to the original shell via a return code of 136 # RC_TESTS_WERE_RUN. 137 # 138 ######################################################################## 139 140 cd ${BIND_DIR}/$VER 141 142 if [[ $SU_SUCCEEDED == $RC_TESTS_WERE_RUN ]] ; then 143 exit 0; 144 else 145 export IFCONFIG_SH_DIR=${BIND_DIR}/$VER/bin/tests/system 146 export IFCONFIG_SH=$IFCONFIG_SH_DIR/ifconfig.sh 147 148 # setup interfaces if we're running as root 149 if [[ $(id) == "uid=0(root)"* ]]; then 150 # ROOT user, run ifconfig to set up tests 151 ( cd $IFCONFIG_SH_DIR ; $IFCONFIG_SH up ) 152 interfaces=1 153 echo "Please check below to make sure the interfaces are correct" 154 ifconfig -a 155 fi 156 157 158 TIMESTAMP=`date +"%Y-%m-%d-%H:%M:%S"` 159 export TEST_RESULTS=${TEST_RESULTS:-$HOME/$TIMESTAMP-bind-test-results} 160 161 cd ${BIND_DIR}/$VER 162 echo "Executing tests as `whoami` in $PWD" 163 164 make test > $TEST_RESULTS 2>&1 165 166 # run ifconfig to tear down tests 167 if [[ -n $interfaces ]]; then 168 ( cd $IFCONFIG_SH_DIR ; $IFCONFIG_SH down ) 169 echo "Please check below to make sure the interfaces are correct" 170 ifconfig -a 171 fi 172 173 # display test results 174 echo "********************************************************************" 175 echo "Test results are in the file:" 176 ( cd `dirname $TEST_RESULTS` ; echo " $PWD/`basename $TEST_RESULTS`" ) 177 echo "Summary: " 178 for result in PASS FAIL UNTESTED ; do 179 echo $result `grep -c ^R:$result $TEST_RESULTS` 180 done 181 # grep ^R: $TEST_RESULTS | sort | uniq 182 echo "********************************************************************" 183 fi 184 185 exit $RC_TESTS_WERE_RUN 186 187