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