#!@KSH@ # $1 = file name # $2 = suffix list separated by white space (e.g. ".c .C .h .y") # returns zero if file name as a suffix in the suffix list, non-zero otherwise. function has_suffix { echo $1 $2 for id in $2 ; do echo $id one=$(basename "$1" ${id})${id} two=$(basename "$1") if [[ "$one" = "$two" ]] ; then return 0 fi done return 1 } # unique subdirectory ID for the Work dir dirid=0 # $1 = traverse directory # $2 = command to execute # $3 = file that is skip list # $4 = list of suffixes for test files # $5 = log file # $6 = current suite function visit_dir { ANY_FAILED=0 echo "Entering $1" echo "Entering $1" >> $5 2>&1 for file1 in "$1"/* ; do curr_file="${file1}" bare_file=$(\basename "${curr_file}") canonical_file="$6/$bare_file" if [[ -x "${curr_file}" && -d "${curr_file}" ]] ; then visit_dir "${curr_file}" "$2" "$3" "$4" "$5" "$canonical_file" rc=$? if [[ "${rc}" = "1" ]] ; then ANY_FAILED=1 fi elif has_suffix "${curr_file}" "$4" > /dev/null 2>&1 ; then echo "${curr_file}: Starting ..." >> $5 2>&1 if [[ -r "${curr_file}" ]] ; then bare_file_noext="${bare_file}" for id in $4 ; do bare_file_noext=$(\basename "${bare_file_noext}" ${id}) done canonical_file_noext="$6/$bare_file_noext" #echo canonical_file=${canonical_file} #echo canonical_file_noext=${canonical_file_noext} #echo bare_file=${bare_file} #echo bare_file_noext=${bare_file_noext} if [[ -z "${TESTS}" && \ ( -n $(grep "^${canonical_file}\$" $3 2> /dev/null) || \ -n $(grep "^\*/${bare_file}\$" $3 2> /dev/null) ) ]] ; then echo "${canonical_file}: Skipped" echo "${canonical_file}: Skipped" >> $5 2>&1 elif [[ -n "${TESTS}" && \ $(echo " ${TESTS} " | grep " ${canonical_file} " 2> /dev/null) = "" && \ $(echo " ${TESTS} " | grep " ${bare_file} " 2> /dev/null) = "" && \ $(echo " ${TESTS} " | grep " ${canonical_file_noext} " 2> /dev/null) = "" && \ $(echo " ${TESTS} " | grep " ${bare_file_noext} " 2> /dev/null) = "" \ ]] ; then echo "${canonical_file}: Skipped" echo "${canonical_file}: Skipped" >> $5 2>&1 else dirid=$(($dirid+1)) # fails with non-Gnu awk #QUSER=`echo $USER | awk '{ gsub("[^a-zA-Z0-9_-]","_"); print; }'` QUSER=`echo $USER | sed 's/[^a-zA-Z0-9_-]/_/g'` rm -rf Work.$QUSER.$$.$dirid > /dev/null 2>&1 || exit 250 mkdir Work.$QUSER.$$.$dirid > /dev/null 2>&1 || exit 251 SAVED_DIR=`pwd` cd Work.$QUSER.$$.$dirid > /dev/null 2>&1 || exit 252 echo "${canonical_file}: Working Directory is: `pwd`" >> $5 2>&1 $2 "${canonical_file}" >> $5 2>&1 # $2 "${curr_file}" > /dev/null 2>&1 rc=$? cd ${SAVED_DIR} > /dev/null 2>&1 || exit 253 #rm -rf Work.$QUSER.$$.$dirid > /dev/null 2>&1 || exit 254 if [[ "${rc}" = "0" ]] ; then echo "${canonical_file}: PASSED" echo "${canonical_file}: PASSED" >> $5 2>&1 rm -rf Work.$QUSER.$$.$dirid > /dev/null 2>&1 || exit 254 else echo "${canonical_file}: FAILED (${rc}) " echo "${canonical_file}: FAILED (${rc}) " >> $5 2>&1 ANY_FAILED=1 fi fi else echo "${curr_file}: Unreadable" echo "${curr_file}: Unreadable" >> $5 2>&1 fi fi done echo "Leaving $1" echo "Leaving $1" >> $5 2>&1 return ${ANY_FAILED} } # Command line if [[ "$#" != "2" ]] ; then echo "$0: (Syntax Error) Usage: $0 suite logfile" exit 1 fi # Setup variables #: ${TS_HOME_DIRECTORY:=$srcdir} ; export TS_HOME_DIRECTORY : ${TS_HOME_DIRECTORY:=`cd $srcdir;pwd`} ; export TS_HOME_DIRECTORY : ${TS_BUILD_DIRECTORY:=`pwd`} ; export TS_BUILD_DIRECTORY # Setup suite environment if [[ -a "$1.suite" && -r "$1.suite" ]] ; then # provide some reasonable defaults # prevent non-deterministic output from the backend : ${TI_BACKEND_SILENT="1"} ; export TI_BACKEND_SILENT : ${TS_COMMAND:="${TS_BUILD_DIRECTORY}/bin/stdout_err_tester"} ; export TS_COMMAND : ${TS_SKIPLIST:="${TS_HOME_DIRECTORY}/common.skip"} ; export TS_SKIPLIST : ${TS_SUFFIXES:=".ti .java"} ; export TS_SUFFIXES : ${SS_COMPILER:="${TS_BUILD_DIRECTORY}/../../tcbuild/tcbuild"} ; export SS_COMPILER : ${SS_COMPILER_FLAGS:=""} ; export SS_COMPILER_FLAGS : ${SS_NORMALIZER:="${TS_BUILD_DIRECTORY}/bin/stdout_err_norm"} ; export SS_NORMALIZER : ${SS_TCRUN="${TS_BUILD_DIRECTORY}/../../tcbuild/tcrun -n 1"} ; export SS_TCRUN : ${TI_THREADS:="1"} ; export TI_THREADS : ${SS_DEFAULT_COMPILER_FLAGS:="-O --verbose --backend sequential"} ; export SS_DEFAULT_COMPILER_FLAGS # The suite file must at least set the following: # TS_COMMAND Command to run for each test # TS_SKIPLIST File that is the skip list # TS_SUFFIXES List of file suffixes of test files . "$1.suite" else echo "$0: (Error) Cannot find/read the suite descriptor \"$1.suite\"." exit 1 fi if [[ ! -d "$1" || ! -x "$1" ]] ; then echo "$0: (Error) Cannot find/read the directory \"$1\"." exit 1 fi # Check that the proper variables were set by the suite file if [[ -z "${TS_COMMAND}" || -z "${TS_SKIPLIST}" || -z "${TS_SUFFIXES}" ]] ; then echo "$0: (Error) Variables not correctly setup by suite descriptor \"$1.suite\"." exit 1 fi # Log file echo "Log file is: $2" > $2 # Test suite visit_dir "$1" "${TS_COMMAND}" "${TS_SKIPLIST}" "${TS_SUFFIXES}" "$2" "`basename \"$1\"`" # Analyze results rc=$? if [[ "${rc}" != "0" ]] ; then echo "$0: (Warning) at least one test failed." fi # Done exit ${rc}