1#! /bin/echo this_file_should_be_sourced,_not_executed 2# -*- Mode: Shell-script -*- 3# 4# defs --- define the environment for autogen tests. 5# 6# Author: Bruce Korb <bkorb@gnu.org> 7# 8## This file is part of AutoOpts, a companion to AutoGen. 9## AutoOpts is free software. 10## AutoOpts is Copyright (C) 1992-2018 by Bruce Korb - all rights reserved 11## 12## AutoOpts is available under any one of two licenses. The license 13## in use must be one of these two and the choice is under the control 14## of the user of the license. 15## 16## The GNU Lesser General Public License, version 3 or later 17## See the files "COPYING.lgplv3" and "COPYING.gplv3" 18## 19## The Modified Berkeley Software Distribution License 20## See the file "COPYING.mbsd" 21## 22## These files have the following sha256 sums: 23## 24## 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 25## 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 26## 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd 27 28# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 29# 30# C O N F I G U R E D V A L U E S 31# 32# Make sure srcdir is an absolute path. Supply the variable 33# if it does not exist. We want to be able to run the tests 34# stand-alone!! 35# 36cfg_vals() 37{ 38 case `uname -s` in 39 SunOS ) 40 if test "X$BASH_VERSION" = X 41 then 42 # On Solaris, make certain we do not use /bin/sh 43 sh=`which bash` 44 test "X$sh" = X && sh=/usr/xpg4/bin/sh 45 BASH_VERSION=not-good-enough 46 export BASH_VERSION 47 exec $sh "$0" "$@" 48 fi 49 ;; 50 esac 51 52 set -a 53 TESTS='' 54 builddir=`pwd` 55 progpid=$$ 56 : ${top_builddir=/u/bkorb/tools/ag/autogen-bld} 57 top_builddir=`cd ${top_builddir} >/dev/null ; pwd` 58 : ${top_srcdir=/u/bkorb/tools/ag/autogen-bld} 59 top_srcdir=`cd ${top_srcdir} >/dev/null ; pwd` 60 : ${srcdir=/u/bkorb/tools/ag/autogen-bld/getdefs/test} 61 srcdir=`cd $srcdir >/dev/null && pwd` 62 . ${top_builddir}/config/shdefs "${builddir}/` 63 echo $0|${SED:-sed} 's@.*/@@'`" 64 progname=`echo "$1" | ${SED} 's,^.*/,,'` 65 testname=`echo "$progname" | ${SED} 's,\..*$,,'` 66 testsubdir=${testname}-testd 67 tstdir=${builddir}/${testsubdir} 68 PS4=">${testname}-\${FUNCNAME}> " 69 test_name=`echo ${testname} | ${SED} 's/-/_/g'` 70 ( exec 2>/dev/null; ulimit -c unlimited ) && \ 71 ulimit -c unlimited 72 73 CFLAGS="${CFLAGS} ${DEFS}" 74 : ${PAGER=more} 75 76 stdopts=${top_srcdir}/autoopts/test/stdopts.def 77 test_main=yes 78 use_flags=true 79 sed_omit_license="/-\*- buffer-read-only:/,/^ \*\//d" 80 TERM='' 81 set +a 82 83 ( 84 test_local() { 85 local local_works=yes 86 } 87 test_local 88 ) || eval 'local() { : ; }' 89 90 vars=`set | ${SED} -n '/^\(LANG\|LC_[A-Z_]*\)=/s/=.*//p'` 2>/dev/null 91 unset AUTOOPTS_USAGE $vars CONTENT_LENGTH REQUEST_METHOD QUERY_STRING 92} 93 94# If only the "rm(1)" command could be relied upon.... 95# 96purge() 97{ 98 rm -rf ${*} 2>/dev/null 99 bad='' 100 for f 101 do test -f ${f} -o -d ${f} && bad="${bad} ${f}" 102 done 103 test -z "$bad" && return 0 104 105 # NFS "busy" files and MS-DOS fs sometimes fail. 106 # 107 set -- $bad 108 test "x${RANDOM}" = "x${RANDOM}" && RANDOM=`expr 0${RANDOM} + 1 2>/dev/null` 109 110 f=zzPURGE-${1}-${RANDOM}-${progpid} 111 if test $# -gt 1 112 then mkdir "${f}" 113 mv $* "${f}/." 114 else mv $1 "${f}" 115 fi 116} 117 118init_tests() 119{ 120 exec 8>&2 121 BASH_XTRACEFD=8 122 123 TMPDIR="${tstdir}/${testname}-tmpd" 124 mkdir -p ${TMPDIR} 125 CFLAGS=`echo ${CFLAGS} | \ 126 ${SED} "s/-Werror[^ ${ht}]*//g;s/-Wextra//g"` 127 128 lo_dir=${top_builddir}/autoopts 129 lo_lib=`find ${lo_dir} -type f -name "*libopts.${OBJEXT}" | head -n1` 130 test -f "$lo_lib" || { 131 lo_lib=`find ${lo_dir} -type f -name "*libopts.lo" | head -n1` 132 test -f "$lo_lib" || die "no libopts lib" 133 } 134 lo_dir=${lo_lib%/*} 135 test "X${LD_LIBRARY_PATH}" = X || \ 136 LD_LIBRARY_PATH=:${LD_LIBRARY_PATH} 137 LD_LIBRARY_PATH=${lo_dir}:${LIBGUILE_PATH}${LD_LIBRARY_PATH} 138 139 case ${AG_VERSION} in 140 *pre* ) GUILE_WARN_DEPRECATED=detailed ;; 141 * ) GUILE_WARN_DEPRECATED=no ;; 142 esac 143 144 case "$LIB" in 145 *-lgen* ) : ;; 146 * ) 147 for f in /usr/lib*/libgen.so /lib*/libgen.so 148 do 149 test -f $f && { 150 LIB="${LIB} -lgen" 151 break 152 } 153 done 154 ;; 155 esac 156 LIB="${lo_lib} ${LIB}" 157 158 AG_L=run_ag\ ao 159 agl_opts="-L${top_builddir}/autoopts/tpl" 160 test "L${top_builddir}" = "L${top_srcdir}" || \ 161 agl_opts="$agl_opts -L${top_srcdir}/autoopts/tpl" 162 export TMPDIR PATH LD_LIBRARY_PATH \ 163 GUILE_WARN_DEPRECATED LIB AG_L agl_opts \ 164 CC LIBGUILE AG_VERSION 165} 166 167be_silent() 168{ 169 setx=: 170 msg=echo 171 VERBOSE=false 172 purge ${testsubdir} 173 174 run_ag() 175 { 176 local opts= 177 opts='' 178 shift 179 180 case " $* " in 181 *' -L'* ) : ;; 182 * ) opts="${agl_opts}" ;; 183 esac 184 185 ${AGexe} ${opts} "$@" 186 } 187 188 init_tests 189} 190 191be_verbose() 192{ 193 set -x 194 setx='set -x' 195 msg=: 196 VERBOSE=true 197 test -d ${testsubdir} || mkdir ${testsubdir} || exit 1 198 199 run_ag() 200 { 201 local opts= tfile=${testname}-aglog-${1}-${progpid}.log 202 ${verb_ok:-true} && { 203 case " $* " in 204 *' --trace'* ) : ;; 205 * ) 206 opts="--trace=every --trace-out=>>${tfile}" 207 ;; 208 esac 209 AUTOGEN_TRACE=every 210 AUTOGEN_TRACE_OUT=">>`pwd`/${tfile}" 211 export AUTOGEN_TRACE_OUT AUTOGEN_TRACE 212 } 213 shift 214 215 case " $* " in 216 *' -L'* ) : ;; 217 * ) opts="${opts} ${agl_opts}" ;; 218 esac 219 220 MALLOC_CHECK_=3 ${AGexe} ${opts} "$@" 221 } 222 223 init_tests 224} 225 226cfg_inc() 227{ 228 test_src=$srcdir/${testname}.test 229 cd ${testsubdir} || { 230 echo "Cannot make or change into ${testsubdir}" 231 exit 1 232 } 233 234 dirs=` 235 for f in ${top_builddir} ${top_srcdir} 236 do 237 for d in . autoopts agen5 238 do 239 cd $f/$d 240 pwd >&9 241 cd - 242 done 9>&1 1>/dev/null 243 done | sort -u | ${SED} 's/^/-I/'` 244 245 INC=`echo ${dirs} ${CPPFLAGS}` 246 247 : "=== Running $progname for ${testname} using ${SHELL} ===" 248 chmod +w * > /dev/null 2>&1 || : 249 ${VERBOSE} && SHELLX="${SHELL} -x" || SHELLX="${SHELL}" 250} 251 252# # # # 253# 254# "clean_help" -- remove variable parts so results can be compared 255# 256nl=' 257' 258ht=' ' 259basic_help_clean="/^Packaged by/d 260/^Report .* bugs to/d 261/[Pp]lease send bug reports/d 262/^exit [0-9]/d 263/^[ ${ht}]*\$/d" 264TR=`command -v tr` 265test -x "$TR" || die "cannot run tests without 'tr' program" 266 267export nl ht basic_help_clean TR 268readonly nl ht basic_help_clean TR 269 270clean_help() { 271 test -z "$sedcmd" && \ 272 s=${basic_help_clean} || \ 273 s="${sedcmd}${nl}${basic_help_clean}" 274 275 ${SED} "${s}" ${1+"$@"} 276} 277 278compile() 279{ 280 ${setx} 281 test "X${Csrc}" = "X" && Csrc="${testname}" 282 test "X${Cexe}" = "X" && Cexe="${Csrc}" 283 test "X${Dnam}" = "X" && Dnam="${testname}" 284 285 d=`echo TEST_TEST_${Dnam}_OPTS | ${TR} '[a-z]-' '[A-Z]_'` 286 cc_cmd="${CC} ${CFLAGS} -D$d ${INC} -o ${Cexe} ${Csrc}.c ${LIB}" 287 eval ${cc_cmd} || \ 288 failure cannot compile ${Csrc}.c 289 if test $# -gt 0 290 then 291 ( set +xe 292 exec 2>&1 293 ./${Cexe} ${*} ${dosed} 294 ) || failure cannot obtain help output for ${Csrc} 295 fi > ${Cexe}.RAW-HELP 296 clean_help ${Cexe}.RAW-HELP > ${Csrc}.help 297 Csrc='' Cexe='' Dnam='' 298} 299 300cleanup() 301{ 302 kill -9 $THUMPER_PID 303 trap '' 15 304 ${setx} 305 ${VERBOSE} || { 306 cd ${builddir} 307 purge ${testsubdir} 308 } 309 ${msg} ${testname} done 310 exit 0 311} 312 313# A standard failure function 314# 315failure() 316{ 317 kill -9 $THUMPER_PID 318 trap '' 15 319 set -x 320 cd ${tstdir}/.. 321 if test -d FAILURES 322 then test -d "FAILURES/${testsubdir}" && \ 323 purge "FAILURES/${testsubdir}" 324 else mkdir FAILURES 325 fi 326 327 mv "${testsubdir}" "FAILURES/${testsubdir}" 328 test -f "${testname}.log" && { 329 mv "${testname}.log" "FAILURES/${testsubdir}/amtest-${testname}.log" 330 ln -s "FAILURES/${testsubdir}/amtest-${testname}.log" "${testname}.log" 331 } 332 echo FAILURE: "$*" 333 exit 1 334} 335 336thumper() 337{ 338 exec > /dev/null 2>&1 </dev/null 339 set +x 340 bdir=`cd "$builddir" >/dev/null ; pwd` 341 cd / 342 rpid=${progpid} 343 test -z "${kill_delay}" && kill_delay=3 344 kill_delay=`expr $kill_delay '*' $AG_TIMEOUT` 345 while test ${kill_delay} -gt 0 346 do sleep 1 347 ps -p ${rpid} || exit 0 348 kill_delay=`expr $kill_delay - 1` 349 done 350 kill -15 ${rpid} 351 sleep 1 352 ps -p ${rpid} || exit 353 test -d "$bdir" && { 354 test -d ${bdir}/FAILURES || \ 355 mkdir ${bdir}/FAILURES 356 mv -f "${tstdir}" "${bdir}/FAILURES/." 357 } 358 kill -9 ${rpid} 359} 360 361# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 362 363cfg_vals $0 364 365case "${VERBOSE}" in 366'' | [Nn]* | 0 | [Ff]* ) 367 be_silent ;; 368 369[Yy]* | [0-9] | [Tt]* ) 370 be_verbose ;; 371 372* ) 373 case "$-" in 374 *x* ) be_verbose ;; 375 * ) be_silent ;; 376 esac 377esac 378 379thumper & 380THUMPER_PID=$! 381cfg_inc 382 383trap "failure 'test ${testname} killed on timeout'" 15 384 385## Local Variables: 386## mode: shell-script 387## indent-tabs-mode: nil 388## sh-indentation: 2 389## sh-basic-offset: 2 390## End: 391 392# defs.in ends here 393