run-tests.sh 11.9 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
    echo "    -c -- clean load test"
    echo "    -l -- load systems tests"
22 23
}

24
unset DEBUG_ASDF_TEST upgrade clean_load load_systems
Robert P. Goldman's avatar
 
Robert P. Goldman committed
25

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

49
if [ x"$1" = "xhelp" ]; then
Robert P. Goldman's avatar
 
Robert P. Goldman committed
50 51
    usage
    exit 1
52
fi
53
lisp=${1:-sbcl} ; shift
54

55

56 57 58 59 60 61 62 63 64 65 66 67 68
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
69

70
do_tests() {
71 72 73 74 75
  if [ -z "$*" ]; then
       scripts="*.script"
  else
       scripts="$*"
  fi
76
  env | grep -i asdf
77
  rm -f ~/.cache/common-lisp/"`pwd`"/* || true
78
  ( cd .. && DO $cmd $debugp $eval '(or #.(load "test/script-support.lisp") #.(asdf-test::compile-asdf-script))' )
79 80
  if [ $? -ne 0 ] ; then
    echo "Compilation FAILED" >&2
81 82 83 84 85 86
    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
87 88
  else
    echo "Compiled OK" >&2
89 90 91 92
    test_count=0
    test_pass=0
    test_fail=0
    failed_list=""
93 94
    for i in $scripts ;
    do
95 96
      echo "Testing: $i" >&2
      test_count=`expr "$test_count" + 1`
97
      rm -f ~/.cache/common-lisp/"`pwd`"/* || true
98
      if DO $cmd $debugp $eval "(load \"script-support.lisp\")" $eval "(asdf-test::load-asdf)" $eval "(asdf-test::with-test () (load \"$i\"))" ; then
99
        echo "Using $command, $i passed" >&2
100 101
	test_pass=`expr "$test_pass" + 1`
      else
102
        echo "Using $command, $i failed" >&2
103 104
	test_fail=`expr "$test_fail" + 1`
	failed_list="$failed_list $i"
105 106 107 108 109
        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
110
        echo "'(#.(load \"script-support.lisp\") #.(asdf-test::da) #.(load-asdf) #.(load \"$i\"))" >&2
111
      fi
112 113
      echo >&2
      echo >&2
114 115
    done
    echo >&2
Gary King's avatar
Gary King committed
116
    echo "-#---------------------------------------" >&2
117
    echo "Using $command" >&2
118 119 120 121
    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
122
        echo success > ../build/results/status
123 124 125
    else
	echo "failing test(s): $failed_list" >&2
    fi
Gary King's avatar
Gary King committed
126
    echo "-#---------------------------------------" >&2
127
    echo >&2
128
  fi
129 130
}

131
# terminate on error
132 133
set -e

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

217
if ! type "$command" > /dev/null ; then
218
    echo "lisp implementation not found: $command" >&2
219 220 221
    exit 43
fi

222
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
223 224

## Make sure testing remains within the confines of this filesystem tree
225
export CL_SOURCE_REGISTRY="${ASDFDIR}"
226
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
227

228
cmd="$command $flags"
229
debugp=
230
if [ -z "${DEBUG_ASDF_TEST}" ] ; then
231
  debugp="$nodebug"
232 233
fi

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

235
create_config () {
236
    mkdir -p ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
237
}
238
upgrade_tags () {
239 240
    if [ -n "$ASDF_UPGRADE_TEST_TAGS" ] ; then
        echo $ASDF_UPGRADE_TEST_TAGS ; return
241
    fi
242
    # REQUIRE is a magic tag meaning whatever your implementation provides
243
    # 1.85 is the last release by Daniel Barlow (not 1.37, which is the README revision!)
244 245 246
    # 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
247
    # 2.26.61 is the last single-package ASDF.
248
    echo REQUIRE 1.85 1.97 1.369
249 250 251
    git tag -l '2.0??'
    git tag -l '2.??'
}
252
upgrade_methods () {
253 254
    if [ -n "$ASDF_UPGRADE_TEST_METHODS" ] ; then
        echo $ASDF_UPGRADE_TEST_METHODS ; return
255 256
    fi
    cat <<EOF
257
'load-asdf-lisp'load-asdf-lisp-clean
258 259 260 261 262 263
'load-asdf-lisp'load-asdf-system
'load-asdf-lisp'compile-load-asdf
'load-asdf-lisp'load-asdf-fasl
()'load-asdf-fasl
EOF
}
264 265
extract_tagged_asdf () {
    ver=$1
266
    if [ REQUIRE = "$ver" ] ; then return 0 ; fi
267 268 269
    file=build/asdf-${tag}.lisp ;
    if [ ! -f $file ] ; then
        case $ver in
270
            1.*|2.0*|2.2[0-6]|2.26.61)
271 272 273 274 275 276 277 278
                git show ${tag}:asdf.lisp > $file ;;
            *)
                echo "Don't know how to extract asdf.lisp for version $tag"
                exit 55
                ;;
        esac
    fi
}
279 280 281 282 283 284 285 286 287 288
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.
289
            : ;;
290 291 292 293 294 295 296 297 298 299 300 301
        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
302
}
303
run_upgrade_tests () {
304
    cd ${ASDFDIR}
305 306
    su=test/script-support.lisp
    for tag in `upgrade_tags` ; do
307 308 309 310
        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
311
                $cmd $debugp $eval \
312
                "'(#.(load\"$su\")#.(in-package :asdf-test)#.(test-upgrade $method \"$tag\"))" ||
313 314 315
                { 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 ;
316
                  echo "or more interactively (and maybe with rlwrap or in emacs), start with:"
317
                  echo "$cmd"
318 319 320
                  echo "then copy/paste:"
                  echo "(load\"$su\") (da) (test-upgrade $method \"$tag\")"
                  exit 1 ;}
321
    fi ; done ; done 2>&1 | tee build/results/${lisp}-upgrade.text
322 323
}
run_tests () {
324
  cd ${ASDFDIR}/test
325 326 327 328
  create_config
  mkdir -p ../build/results
  echo failure > ../build/results/status
    thedate=`date "+%Y-%m-%d"`
329
    do_tests "$@" 2>&1 | \
330 331 332
	tee "../build/results/${lisp}.text" "../build/results/${lisp}-${thedate}.save"
    read a < ../build/results/status
  clean_up
333 334 335 336 337 338 339
  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
340
}
341
clean_up () {
342
    rm -rf ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
343
}
344
test_clean_load () {
345
    case $lisp in
346
        gcl|cmucl) return 0 ;; # These are hopeless
347
    esac
348 349
    nop=build/results/${lisp}-nop.text
    load=build/results/${lisp}-load.text
350
    ${cmd} ${eval} \
351
      '(or #.(load "test/script-support.lisp" :verbose nil :print nil) #.(asdf-test::exit-lisp 0))' \
352
        > $nop 2>&1
353
    ${cmd} ${eval} \
354
      '(or #.(load "build/asdf.lisp" :verbose nil :print nil) #.(asdf/image:quit 0))' \
355 356 357 358 359 360 361
        > $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
}
362 363 364 365 366 367 368 369
test_load_systems () {
    case $lisp in
        gcl) return 0 ;; # This one is hopeless
    esac
    ${cmd} ${eval} \
      "(or #.(load \"test/script-support.lisp\") #.(asdf-test::with-test () (asdf-test::test-load-systems ${s})))" \
        2>&1 | tee build/results/${lisp}-systems.text
}
370

371
if [ -z "$cmd" ] ; then
Gary King's avatar
Gary King committed
372
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
373 374
elif [ -n "$clean_load" ] ; then
    test_clean_load
375 376
elif [ -n "$load_systems" ] ; then
    test_load_systems
377 378
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
379
else
380
    run_tests "$@"
381
fi