1#! /bin/sh
2# test-driver - basic testsuite driver script.
3
4scriptversion=2013-07-13.22; # UTC
5
6# Copyright (C) 2011-2013 Free Software Foundation, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License, version 2.0,
10# as published by the Free Software Foundation.
11#
12# This program is also distributed with certain software (including
13# but not limited to OpenSSL) that is licensed under separate terms,
14# as designated in a particular file or component or in included license
15# documentation.  The authors of MySQL hereby grant you an additional
16# permission to link the program and your derivative works with the
17# separately licensed software that they have included with MySQL.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU General Public License, version 2.0, for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27# As a special exception to the GNU General Public License, if you
28# distribute this file as part of a program that contains a
29# configuration script generated by Autoconf, you may include it under
30# the same distribution terms that you use for the rest of that program.
31
32# This file is maintained in Automake, please report
33# bugs to <bug-automake@gnu.org> or send patches to
34# <automake-patches@gnu.org>.
35
36# Make unconditional expansion of undefined variables an error.  This
37# helps a lot in preventing typo-related bugs.
38set -u
39
40usage_error ()
41{
42  echo "$0: $*" >&2
43  print_usage >&2
44  exit 2
45}
46
47print_usage ()
48{
49  cat <<END
50Usage:
51  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
52              [--expect-failure={yes|no}] [--color-tests={yes|no}]
53              [--enable-hard-errors={yes|no}] [--]
54              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
55The '--test-name', '--log-file' and '--trs-file' options are mandatory.
56END
57}
58
59test_name= # Used for reporting.
60log_file=  # Where to save the output of the test script.
61trs_file=  # Where to save the metadata of the test run.
62expect_failure=no
63color_tests=no
64enable_hard_errors=yes
65while test $# -gt 0; do
66  case $1 in
67  --help) print_usage; exit $?;;
68  --version) echo "test-driver $scriptversion"; exit $?;;
69  --test-name) test_name=$2; shift;;
70  --log-file) log_file=$2; shift;;
71  --trs-file) trs_file=$2; shift;;
72  --color-tests) color_tests=$2; shift;;
73  --expect-failure) expect_failure=$2; shift;;
74  --enable-hard-errors) enable_hard_errors=$2; shift;;
75  --) shift; break;;
76  -*) usage_error "invalid option: '$1'";;
77   *) break;;
78  esac
79  shift
80done
81
82missing_opts=
83test x"$test_name" = x && missing_opts="$missing_opts --test-name"
84test x"$log_file"  = x && missing_opts="$missing_opts --log-file"
85test x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
86if test x"$missing_opts" != x; then
87  usage_error "the following mandatory options are missing:$missing_opts"
88fi
89
90if test $# -eq 0; then
91  usage_error "missing argument"
92fi
93
94if test $color_tests = yes; then
95  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
96  red='' # Red.
97  grn='' # Green.
98  lgn='' # Light green.
99  blu='' # Blue.
100  mgn='' # Magenta.
101  std=''     # No color.
102else
103  red= grn= lgn= blu= mgn= std=
104fi
105
106do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
107trap "st=129; $do_exit" 1
108trap "st=130; $do_exit" 2
109trap "st=141; $do_exit" 13
110trap "st=143; $do_exit" 15
111
112# Test script is run here.
113"$@" >$log_file 2>&1
114estatus=$?
115if test $enable_hard_errors = no && test $estatus -eq 99; then
116  estatus=1
117fi
118
119case $estatus:$expect_failure in
120  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
121  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
122  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
123  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
124  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
125  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
126esac
127
128# Report outcome to console.
129echo "${col}${res}${std}: $test_name"
130
131# Register the test result, and other relevant metadata.
132echo ":test-result: $res" > $trs_file
133echo ":global-test-result: $res" >> $trs_file
134echo ":recheck: $recheck" >> $trs_file
135echo ":copy-in-global-log: $gcopy" >> $trs_file
136
137# Local Variables:
138# mode: shell-script
139# sh-indentation: 2
140# eval: (add-hook 'write-file-hooks 'time-stamp)
141# time-stamp-start: "scriptversion="
142# time-stamp-format: "%:y-%02m-%02d.%02H"
143# time-stamp-time-zone: "UTC"
144# time-stamp-end: "; # UTC"
145# End:
146