Home | History | Annotate | Download | only in android
      1 #! /bin/sh
      2 # test-driver - basic testsuite driver script.
      3 
      4 # Slightly modified for Android, see ANDROID comment below.
      5 
      6 scriptversion=2012-06-27.10; # UTC
      7 
      8 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
      9 #
     10 # This program is free software; you can redistribute it and/or modify
     11 # it under the terms of the GNU General Public License as published by
     12 # the Free Software Foundation; either version 2, or (at your option)
     13 # any later version.
     14 #
     15 # This program is distributed in the hope that it will be useful,
     16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18 # GNU General Public License for more details.
     19 #
     20 # You should have received a copy of the GNU General Public License
     21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22 
     23 # As a special exception to the GNU General Public License, if you
     24 # distribute this file as part of a program that contains a
     25 # configuration script generated by Autoconf, you may include it under
     26 # the same distribution terms that you use for the rest of that program.
     27 
     28 # This file is maintained in Automake, please report
     29 # bugs to <bug-automake (at] gnu.org> or send patches to
     30 # <automake-patches (at] gnu.org>.
     31 
     32 # Make unconditional expansion of undefined variables an error.  This
     33 # helps a lot in preventing typo-related bugs.
     34 set -u
     35 
     36 usage_error ()
     37 {
     38   echo "$0: $*" >&2
     39   print_usage >&2
     40   exit 2
     41 }
     42 
     43 print_usage ()
     44 {
     45   cat <<END
     46 Usage:
     47   test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
     48               [--expect-failure={yes|no}] [--color-tests={yes|no}]
     49               [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
     50 The '--test-name', '--log-file' and '--trs-file' options are mandatory.
     51 END
     52 }
     53 
     54 # TODO: better error handling in option parsing (in particular, ensure
     55 # TODO: $log_file, $trs_file and $test_name are defined).
     56 test_name= # Used for reporting.
     57 log_file=  # Where to save the output of the test script.
     58 trs_file=  # Where to save the metadata of the test run.
     59 expect_failure=no
     60 color_tests=no
     61 enable_hard_errors=yes
     62 while test $# -gt 0; do
     63   case $1 in
     64   --help) print_usage; exit $?;;
     65   --version) echo "test-driver $scriptversion"; exit $?;;
     66   --test-name) test_name=$2; shift;;
     67   --log-file) log_file=$2; shift;;
     68   --trs-file) trs_file=$2; shift;;
     69   --color-tests) color_tests=$2; shift;;
     70   --expect-failure) expect_failure=$2; shift;;
     71   --enable-hard-errors) enable_hard_errors=$2; shift;;
     72   --) shift; break;;
     73   -*) usage_error "invalid option: '$1'";;
     74   esac
     75   shift
     76 done
     77 
     78 if test $color_tests = yes; then
     79   # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
     80   red='[0;31m' # Red.
     81   grn='[0;32m' # Green.
     82   lgn='[1;32m' # Light green.
     83   blu='[1;34m' # Blue.
     84   mgn='[0;35m' # Magenta.
     85   std='[m'     # No color.
     86 else
     87   red= grn= lgn= blu= mgn= std=
     88 fi
     89 
     90 do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
     91 trap "st=129; $do_exit" 1
     92 trap "st=130; $do_exit" 2
     93 trap "st=141; $do_exit" 13
     94 trap "st=143; $do_exit" 15
     95 
     96 # Test script is run here.
     97 # ANDROID: old line was: "$@" > $log_file 2>&1
     98 progdir=$(dirname "$0")
     99 "$progdir/test-shell.sh" "$@" > $log_file 2>&1
    100 estatus=$?
    101 if test $enable_hard_errors = no && test $estatus -eq 99; then
    102   estatus=1
    103 fi
    104 
    105 case $estatus:$expect_failure in
    106   0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
    107   0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
    108   77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
    109   99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
    110   *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
    111   *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
    112 esac
    113 
    114 # Report outcome to console.
    115 echo "${col}${res}${std}: $test_name"
    116 
    117 # Register the test result, and other relevant metadata.
    118 echo ":test-result: $res" > $trs_file
    119 echo ":global-test-result: $res" >> $trs_file
    120 echo ":recheck: $recheck" >> $trs_file
    121 echo ":copy-in-global-log: $gcopy" >> $trs_file
    122 
    123 # Local Variables:
    124 # mode: shell-script
    125 # sh-indentation: 2
    126 # eval: (add-hook 'write-file-hooks 'time-stamp)
    127 # time-stamp-start: "scriptversion="
    128 # time-stamp-format: "%:y-%02m-%02d.%02H"
    129 # time-stamp-time-zone: "UTC"
    130 # time-stamp-end: "; # UTC"
    131 # End:
    132