run-tests.sh 11.4 KB
Newer Older
Daniel Barlow's avatar
Daniel Barlow committed
1 2
#!/bin/sh

3
# do_tests {lisp invocation} {scripts-regex}
4 5 6 7
# - read lisp forms one at a time from standard input
# - quit with exit status 0 on getting eof
# - quit with exit status >0 if an unhandled error occurs

8 9 10 11 12 13
usage () {
    echo "$0 [lisp invocation] [scripts-regex]"
    echo " - read lisp forms one at a time from matching scripts"
    echo " - quit with exit status 0 on getting eof"
    echo " - quit with exit status >0 if an unhandled error occurs"
    echo " you need to supply the .script in the second argument"
14
    echo " lisps include abcl, allegro, allegromodern, ccl (clozure),"
15
    echo "  clisp, cmucl, ecl, gcl, gclcvs, sbcl, scl and xcl."
16 17
    echo "OPTIONS:"
    echo "    -d -- debug mode"
18 19
    echo "    -h -- show this message."
    echo "    -u -- upgrade tests."
20 21
}

22
unset DEBUG_ASDF_TEST upgrade clean_load
Robert P. Goldman's avatar
 
Robert P. Goldman committed
23

24
while getopts "duhc" OPTION
Robert P. Goldman's avatar
 
Robert P. Goldman committed
25
do
26
    case $OPTION in
Robert P. Goldman's avatar
 
Robert P. Goldman committed
27
        d)
28
            export DEBUG_ASDF_TEST=t
Robert P. Goldman's avatar
 
Robert P. Goldman committed
29 30
            ;;
        u)
31
            upgrade=t
Robert P. Goldman's avatar
 
Robert P. Goldman committed
32
            ;;
33 34 35
        c)
            clean_load=t
            ;;
Robert P. Goldman's avatar
 
Robert P. Goldman committed
36 37 38 39 40 41 42
        h)
            usage
            exit 1
            ;;
    esac
done
shift $(($OPTIND - 1))
43

44
if [ x"$1" = "xhelp" ]; then
Robert P. Goldman's avatar
 
Robert P. Goldman committed
45 46
    usage
    exit 1
47
fi
48
lisp=${1:-sbcl} ; shift
49

50

51 52 53 54 55 56 57 58 59 60 61 62 63
ECHO () { printf '%s\n' "$*" ;}
ECHOn () { printf '%s' "$*" ;}
DBG () { ECHO "$*" >& 2 ;}
simple_term_p () {
  case "$1" in *[!a-zA-Z0-9-+_,.:=%/]*) return 1 ;; *) return 0 ;; esac
}
kwote0 () { ECHOn "$1" | sed -e "s/\([\\\\\"\$\`]\)/\\\\\\1/g" ;}
kwote1 () { if simple_term_p "$1" ; then ECHOn "$1"
  else ECHOn "\"$(kwote0 "$1")\"" ; fi ;}
kwote () { ( set +x
  k="" ; for i ; do ECHOn "$k" ; kwote1 "$i" ; k=" " ; done ; echo
) }
DO () { kwote "$@" ; "$@" ; }
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
64

