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