1*a67afe4dSAndroid Build Coastguard Worker#! /bin/sh 2*a67afe4dSAndroid Build Coastguard Worker# test-driver - basic testsuite driver script. 3*a67afe4dSAndroid Build Coastguard Worker 4*a67afe4dSAndroid Build Coastguard Workerscriptversion=2024-06-19.01; # UTC 5*a67afe4dSAndroid Build Coastguard Worker 6*a67afe4dSAndroid Build Coastguard Worker# Copyright (C) 2011-2024 Free Software Foundation, Inc. 7*a67afe4dSAndroid Build Coastguard Worker# 8*a67afe4dSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or modify 9*a67afe4dSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by 10*a67afe4dSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2, or (at your option) 11*a67afe4dSAndroid Build Coastguard Worker# any later version. 12*a67afe4dSAndroid Build Coastguard Worker# 13*a67afe4dSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful, 14*a67afe4dSAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a67afe4dSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a67afe4dSAndroid Build Coastguard Worker# GNU General Public License for more details. 17*a67afe4dSAndroid Build Coastguard Worker# 18*a67afe4dSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License 19*a67afe4dSAndroid Build Coastguard Worker# along with this program. If not, see <https://www.gnu.org/licenses/>. 20*a67afe4dSAndroid Build Coastguard Worker 21*a67afe4dSAndroid Build Coastguard Worker# As a special exception to the GNU General Public License, if you 22*a67afe4dSAndroid Build Coastguard Worker# distribute this file as part of a program that contains a 23*a67afe4dSAndroid Build Coastguard Worker# configuration script generated by Autoconf, you may include it under 24*a67afe4dSAndroid Build Coastguard Worker# the same distribution terms that you use for the rest of that program. 25*a67afe4dSAndroid Build Coastguard Worker 26*a67afe4dSAndroid Build Coastguard Worker# This file is maintained in Automake, please report 27*a67afe4dSAndroid Build Coastguard Worker# bugs to <[email protected]> or send patches to 28*a67afe4dSAndroid Build Coastguard Worker# <[email protected]>. 29*a67afe4dSAndroid Build Coastguard Worker 30*a67afe4dSAndroid Build Coastguard Worker# Make unconditional expansion of undefined variables an error. This 31*a67afe4dSAndroid Build Coastguard Worker# helps a lot in preventing typo-related bugs. 32*a67afe4dSAndroid Build Coastguard Workerset -u 33*a67afe4dSAndroid Build Coastguard Worker 34*a67afe4dSAndroid Build Coastguard Workerusage_error () 35*a67afe4dSAndroid Build Coastguard Worker{ 36*a67afe4dSAndroid Build Coastguard Worker echo "$0: $*" >&2 37*a67afe4dSAndroid Build Coastguard Worker print_usage >&2 38*a67afe4dSAndroid Build Coastguard Worker exit 2 39*a67afe4dSAndroid Build Coastguard Worker} 40*a67afe4dSAndroid Build Coastguard Worker 41*a67afe4dSAndroid Build Coastguard Workerprint_usage () 42*a67afe4dSAndroid Build Coastguard Worker{ 43*a67afe4dSAndroid Build Coastguard Worker cat <<END 44*a67afe4dSAndroid Build Coastguard WorkerUsage: 45*a67afe4dSAndroid Build Coastguard Worker test-driver --test-name NAME --log-file PATH --trs-file PATH 46*a67afe4dSAndroid Build Coastguard Worker [--expect-failure {yes|no}] [--color-tests {yes|no}] 47*a67afe4dSAndroid Build Coastguard Worker [--collect-skipped-logs {yes|no}] 48*a67afe4dSAndroid Build Coastguard Worker [--enable-hard-errors {yes|no}] [--] 49*a67afe4dSAndroid Build Coastguard Worker TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 50*a67afe4dSAndroid Build Coastguard Worker 51*a67afe4dSAndroid Build Coastguard WorkerThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 52*a67afe4dSAndroid Build Coastguard WorkerSee the GNU Automake documentation for information. 53*a67afe4dSAndroid Build Coastguard Worker 54*a67afe4dSAndroid Build Coastguard WorkerReport bugs to <[email protected]>. 55*a67afe4dSAndroid Build Coastguard WorkerGNU Automake home page: <https://www.gnu.org/software/automake/>. 56*a67afe4dSAndroid Build Coastguard WorkerGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 57*a67afe4dSAndroid Build Coastguard WorkerEND 58*a67afe4dSAndroid Build Coastguard Worker} 59*a67afe4dSAndroid Build Coastguard Worker 60*a67afe4dSAndroid Build Coastguard Workertest_name= # Used for reporting. 61*a67afe4dSAndroid Build Coastguard Workerlog_file= # Where to save the output of the test script. 62*a67afe4dSAndroid Build Coastguard Workertrs_file= # Where to save the metadata of the test run. 63*a67afe4dSAndroid Build Coastguard Workerexpect_failure=no 64*a67afe4dSAndroid Build Coastguard Workercolor_tests=no 65*a67afe4dSAndroid Build Coastguard Workercollect_skipped_logs=yes 66*a67afe4dSAndroid Build Coastguard Workerenable_hard_errors=yes 67*a67afe4dSAndroid Build Coastguard Workerwhile test $# -gt 0; do 68*a67afe4dSAndroid Build Coastguard Worker case $1 in 69*a67afe4dSAndroid Build Coastguard Worker --help) print_usage; exit $?;; 70*a67afe4dSAndroid Build Coastguard Worker --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; 71*a67afe4dSAndroid Build Coastguard Worker --test-name) test_name=$2; shift;; 72*a67afe4dSAndroid Build Coastguard Worker --log-file) log_file=$2; shift;; 73*a67afe4dSAndroid Build Coastguard Worker --trs-file) trs_file=$2; shift;; 74*a67afe4dSAndroid Build Coastguard Worker --color-tests) color_tests=$2; shift;; 75*a67afe4dSAndroid Build Coastguard Worker --collect-skipped-logs) collect_skipped_logs=$2; shift;; 76*a67afe4dSAndroid Build Coastguard Worker --expect-failure) expect_failure=$2; shift;; 77*a67afe4dSAndroid Build Coastguard Worker --enable-hard-errors) enable_hard_errors=$2; shift;; 78*a67afe4dSAndroid Build Coastguard Worker --) shift; break;; 79*a67afe4dSAndroid Build Coastguard Worker -*) usage_error "invalid option: '$1'";; 80*a67afe4dSAndroid Build Coastguard Worker *) break;; 81*a67afe4dSAndroid Build Coastguard Worker esac 82*a67afe4dSAndroid Build Coastguard Worker shift 83*a67afe4dSAndroid Build Coastguard Workerdone 84*a67afe4dSAndroid Build Coastguard Worker 85*a67afe4dSAndroid Build Coastguard Workermissing_opts= 86*a67afe4dSAndroid Build Coastguard Workertest x"$test_name" = x && missing_opts="$missing_opts --test-name" 87*a67afe4dSAndroid Build Coastguard Workertest x"$log_file" = x && missing_opts="$missing_opts --log-file" 88*a67afe4dSAndroid Build Coastguard Workertest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 89*a67afe4dSAndroid Build Coastguard Workerif test x"$missing_opts" != x; then 90*a67afe4dSAndroid Build Coastguard Worker usage_error "the following mandatory options are missing:$missing_opts" 91*a67afe4dSAndroid Build Coastguard Workerfi 92*a67afe4dSAndroid Build Coastguard Worker 93*a67afe4dSAndroid Build Coastguard Workerif test $# -eq 0; then 94*a67afe4dSAndroid Build Coastguard Worker usage_error "missing argument" 95*a67afe4dSAndroid Build Coastguard Workerfi 96*a67afe4dSAndroid Build Coastguard Worker 97*a67afe4dSAndroid Build Coastguard Workerif test $color_tests = yes; then 98*a67afe4dSAndroid Build Coastguard Worker # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 99*a67afe4dSAndroid Build Coastguard Worker red='[0;31m' # Red. 100*a67afe4dSAndroid Build Coastguard Worker grn='[0;32m' # Green. 101*a67afe4dSAndroid Build Coastguard Worker lgn='[1;32m' # Light green. 102*a67afe4dSAndroid Build Coastguard Worker blu='[1;34m' # Blue. 103*a67afe4dSAndroid Build Coastguard Worker mgn='[0;35m' # Magenta. 104*a67afe4dSAndroid Build Coastguard Worker std='[m' # No color. 105*a67afe4dSAndroid Build Coastguard Workerelse 106*a67afe4dSAndroid Build Coastguard Worker red= grn= lgn= blu= mgn= std= 107*a67afe4dSAndroid Build Coastguard Workerfi 108*a67afe4dSAndroid Build Coastguard Worker 109*a67afe4dSAndroid Build Coastguard Workerdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 110*a67afe4dSAndroid Build Coastguard Workertrap "st=129; $do_exit" 1 111*a67afe4dSAndroid Build Coastguard Workertrap "st=130; $do_exit" 2 112*a67afe4dSAndroid Build Coastguard Workertrap "st=141; $do_exit" 13 113*a67afe4dSAndroid Build Coastguard Workertrap "st=143; $do_exit" 15 114*a67afe4dSAndroid Build Coastguard Worker 115*a67afe4dSAndroid Build Coastguard Worker# Test script is run here. We create the file first, then append to it, 116*a67afe4dSAndroid Build Coastguard Worker# to ameliorate tests themselves also writing to the log file. Our tests 117*a67afe4dSAndroid Build Coastguard Worker# don't, but others can (automake bug#35762). 118*a67afe4dSAndroid Build Coastguard Worker: >"$log_file" 119*a67afe4dSAndroid Build Coastguard Worker"$@" >>"$log_file" 2>&1 120*a67afe4dSAndroid Build Coastguard Workerestatus=$? 121*a67afe4dSAndroid Build Coastguard Worker 122*a67afe4dSAndroid Build Coastguard Workerif test $enable_hard_errors = no && test $estatus -eq 99; then 123*a67afe4dSAndroid Build Coastguard Worker tweaked_estatus=1 124*a67afe4dSAndroid Build Coastguard Workerelse 125*a67afe4dSAndroid Build Coastguard Worker tweaked_estatus=$estatus 126*a67afe4dSAndroid Build Coastguard Workerfi 127*a67afe4dSAndroid Build Coastguard Worker 128*a67afe4dSAndroid Build Coastguard Workercase $tweaked_estatus:$expect_failure in 129*a67afe4dSAndroid Build Coastguard Worker 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 130*a67afe4dSAndroid Build Coastguard Worker 0:*) col=$grn res=PASS recheck=no gcopy=no;; 131*a67afe4dSAndroid Build Coastguard Worker 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; 132*a67afe4dSAndroid Build Coastguard Worker 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 133*a67afe4dSAndroid Build Coastguard Worker *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 134*a67afe4dSAndroid Build Coastguard Worker *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 135*a67afe4dSAndroid Build Coastguard Workeresac 136*a67afe4dSAndroid Build Coastguard Worker 137*a67afe4dSAndroid Build Coastguard Worker# Report the test outcome and exit status in the logs, so that one can 138*a67afe4dSAndroid Build Coastguard Worker# know whether the test passed or failed simply by looking at the '.log' 139*a67afe4dSAndroid Build Coastguard Worker# file, without the need of also peaking into the corresponding '.trs' 140*a67afe4dSAndroid Build Coastguard Worker# file (automake bug#11814). 141*a67afe4dSAndroid Build Coastguard Workerecho "$res $test_name (exit status: $estatus)" >>"$log_file" 142*a67afe4dSAndroid Build Coastguard Worker 143*a67afe4dSAndroid Build Coastguard Worker# Report outcome to console. 144*a67afe4dSAndroid Build Coastguard Workerecho "${col}${res}${std}: $test_name" 145*a67afe4dSAndroid Build Coastguard Worker 146*a67afe4dSAndroid Build Coastguard Worker# Register the test result, and other relevant metadata. 147*a67afe4dSAndroid Build Coastguard Workerecho ":test-result: $res" > $trs_file 148*a67afe4dSAndroid Build Coastguard Workerecho ":global-test-result: $res" >> $trs_file 149*a67afe4dSAndroid Build Coastguard Workerecho ":recheck: $recheck" >> $trs_file 150*a67afe4dSAndroid Build Coastguard Workerecho ":copy-in-global-log: $gcopy" >> $trs_file 151*a67afe4dSAndroid Build Coastguard Worker 152*a67afe4dSAndroid Build Coastguard Worker# Local Variables: 153*a67afe4dSAndroid Build Coastguard Worker# mode: shell-script 154*a67afe4dSAndroid Build Coastguard Worker# sh-indentation: 2 155*a67afe4dSAndroid Build Coastguard Worker# eval: (add-hook 'before-save-hook 'time-stamp) 156*a67afe4dSAndroid Build Coastguard Worker# time-stamp-start: "scriptversion=" 157*a67afe4dSAndroid Build Coastguard Worker# time-stamp-format: "%:y-%02m-%02d.%02H" 158*a67afe4dSAndroid Build Coastguard Worker# time-stamp-time-zone: "UTC0" 159*a67afe4dSAndroid Build Coastguard Worker# time-stamp-end: "; # UTC" 160*a67afe4dSAndroid Build Coastguard Worker# End: 161