65
do_tests() {
66 67 68 69 70
  if [ -z "$*" ]; then
       scripts="*.script"
  else
       scripts="$*"
  fi
71
  env | grep -i asdf
72
  rm -f ~/.cache/common-lisp/"`pwd`"/* || true
73
  ( cd .. && DO $cmd $debugp $eval '(or #.(load "test/script-support.lisp") #.(asdf-test::compile-asdf-script))' )
74 75
  if [ $? -ne 0 ] ; then
    echo "Compilation FAILED" >&2
76 77 78 79 80 81
    echo "you can retry compilation with:" >&2
    echo ./test/run-tests.sh $lisp >&2
    echo "or more interactively (and maybe with rlwrap or in emacs), start with:" >&2
    echo "$cmd" >&2
    echo "then copy/paste:" >&2
    echo '(load "test/script-support.lisp") (asdf-test::compile-asdf-script)' >&2
82 83
  else
    echo "Compiled OK" >&2
84 85 86 87
    test_count=0
    test_pass=0
    test_fail=0
    failed_list=""
88 89
    for i in $scripts ;
    do
90 91
      echo "Testing: $i" >&2
      test_count=`expr "$test_count" + 1`
92
      rm -f ~/.cache/common-lisp/"`pwd`"/* || true
93
      if DO $cmd $debugp $eval "(load \"script-support.lisp\")" $eval "(asdf-test::with-test () (load \"$i\"))" ; then
94
        echo "Using $command, $i passed" >&2
95 96
	test_pass=`expr "$test_pass" + 1`
      else
97
        echo "Using $command, $i failed" >&2
98 99
	test_fail=`expr "$test_fail" + 1`
	failed_list="$failed_list $i"
100 101 102 103 104 105
        echo "you can retry compilation with:" >&2
        echo ./test/run-tests.sh $lisp $i >&2
        echo "or more interactively (and maybe with rlwrap or in emacs), start with:" >&2
        echo "(cd test ; $cmd )" >&2
        echo "then copy/paste:" >&2
        echo "'(#.(load \"script-support.lisp\") #.(asdf-test::da) #.(asdf-test::with-test () (load \"$i\")))" >&2
106
      fi
107 108
      echo >&2
      echo >&2
109 110
    done
    echo >&2
Gary King's avatar
Gary King committed
111
    echo "-#---------------------------------------" >&2
112
    echo "Using $command" >&2
113 114 115 116
    echo "Ran $test_count tests: " >&2
    echo "  $test_pass passing and $test_fail failing" >&2
    if [ $test_fail -eq 0 ] ; then
	echo "all tests apparently successful" >&2
117
        echo success > ../build/results/status
118 119 120
    else
	echo "failing test(s): $failed_list" >&2
    fi
Gary King's avatar
Gary King committed
121
    echo "-#---------------------------------------" >&2
122
    echo >&2
123
  fi
124 125
}

126
# terminate on error
127 128
set -e

129
command= flags= nodebug= eval=
130
case "$lisp" in
131 132
  abcl)
    command="${ABCL:-abcl}"
133
    flags="--noinit --nosystem --noinform"
134
    eval="--eval" ;;
135
  allegro)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
136
    command="${ALLEGRO:-alisp}"
137
    #flags="-q"
138 139
    nodebug="-batch"
    eval="-e" ;;
140
  allegromodern)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
141
    command="${ALLEGROMODERN:-mlisp}"
142 143 144
    flags="-q"
    nodebug="-batch"
    eval="-e" ;;
145
  ccl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
146
    command="${CCL:-ccl}"
147 148 149
    flags="--no-init --quiet"
    nodebug="--batch"
    eval="--eval" ;;
150 151
  clisp)
    command="${CLISP:-clisp}"
152
    flags="-norc --silent -ansi -I "
153 154
    nodebug="-on-error exit"
    eval="-x" ;;
155
  cmucl)
156 157 158
    # cmucl likes to have its executable called lisp, but so does scl
    # Please use a symlink or an exec ... "$@" trampoline script.
    command="${CMUCL:-cmucl}"
159 160 161
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
162
  ecl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
163
    command="${ECL:-ecl}"
164 165
    flags="-norc -load sys:cmp"
    eval="-eval" ;;
166
  ecl_bytecodes)
167 168
    command="${ECL:-ecl}"
    flags="-norc -eval (ext::install-bytecodes-compiler)"
169
    eval="-eval" ;;
170 171 172 173 174
  gcl)
    export GCL_ANSI=t
    command="${GCL:-gcl}"
    flags="-batch"
    eval="-eval" ;;
175 176
  gclcvs)
    export GCL_ANSI=t
177
    command="${GCLCVS:-gclcvs}"
178 179
    flags="-batch"
    eval="-eval" ;;
180
  lispworks)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
181
    command="${LISPWORKS:-lispworks}"
182 183 184 185
    # If you have a licensed copy of lispworks,
    # you can obtain the "lispworks" binary with, e.g.
    # echo '(hcl:save-image "/lispworks" :environment nil)' > /tmp/build.lisp ;
    # ./lispworks-6-0-0-x86-linux -siteinit - -init - -build /tmp/build.lisp
186 187
    flags="-siteinit - -init -"
    eval="-eval" ;;
188 189 190 191
  mkcl)
    command="${MKCL:-mkcl}"
    flags="-norc"
    eval="-eval" ;;
192 193
  sbcl)
    command="${SBCL:-sbcl}"
194
    flags="--noinform --userinit /dev/null --sysinit /dev/null" # --eval (require'asdf)
195
    nodebug="--disable-debugger"
196
    eval="--eval" ;;
197 198 199 200 201
  scl)
    command="${SCL:-scl}"
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
202 203 204 205
  xcl)
    command="${XCL:-xcl}"
    flags="--no-userinit --no-siteinit"
    eval="--eval" ;;
206 207 208 209
  *)
    echo "Unsupported lisp: $1" >&2
    echo "Please add support to run-tests.sh" >&2
    exit 42 ;;
210
esac
211

212
if ! type "$command" > /dev/null ; then
213
    echo "lisp implementation not found: $command" >&2
214 215 216
    exit 43
fi

217
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
218 219

## Make sure testing remains within the confines of this filesystem tree
220
export CL_SOURCE_REGISTRY="${ASDFDIR}"
221
export ASDF_OUTPUT_TRANSLATIONS="(:output-translations (\"${ASDFDIR}\" (\"${ASDFDIR}/build/fasls\" :implementation)) :ignore-inherited-configuration)"
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
222

223
cmd="$command $flags"
224
debugp=
225
if [ -z "${DEBUG_ASDF_TEST}" ] ; then
226
  debugp="$nodebug"
227 228
fi

Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
229

230
create_config () {
231
    mkdir -p ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
232
}
233
upgrade_tags () {
234 235
    if [ -n "$ASDF_UPGRADE_TEST_TAGS" ] ; then
        echo $ASDF_UPGRADE_TEST_TAGS ; return
236
    fi
237
    # REQUIRE is a magic tag meaning whatever your implementation provides
238 239 240 241
    # 1.37 is the last release by Daniel Barlow
    # 1.97 is the last release before Gary King takes over
    # 1.369 is the last release by Gary King
    # 2.000 to 2.019 and 2.20 to 2.27 and beyond are Faré's "stable" releases
242 243
    # 2.26.61 is the last single-package ASDF.
    echo REQUIRE 1.37 1.97 1.369 2.26.61
244 245 246
    git tag -l '2.0??'
    git tag -l '2.??'
}
247
upgrade_methods () {
248 249
    if [ -n "$ASDF_UPGRADE_TEST_METHODS" ] ; then
        echo $ASDF_UPGRADE_TEST_METHODS ; return
250 251 252 253 254 255 256 257
    fi
    cat <<EOF
'load-asdf-lisp'load-asdf-system
'load-asdf-lisp'compile-load-asdf
'load-asdf-lisp'load-asdf-fasl
()'load-asdf-fasl
EOF
}
258 259
extract_tagged_asdf () {
    ver=$1
260
    if [ REQUIRE = "$ver" ] ; then return 0 ; fi
261 262 263
    file=build/asdf-${tag}.lisp ;
    if [ ! -f $file ] ; then
        case $ver in
264
            1.*|2.0*|2.2[0-6]|2.26.61)
265 266 267 268 269 270 271 272
                git show ${tag}:asdf.lisp > $file ;;
            *)
                echo "Don't know how to extract asdf.lisp for version $tag"
                exit 55
                ;;
        esac
    fi
}
273 274 275 276 277 278 279 280 281 282
valid_upgrade_test_p () {
    case "${1}:${2}:${3}" in
        abcl:2.0[01][1-9]:*|abcl:2.2[1-2]:*)
            : Skip, because it is so damn slow ;;
        ccl:1.*|ccl:2.0[01]*)
            : Skip, because ccl broke old asdf ;;
        clisp:1.??*|clisp:2.00[0-7]:*)
            # my old ubuntu clisp 2.44.1 is wired in with an antique ASDF 1 from CLC that can't be downgraded.
            # 2.00[0-7] use UID, which fails on that CLISP and was removed afterwards.
            # Note that for the longest time, CLISP has included 2.011 in its distribution.
283
            : ;;
284 285 286 287 288 289 290 291 292 293 294 295
        cmucl:1.*|cmucl:2.00*|cmucl:2.01[0-4]:*)
            : Skip, CMUCL has problems before 2.014.7 due to source-registry upgrade ;;
        ecl*:1.*|ecl*:2.0[01]*|ecl*:2.20:*)
            : Skip, because of various ASDF issues ;;
        gcl:1.*|gcl:2.0*|gcl:2.2[0-6]*) : Skip old versions that do not support GCL 2.6 ;;
        mkcl:1.*|mkcl:2.0[01]*|mkcl:2.2[0-3]:*)
            : Skip, because MKCL is only supported starting with 2.24 ;;
        xcl:1.*|xcl:2.00*|xcl:2.01[0-4]:*|xcl:*)
            : XCL support starts with ASDF 2.014.2 - It also hangs badly during upgrade. ;;
        *) return 0 ;;
   esac
   return 1
296
}
297
run_upgrade_tests () {
298
    cd ${ASDFDIR}
299 300
    su=test/script-support.lisp
    for tag in `upgrade_tags` ; do
301 302 303 304
        for method in `upgrade_methods` ; do
            if valid_upgrade_test_p $lisp $tag $method ; then
                echo "Testing ASDF upgrade from ${tag} using method $method"
                extract_tagged_asdf $tag
305
                $cmd $debugp $eval \
306
                "'(#.(load\"$su\")#.(in-package :asdf-test)#.(test-upgrade $method \"$tag\"))" ||
307 308 309
                { echo "upgrade FAILED for $lisp from $tag using method $method" ;
                  echo "you can retry just that test with:" ;
                  echo ASDF_UPGRADE_TEST_TAGS=\"$tag\" ADSF_UPGRADE_TEST_METHODS=\"$method\" ./test/run-tests.sh -u $lisp ;
310
                  echo "or more interactively (and maybe with rlwrap or in emacs), start with:"
311
                  echo "$cmd"
312 313 314
                  echo "then copy/paste:"
                  echo "(load\"$su\") (da) (test-upgrade $method \"$tag\")"
                  exit 1 ;}
315
    fi ; done ; done 2>&1 | tee build/results/${lisp}-upgrade.text
316 317
}
run_tests () {
318
  cd ${ASDFDIR}/test
319 320 321 322
  create_config
  mkdir -p ../build/results
  echo failure > ../build/results/status
    thedate=`date "+%Y-%m-%d"`
323
    do_tests "$@" 2>&1 | \
324 325 326
	tee "../build/results/${lisp}.text" "../build/results/${lisp}-${thedate}.save"
    read a < ../build/results/status
  clean_up
327 328 329 330 331 332 333
  if [ success = "$a" ] ; then ## exit code
      return 0
  else
     echo "To view full results and failures, try the following command:" >&2
     echo "     less -p ABORTED build/results/${lisp}.text" >&2
     return 1
  fi
334
}
335
clean_up () {
336
    rm -rf ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
337
}
338
test_clean_load () {
339
    case $lisp in
340
        gcl|cmucl) return 0 ;; # These are hopeless
341
    esac
342 343
    nop=build/results/${lisp}-nop.text
    load=build/results/${lisp}-load.text
344
    ${cmd} ${eval} \
345 346
      '(or #.(setf *load-verbose* nil) #.(load "test/script-support.lisp") #.(asdf-test::exit-lisp 0))' \
        > $nop 2>&1
347
    ${cmd} ${eval} \
348 349 350 351 352 353 354 355
      '(or #.(setf *load-verbose* nil) #.(load "build/asdf.lisp") #.(asdf/image:quit 0))' \
        > $load 2>&1
    if diff $nop $load ; then
      echo "GOOD: Loading ASDF on $lisp produces no message" >&2 ; return 0
    else
      echo "BAD: Loading ASDF on $lisp produces messages" >&2 ; return 1
    fi
}
356

357
if [ -z "$cmd" ] ; then
Gary King's avatar
Gary King committed
358
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
359 360
elif [ -n "$clean_load" ] ; then
    test_clean_load
361 362
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
363
else
364
    run_tests "$@"
365
fi