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