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