113498266Sopenharmony_ci#! /bin/sh 213498266Sopenharmony_ci# test-driver - basic testsuite driver script. 313498266Sopenharmony_ci 413498266Sopenharmony_ciscriptversion=2018-03-07.03; # UTC 513498266Sopenharmony_ci 613498266Sopenharmony_ci# Copyright (C) 2011-2021 Free Software Foundation, Inc. 713498266Sopenharmony_ci# 813498266Sopenharmony_ci# This program is free software; you can redistribute it and/or modify 913498266Sopenharmony_ci# it under the terms of the GNU General Public License as published by 1013498266Sopenharmony_ci# the Free Software Foundation; either version 2, or (at your option) 1113498266Sopenharmony_ci# any later version. 1213498266Sopenharmony_ci# 1313498266Sopenharmony_ci# This program is distributed in the hope that it will be useful, 1413498266Sopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of 1513498266Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1613498266Sopenharmony_ci# GNU General Public License for more details. 1713498266Sopenharmony_ci# 1813498266Sopenharmony_ci# You should have received a copy of the GNU General Public License 1913498266Sopenharmony_ci# along with this program. If not, see <https://www.gnu.org/licenses/>. 2013498266Sopenharmony_ci 2113498266Sopenharmony_ci# As a special exception to the GNU General Public License, if you 2213498266Sopenharmony_ci# distribute this file as part of a program that contains a 2313498266Sopenharmony_ci# configuration script generated by Autoconf, you may include it under 2413498266Sopenharmony_ci# the same distribution terms that you use for the rest of that program. 2513498266Sopenharmony_ci 2613498266Sopenharmony_ci# This file is maintained in Automake, please report 2713498266Sopenharmony_ci# bugs to <bug-automake@gnu.org> or send patches to 2813498266Sopenharmony_ci# <automake-patches@gnu.org>. 2913498266Sopenharmony_ci 3013498266Sopenharmony_ci# Make unconditional expansion of undefined variables an error. This 3113498266Sopenharmony_ci# helps a lot in preventing typo-related bugs. 3213498266Sopenharmony_ciset -u 3313498266Sopenharmony_ci 3413498266Sopenharmony_ciusage_error () 3513498266Sopenharmony_ci{ 3613498266Sopenharmony_ci echo "$0: $*" >&2 3713498266Sopenharmony_ci print_usage >&2 3813498266Sopenharmony_ci exit 2 3913498266Sopenharmony_ci} 4013498266Sopenharmony_ci 4113498266Sopenharmony_ciprint_usage () 4213498266Sopenharmony_ci{ 4313498266Sopenharmony_ci cat <<END 4413498266Sopenharmony_ciUsage: 4513498266Sopenharmony_ci test-driver --test-name NAME --log-file PATH --trs-file PATH 4613498266Sopenharmony_ci [--expect-failure {yes|no}] [--color-tests {yes|no}] 4713498266Sopenharmony_ci [--enable-hard-errors {yes|no}] [--] 4813498266Sopenharmony_ci TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 4913498266Sopenharmony_ci 5013498266Sopenharmony_ciThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 5113498266Sopenharmony_ciSee the GNU Automake documentation for information. 5213498266Sopenharmony_ciEND 5313498266Sopenharmony_ci} 5413498266Sopenharmony_ci 5513498266Sopenharmony_citest_name= # Used for reporting. 5613498266Sopenharmony_cilog_file= # Where to save the output of the test script. 5713498266Sopenharmony_citrs_file= # Where to save the metadata of the test run. 5813498266Sopenharmony_ciexpect_failure=no 5913498266Sopenharmony_cicolor_tests=no 6013498266Sopenharmony_cienable_hard_errors=yes 6113498266Sopenharmony_ciwhile test $# -gt 0; do 6213498266Sopenharmony_ci case $1 in 6313498266Sopenharmony_ci --help) print_usage; exit $?;; 6413498266Sopenharmony_ci --version) echo "test-driver $scriptversion"; exit $?;; 6513498266Sopenharmony_ci --test-name) test_name=$2; shift;; 6613498266Sopenharmony_ci --log-file) log_file=$2; shift;; 6713498266Sopenharmony_ci --trs-file) trs_file=$2; shift;; 6813498266Sopenharmony_ci --color-tests) color_tests=$2; shift;; 6913498266Sopenharmony_ci --expect-failure) expect_failure=$2; shift;; 7013498266Sopenharmony_ci --enable-hard-errors) enable_hard_errors=$2; shift;; 7113498266Sopenharmony_ci --) shift; break;; 7213498266Sopenharmony_ci -*) usage_error "invalid option: '$1'";; 7313498266Sopenharmony_ci *) break;; 7413498266Sopenharmony_ci esac 7513498266Sopenharmony_ci shift 7613498266Sopenharmony_cidone 7713498266Sopenharmony_ci 7813498266Sopenharmony_cimissing_opts= 7913498266Sopenharmony_citest x"$test_name" = x && missing_opts="$missing_opts --test-name" 8013498266Sopenharmony_citest x"$log_file" = x && missing_opts="$missing_opts --log-file" 8113498266Sopenharmony_citest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 8213498266Sopenharmony_ciif test x"$missing_opts" != x; then 8313498266Sopenharmony_ci usage_error "the following mandatory options are missing:$missing_opts" 8413498266Sopenharmony_cifi 8513498266Sopenharmony_ci 8613498266Sopenharmony_ciif test $# -eq 0; then 8713498266Sopenharmony_ci usage_error "missing argument" 8813498266Sopenharmony_cifi 8913498266Sopenharmony_ci 9013498266Sopenharmony_ciif test $color_tests = yes; then 9113498266Sopenharmony_ci # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 9213498266Sopenharmony_ci red='[0;31m' # Red. 9313498266Sopenharmony_ci grn='[0;32m' # Green. 9413498266Sopenharmony_ci lgn='[1;32m' # Light green. 9513498266Sopenharmony_ci blu='[1;34m' # Blue. 9613498266Sopenharmony_ci mgn='[0;35m' # Magenta. 9713498266Sopenharmony_ci std='[m' # No color. 9813498266Sopenharmony_cielse 9913498266Sopenharmony_ci red= grn= lgn= blu= mgn= std= 10013498266Sopenharmony_cifi 10113498266Sopenharmony_ci 10213498266Sopenharmony_cido_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 10313498266Sopenharmony_citrap "st=129; $do_exit" 1 10413498266Sopenharmony_citrap "st=130; $do_exit" 2 10513498266Sopenharmony_citrap "st=141; $do_exit" 13 10613498266Sopenharmony_citrap "st=143; $do_exit" 15 10713498266Sopenharmony_ci 10813498266Sopenharmony_ci# Test script is run here. We create the file first, then append to it, 10913498266Sopenharmony_ci# to ameliorate tests themselves also writing to the log file. Our tests 11013498266Sopenharmony_ci# don't, but others can (automake bug#35762). 11113498266Sopenharmony_ci: >"$log_file" 11213498266Sopenharmony_ci"$@" >>"$log_file" 2>&1 11313498266Sopenharmony_ciestatus=$? 11413498266Sopenharmony_ci 11513498266Sopenharmony_ciif test $enable_hard_errors = no && test $estatus -eq 99; then 11613498266Sopenharmony_ci tweaked_estatus=1 11713498266Sopenharmony_cielse 11813498266Sopenharmony_ci tweaked_estatus=$estatus 11913498266Sopenharmony_cifi 12013498266Sopenharmony_ci 12113498266Sopenharmony_cicase $tweaked_estatus:$expect_failure in 12213498266Sopenharmony_ci 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 12313498266Sopenharmony_ci 0:*) col=$grn res=PASS recheck=no gcopy=no;; 12413498266Sopenharmony_ci 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 12513498266Sopenharmony_ci 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 12613498266Sopenharmony_ci *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 12713498266Sopenharmony_ci *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 12813498266Sopenharmony_ciesac 12913498266Sopenharmony_ci 13013498266Sopenharmony_ci# Report the test outcome and exit status in the logs, so that one can 13113498266Sopenharmony_ci# know whether the test passed or failed simply by looking at the '.log' 13213498266Sopenharmony_ci# file, without the need of also peaking into the corresponding '.trs' 13313498266Sopenharmony_ci# file (automake bug#11814). 13413498266Sopenharmony_ciecho "$res $test_name (exit status: $estatus)" >>"$log_file" 13513498266Sopenharmony_ci 13613498266Sopenharmony_ci# Report outcome to console. 13713498266Sopenharmony_ciecho "${col}${res}${std}: $test_name" 13813498266Sopenharmony_ci 13913498266Sopenharmony_ci# Register the test result, and other relevant metadata. 14013498266Sopenharmony_ciecho ":test-result: $res" > $trs_file 14113498266Sopenharmony_ciecho ":global-test-result: $res" >> $trs_file 14213498266Sopenharmony_ciecho ":recheck: $recheck" >> $trs_file 14313498266Sopenharmony_ciecho ":copy-in-global-log: $gcopy" >> $trs_file 14413498266Sopenharmony_ci 14513498266Sopenharmony_ci# Local Variables: 14613498266Sopenharmony_ci# mode: shell-script 14713498266Sopenharmony_ci# sh-indentation: 2 14813498266Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp) 14913498266Sopenharmony_ci# time-stamp-start: "scriptversion=" 15013498266Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H" 15113498266Sopenharmony_ci# time-stamp-time-zone: "UTC0" 15213498266Sopenharmony_ci# time-stamp-end: "; # UTC" 15313498266Sopenharmony_ci# End: 154