roentgen b75cab
#! /bin/sh
roentgen b75cab
# test-driver - basic driver script for the 'parallel-tests' mode.
roentgen b75cab
roentgen b75cab
scriptversion=2012-06-27.10; # UTC
roentgen b75cab
roentgen b75cab
# Copyright (C) 2011-2012 Free Software Foundation, Inc.
roentgen b75cab
#
roentgen b75cab
# This program is free software; you can redistribute it and/or modify
roentgen b75cab
# it under the terms of the GNU General Public License as published by
roentgen b75cab
# the Free Software Foundation; either version 2, or (at your option)
roentgen b75cab
# any later version.
roentgen b75cab
#
roentgen b75cab
# This program is distributed in the hope that it will be useful,
roentgen b75cab
# but WITHOUT ANY WARRANTY; without even the implied warranty of
roentgen b75cab
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
roentgen b75cab
# GNU General Public License for more details.
roentgen b75cab
#
roentgen b75cab
# You should have received a copy of the GNU General Public License
roentgen b75cab
# along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
roentgen b75cab
roentgen b75cab
# As a special exception to the GNU General Public License, if you
roentgen b75cab
# distribute this file as part of a program that contains a
roentgen b75cab
# configuration script generated by Autoconf, you may include it under
roentgen b75cab
# the same distribution terms that you use for the rest of that program.
roentgen b75cab
roentgen b75cab
# This file is maintained in Automake, please report
roentgen b75cab
# bugs to <bug-automake@gnu.org> or send patches to</bug-automake@gnu.org>
roentgen b75cab
# <automake-patches@gnu.org>.</automake-patches@gnu.org>
roentgen b75cab
roentgen b75cab
# Make unconditional expansion of undefined variables an error.  This
roentgen b75cab
# helps a lot in preventing typo-related bugs.
roentgen b75cab
set -u
roentgen b75cab
roentgen b75cab
usage_error ()
roentgen b75cab
{
roentgen b75cab
  echo "$0: $*" >&2
roentgen b75cab
  print_usage >&2
roentgen b75cab
  exit 2
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
print_usage ()
roentgen b75cab
{
roentgen b75cab
  cat <
roentgen b75cab
Usage:
roentgen b75cab
  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
roentgen b75cab
              [--expect-failure={yes|no}] [--color-tests={yes|no}]
roentgen b75cab
              [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
roentgen b75cab
The '--test-name', '--log-file' and '--trs-file' options are mandatory.
roentgen b75cab
END
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
# TODO: better error handling in option parsing (in particular, ensure
roentgen b75cab
# TODO: $log_file, $trs_file and $test_name are defined).
roentgen b75cab
test_name= # Used for reporting.
roentgen b75cab
log_file=  # Where to save the output of the test script.
roentgen b75cab
trs_file=  # Where to save the metadata of the test run.
roentgen b75cab
expect_failure=no
roentgen b75cab
color_tests=no
roentgen b75cab
enable_hard_errors=yes
roentgen b75cab
while test $# -gt 0; do
roentgen b75cab
  case $1 in
roentgen b75cab
  --help) print_usage; exit $?;;
roentgen b75cab
  --version) echo "test-driver $scriptversion"; exit $?;;
roentgen b75cab
  --test-name) test_name=$2; shift;;
roentgen b75cab
  --log-file) log_file=$2; shift;;
roentgen b75cab
  --trs-file) trs_file=$2; shift;;
roentgen b75cab
  --color-tests) color_tests=$2; shift;;
roentgen b75cab
  --expect-failure) expect_failure=$2; shift;;
roentgen b75cab
  --enable-hard-errors) enable_hard_errors=$2; shift;;
roentgen b75cab
  --) shift; break;;
roentgen b75cab
  -*) usage_error "invalid option: '$1'";;
roentgen b75cab
  esac
roentgen b75cab
  shift
roentgen b75cab
done
roentgen b75cab
roentgen b75cab
if test $color_tests = yes; then
roentgen b75cab
  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
roentgen b75cab
  red='' # Red.
roentgen b75cab
  grn='' # Green.
roentgen b75cab
  lgn='' # Light green.
roentgen b75cab
  blu='' # Blue.
roentgen b75cab
  mgn='' # Magenta.
roentgen b75cab
  std=''     # No color.
roentgen b75cab
else
roentgen b75cab
  red= grn= lgn= blu= mgn= std=
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
roentgen b75cab
trap "st=129; $do_exit" 1
roentgen b75cab
trap "st=130; $do_exit" 2
roentgen b75cab
trap "st=141; $do_exit" 13
roentgen b75cab
trap "st=143; $do_exit" 15
roentgen b75cab
roentgen b75cab
# Test script is run here.
roentgen b75cab
"$@" >$log_file 2>&1
roentgen b75cab
estatus=$?
roentgen b75cab
if test $enable_hard_errors = no && test $estatus -eq 99; then
roentgen b75cab
  estatus=1
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
case $estatus:$expect_failure in
roentgen b75cab
  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
roentgen b75cab
  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
roentgen b75cab
  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
roentgen b75cab
  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
roentgen b75cab
  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
roentgen b75cab
  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
roentgen b75cab
esac
roentgen b75cab
roentgen b75cab
# Report outcome to console.
roentgen b75cab
echo "${col}${res}${std}: $test_name"
roentgen b75cab
roentgen b75cab
# Register the test result, and other relevant metadata.
roentgen b75cab
echo ":test-result: $res" > $trs_file
roentgen b75cab
echo ":global-test-result: $res" >> $trs_file
roentgen b75cab
echo ":recheck: $recheck" >> $trs_file
roentgen b75cab
echo ":copy-in-global-log: $gcopy" >> $trs_file
roentgen b75cab
roentgen b75cab
# Local Variables:
roentgen b75cab
# mode: shell-script
roentgen b75cab
# sh-indentation: 2
roentgen b75cab
# eval: (add-hook 'write-file-hooks 'time-stamp)
roentgen b75cab
# time-stamp-start: "scriptversion="
roentgen b75cab
# time-stamp-format: "%:y-%02m-%02d.%02H"
roentgen b75cab
# time-stamp-time-zone: "UTC"
roentgen b75cab
# time-stamp-end: "; # UTC"
roentgen b75cab
# End: