11.1Sriastrad#! /bin/sh
21.1Sriastrad# test-driver - basic testsuite driver script.
31.1Sriastrad
41.1Sriastradscriptversion=2016-01-11.22; # UTC
51.1Sriastrad
61.1Sriastrad# Copyright (C) 2011-2017 Free Software Foundation, Inc.
71.1Sriastrad#
81.1Sriastrad# This program is free software; you can redistribute it and/or modify
91.1Sriastrad# it under the terms of the GNU General Public License as published by
101.1Sriastrad# the Free Software Foundation; either version 2, or (at your option)
111.1Sriastrad# any later version.
121.1Sriastrad#
131.1Sriastrad# This program is distributed in the hope that it will be useful,
141.1Sriastrad# but WITHOUT ANY WARRANTY; without even the implied warranty of
151.1Sriastrad# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161.1Sriastrad# GNU General Public License for more details.
171.1Sriastrad#
181.1Sriastrad# You should have received a copy of the GNU General Public License
191.1Sriastrad# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201.1Sriastrad
211.1Sriastrad# As a special exception to the GNU General Public License, if you
221.1Sriastrad# distribute this file as part of a program that contains a
231.1Sriastrad# configuration script generated by Autoconf, you may include it under
241.1Sriastrad# the same distribution terms that you use for the rest of that program.
251.1Sriastrad
261.1Sriastrad# This file is maintained in Automake, please report
271.1Sriastrad# bugs to <bug-automake@gnu.org> or send patches to
281.1Sriastrad# <automake-patches@gnu.org>.
291.1Sriastrad
301.1Sriastrad# Make unconditional expansion of undefined variables an error.  This
311.1Sriastrad# helps a lot in preventing typo-related bugs.
321.1Sriastradset -u
331.1Sriastrad
341.1Sriastradusage_error ()
351.1Sriastrad{
361.1Sriastrad  echo "$0: $*" >&2
371.1Sriastrad  print_usage >&2
381.1Sriastrad  exit 2
391.1Sriastrad}
401.1Sriastrad
411.1Sriastradprint_usage ()
421.1Sriastrad{
431.1Sriastrad  cat <<END
441.1SriastradUsage:
451.1Sriastrad  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
461.1Sriastrad              [--expect-failure={yes|no}] [--color-tests={yes|no}]
471.1Sriastrad              [--enable-hard-errors={yes|no}] [--]
481.1Sriastrad              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
491.1SriastradThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
501.1SriastradEND
511.1Sriastrad}
521.1Sriastrad
531.1Sriastradtest_name= # Used for reporting.
541.1Sriastradlog_file=  # Where to save the output of the test script.
551.1Sriastradtrs_file=  # Where to save the metadata of the test run.
561.1Sriastradexpect_failure=no
571.1Sriastradcolor_tests=no
581.1Sriastradenable_hard_errors=yes
591.1Sriastradwhile test $# -gt 0; do
601.1Sriastrad  case $1 in
611.1Sriastrad  --help) print_usage; exit $?;;
621.1Sriastrad  --version) echo "test-driver $scriptversion"; exit $?;;
631.1Sriastrad  --test-name) test_name=$2; shift;;
641.1Sriastrad  --log-file) log_file=$2; shift;;
651.1Sriastrad  --trs-file) trs_file=$2; shift;;
661.1Sriastrad  --color-tests) color_tests=$2; shift;;
671.1Sriastrad  --expect-failure) expect_failure=$2; shift;;
681.1Sriastrad  --enable-hard-errors) enable_hard_errors=$2; shift;;
691.1Sriastrad  --) shift; break;;
701.1Sriastrad  -*) usage_error "invalid option: '$1'";;
711.1Sriastrad   *) break;;
721.1Sriastrad  esac
731.1Sriastrad  shift
741.1Sriastraddone
751.1Sriastrad
761.1Sriastradmissing_opts=
771.1Sriastradtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
781.1Sriastradtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
791.1Sriastradtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
801.1Sriastradif test x"$missing_opts" != x; then
811.1Sriastrad  usage_error "the following mandatory options are missing:$missing_opts"
821.1Sriastradfi
831.1Sriastrad
841.1Sriastradif test $# -eq 0; then
851.1Sriastrad  usage_error "missing argument"
861.1Sriastradfi
871.1Sriastrad
881.1Sriastradif test $color_tests = yes; then
891.1Sriastrad  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
901.1Sriastrad  red='[0;31m' # Red.
911.1Sriastrad  grn='[0;32m' # Green.
921.1Sriastrad  lgn='[1;32m' # Light green.
931.1Sriastrad  blu='[1;34m' # Blue.
941.1Sriastrad  mgn='[0;35m' # Magenta.
951.1Sriastrad  std='[m'     # No color.
961.1Sriastradelse
971.1Sriastrad  red= grn= lgn= blu= mgn= std=
981.1Sriastradfi
991.1Sriastrad
1001.1Sriastraddo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1011.1Sriastradtrap "st=129; $do_exit" 1
1021.1Sriastradtrap "st=130; $do_exit" 2
1031.1Sriastradtrap "st=141; $do_exit" 13
1041.1Sriastradtrap "st=143; $do_exit" 15
1051.1Sriastrad
1061.1Sriastrad# Test script is run here.
1071.1Sriastrad"$@" >$log_file 2>&1
1081.1Sriastradestatus=$?
1091.1Sriastrad
1101.1Sriastradif test $enable_hard_errors = no && test $estatus -eq 99; then
1111.1Sriastrad  tweaked_estatus=1
1121.1Sriastradelse
1131.1Sriastrad  tweaked_estatus=$estatus
1141.1Sriastradfi
1151.1Sriastrad
1161.1Sriastradcase $tweaked_estatus:$expect_failure in
1171.1Sriastrad  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1181.1Sriastrad  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1191.1Sriastrad  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1201.1Sriastrad  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1211.1Sriastrad  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1221.1Sriastrad  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1231.1Sriastradesac
1241.1Sriastrad
1251.1Sriastrad# Report the test outcome and exit status in the logs, so that one can
1261.1Sriastrad# know whether the test passed or failed simply by looking at the '.log'
1271.1Sriastrad# file, without the need of also peaking into the corresponding '.trs'
1281.1Sriastrad# file (automake bug#11814).
1291.1Sriastradecho "$res $test_name (exit status: $estatus)" >>$log_file
1301.1Sriastrad
1311.1Sriastrad# Report outcome to console.
1321.1Sriastradecho "${col}${res}${std}: $test_name"
1331.1Sriastrad
1341.1Sriastrad# Register the test result, and other relevant metadata.
1351.1Sriastradecho ":test-result: $res" > $trs_file
1361.1Sriastradecho ":global-test-result: $res" >> $trs_file
1371.1Sriastradecho ":recheck: $recheck" >> $trs_file
1381.1Sriastradecho ":copy-in-global-log: $gcopy" >> $trs_file
1391.1Sriastrad
1401.1Sriastrad# Local Variables:
1411.1Sriastrad# mode: shell-script
1421.1Sriastrad# sh-indentation: 2
1431.1Sriastrad# eval: (add-hook 'write-file-hooks 'time-stamp)
1441.1Sriastrad# time-stamp-start: "scriptversion="
1451.1Sriastrad# time-stamp-format: "%:y-%02m-%02d.%02H"
1461.1Sriastrad# time-stamp-time-zone: "UTC0"
1471.1Sriastrad# time-stamp-end: "; # UTC"
1481.1Sriastrad# End:
149