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