Blame test-driver

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