File indexing completed on 2024-12-22 04:04:20

0001 #! /bin/sh
0002 # test-driver - basic testsuite driver script.
0003 
0004 scriptversion=2018-03-07.03; # UTC
0005 
0006 # Copyright (C) 2011-2018 Free Software Foundation, Inc.
0007 #
0008 # This program is free software; you can redistribute it and/or modify
0009 # it under the terms of the GNU General Public License as published by
0010 # the Free Software Foundation; either version 2, or (at your option)
0011 # any later version.
0012 #
0013 # This program is distributed in the hope that it will be useful,
0014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016 # GNU General Public License for more details.
0017 #
0018 # You should have received a copy of the GNU General Public License
0019 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
0020 
0021 # As a special exception to the GNU General Public License, if you
0022 # distribute this file as part of a program that contains a
0023 # configuration script generated by Autoconf, you may include it under
0024 # the same distribution terms that you use for the rest of that program.
0025 
0026 # This file is maintained in Automake, please report
0027 # bugs to <bug-automake@gnu.org> or send patches to
0028 # <automake-patches@gnu.org>.
0029 
0030 # Make unconditional expansion of undefined variables an error.  This
0031 # helps a lot in preventing typo-related bugs.
0032 set -u
0033 
0034 usage_error ()
0035 {
0036   echo "$0: $*" >&2
0037   print_usage >&2
0038   exit 2
0039 }
0040 
0041 print_usage ()
0042 {
0043   cat <<END
0044 Usage:
0045   test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
0046               [--expect-failure={yes|no}] [--color-tests={yes|no}]
0047               [--enable-hard-errors={yes|no}] [--]
0048               TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
0049 The '--test-name', '--log-file' and '--trs-file' options are mandatory.
0050 END
0051 }
0052 
0053 test_name= # Used for reporting.
0054 log_file=  # Where to save the output of the test script.
0055 trs_file=  # Where to save the metadata of the test run.
0056 expect_failure=no
0057 color_tests=no
0058 enable_hard_errors=yes
0059 while test $# -gt 0; do
0060   case $1 in
0061   --help) print_usage; exit $?;;
0062   --version) echo "test-driver $scriptversion"; exit $?;;
0063   --test-name) test_name=$2; shift;;
0064   --log-file) log_file=$2; shift;;
0065   --trs-file) trs_file=$2; shift;;
0066   --color-tests) color_tests=$2; shift;;
0067   --expect-failure) expect_failure=$2; shift;;
0068   --enable-hard-errors) enable_hard_errors=$2; shift;;
0069   --) shift; break;;
0070   -*) usage_error "invalid option: '$1'";;
0071    *) break;;
0072   esac
0073   shift
0074 done
0075 
0076 missing_opts=
0077 test x"$test_name" = x && missing_opts="$missing_opts --test-name"
0078 test x"$log_file"  = x && missing_opts="$missing_opts --log-file"
0079 test x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
0080 if test x"$missing_opts" != x; then
0081   usage_error "the following mandatory options are missing:$missing_opts"
0082 fi
0083 
0084 if test $# -eq 0; then
0085   usage_error "missing argument"
0086 fi
0087 
0088 if test $color_tests = yes; then
0089   # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
0090   red='' # Red.
0091   grn='' # Green.
0092   lgn='' # Light green.
0093   blu='' # Blue.
0094   mgn='' # Magenta.
0095   std=''     # No color.
0096 else
0097   red= grn= lgn= blu= mgn= std=
0098 fi
0099 
0100 do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
0101 trap "st=129; $do_exit" 1
0102 trap "st=130; $do_exit" 2
0103 trap "st=141; $do_exit" 13
0104 trap "st=143; $do_exit" 15
0105 
0106 # Test script is run here.
0107 "$@" >$log_file 2>&1
0108 estatus=$?
0109 
0110 if test $enable_hard_errors = no && test $estatus -eq 99; then
0111   tweaked_estatus=1
0112 else
0113   tweaked_estatus=$estatus
0114 fi
0115 
0116 case $tweaked_estatus:$expect_failure in
0117   0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
0118   0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
0119   77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
0120   99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
0121   *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
0122   *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
0123 esac
0124 
0125 # Report the test outcome and exit status in the logs, so that one can
0126 # know whether the test passed or failed simply by looking at the '.log'
0127 # file, without the need of also peaking into the corresponding '.trs'
0128 # file (automake bug#11814).
0129 echo "$res $test_name (exit status: $estatus)" >>$log_file
0130 
0131 # Report outcome to console.
0132 echo "${col}${res}${std}: $test_name"
0133 
0134 # Register the test result, and other relevant metadata.
0135 echo ":test-result: $res" > $trs_file
0136 echo ":global-test-result: $res" >> $trs_file
0137 echo ":recheck: $recheck" >> $trs_file
0138 echo ":copy-in-global-log: $gcopy" >> $trs_file
0139 
0140 # Local Variables:
0141 # mode: shell-script
0142 # sh-indentation: 2
0143 # eval: (add-hook 'before-save-hook 'time-stamp)
0144 # time-stamp-start: "scriptversion="
0145 # time-stamp-format: "%:y-%02m-%02d.%02H"
0146 # time-stamp-time-zone: "UTC0"
0147 # time-stamp-end: "; # UTC"
0148 # End: