#! /usr/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#pragma ident "@(#)testbind.ksh 1.1 09/07/12 SMI"
########################################################################
# setup
#
# First, set up the environment and make the binaries. Then attempt to
# run this shell script again as root with a 'subshell' argument, which
# tells us whether or not we're in the subshell. If we are, then the
# build part is skipped and root runs the tests and will return
# RC_TESTS_WERE_RUN to indicate that the tests were run.
#
########################################################################
export START_DIR=$PWD
export RC_TESTS_WERE_RUN=100
# if in subshell, skip the make
if [[ $1 != 'subshell' ]]; then
# user must provide source tree root
if [[ -z $SFW_ROOT ]]; then
echo "please define SFW_ROOT as the pathname of the workspace"
echo " e.g. export SFW_ROOT=/export/sfwnv"
exit 1
elif [[ ! -d $SFW_ROOT ]]; then
print -u2 "Directory defined in SFW_ROOT does not exist!"
exit 1
fi
# user must provide a script for bldenv
if [[ -z $OPENSOLARIS_SH ]] ; then
echo "please define OPENSOLARIS_SH as a path to bldenv script."
echo " e.g. export OPENSOLARIS_SH=$SFW_ROOT/opensolaris.sh"
exit 1
elif [[ ! -f $OPENSOLARIS_SH ]]; then
print -u2 "File defined in $OPENSOLARIS_SH does not exist!"
exit 1
fi
# check that bldenv is in the path
export BLDENV=`which bldenv`
if [[ -z $BLDENV ]] ; then
echo "please put .../onbld/bin in your path first"
exit 1
fi
export BIND_DIR=$SFW_ROOT/usr/src/cmd/bind
export PKGDEFS=$SFW_ROOT/usr/src/pkgdefs
export SUNWBIND_DIR=$PKGDEFS/SUNWbind
export SUNWBINDC_DIR=$PKGDEFS/SUNWbindc
# Obtain version to be tested
if [[ -z $VER ]]; then
cd $BIND_DIR
TAR_GZ_FILE=`ls *.tar.gz`
VER=${TAR_GZ_FILE%.tar.gz}
fi
# make named
echo "$BLDENV $OPENSOLARIS_SH 'make -f Makefile.sfw install'"
cd $BIND_DIR
$BLDENV $OPENSOLARIS_SH 'make -f Makefile.sfw install'
if [[ $? != 0 ]] ; then
echo "failed to build named"
exit 1
fi
# Make the packages, note awk_pkginfo and audit_pkg are pre-req's
cd $PKGDEFS
$BLDENV $OPENSOLARIS_SH 'make awk_pkginfo audit_pkg'
cd $PKGDEFS/SUNWbind
echo "$BLDENV $OPENSOLARIS_SH 'make pkg'"
$BLDENV $OPENSOLARIS_SH 'make pkg'
if [[ $? != 0 ]] ; then
echo "failed to build SUNWbind"
exit 1
fi
cd $PKGDEFS/SUNWbindc
echo "$BLDENV $OPENSOLARIS_SH 'make pkg'"
$BLDENV $OPENSOLARIS_SH 'make pkg'
if [[ $? != 0 ]] ; then
echo "failed to build SUNWbindc"
exit 1
fi
# Execute ourselves as root if we are not root already.
if [[ $(id) != "uid=0(root)"* ]]; then
export BINDDIR VER
echo '
Some BIND tests require setting up network interfaces using ifconfig.
This requires running as root so enter the root password below.
To skip these tests, just hit enter'
cd $START_DIR
su root -c "$0 subshell"
SU_SUCCEEDED=$?
fi
fi # subshell check
########################################################################
# run the tests
#
# these will either run as root, or as the user who ran this script
# initially. If root runs the tests in a subshell, this will be
# communicated back to the original shell via a return code of
# RC_TESTS_WERE_RUN.
#
########################################################################
cd ${BIND_DIR}/$VER
if [[ $SU_SUCCEEDED == $RC_TESTS_WERE_RUN ]] ; then
exit 0;
else
export IFCONFIG_SH_DIR=${BIND_DIR}/$VER/bin/tests/system
export IFCONFIG_SH=$IFCONFIG_SH_DIR/ifconfig.sh
# setup interfaces if we're running as root
if [[ $(id) == "uid=0(root)"* ]]; then
# ROOT user, run ifconfig to set up tests
( cd $IFCONFIG_SH_DIR ; $IFCONFIG_SH up )
interfaces=1
echo "Please check below to make sure the interfaces are correct"
ifconfig -a
fi
TIMESTAMP=`date +"%Y-%m-%d-%H:%M:%S"`
export TEST_RESULTS=${TEST_RESULTS:-$HOME/$TIMESTAMP-bind-test-results}
cd ${BIND_DIR}/$VER
echo "Executing tests as `whoami` in $PWD"
make test > $TEST_RESULTS 2>&1
# run ifconfig to tear down tests
if [[ -n $interfaces ]]; then
( cd $IFCONFIG_SH_DIR ; $IFCONFIG_SH down )
echo "Please check below to make sure the interfaces are correct"
ifconfig -a
fi
# display test results
echo "********************************************************************"
echo "Test results are in the file:"
( cd `dirname $TEST_RESULTS` ; echo " $PWD/`basename $TEST_RESULTS`" )
echo "Summary: "
for result in PASS FAIL UNTESTED ; do
echo $result `grep -c ^R:$result $TEST_RESULTS`
done
# grep ^R: $TEST_RESULTS | sort | uniq
echo "********************************************************************"
fi
exit $RC_TESTS_WERE_RUN