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