Home | History | Annotate | Line # | Download | only in system
      1      1.1  christos #!/bin/sh
      2      1.1  christos 
      3      1.1  christos # test-driver - basic testsuite driver script.
      4      1.1  christos 
      5      1.1  christos scriptversion=2021-09-20.08 # UTC
      6      1.1  christos 
      7      1.1  christos # Copyright (C) 2011-2020 Free Software Foundation, Inc.
      8      1.1  christos #
      9  1.1.1.2  christos # SPDX-License-Identifier: GPL-2.0-or-later WITH Autoconf-exception-generic
     10      1.1  christos #
     11      1.1  christos # This program is free software; you can redistribute it and/or modify
     12      1.1  christos # it under the terms of the GNU General Public License as published by
     13      1.1  christos # the Free Software Foundation; either version 2, or (at your option)
     14      1.1  christos # any later version.
     15      1.1  christos #
     16      1.1  christos # This program is distributed in the hope that it will be useful,
     17      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     18      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19      1.1  christos # GNU General Public License for more details.
     20      1.1  christos #
     21      1.1  christos # You should have received a copy of the GNU General Public License
     22      1.1  christos # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     23      1.1  christos 
     24      1.1  christos # As a special exception to the GNU General Public License, if you
     25      1.1  christos # distribute this file as part of a program that contains a
     26      1.1  christos # configuration script generated by Autoconf, you may include it under
     27      1.1  christos # the same distribution terms that you use for the rest of that program.
     28      1.1  christos 
     29      1.1  christos # This file is maintained in Automake, please report
     30      1.1  christos # bugs to <bug-automake (at] gnu.org> or send patches to
     31      1.1  christos # <automake-patches (at] gnu.org>.
     32      1.1  christos 
     33      1.1  christos # Make unconditional expansion of undefined variables an error.  This
     34      1.1  christos # helps a lot in preventing typo-related bugs.
     35      1.1  christos set -u
     36      1.1  christos 
     37      1.1  christos usage_error() {
     38      1.1  christos   echo "$0: $*" >&2
     39      1.1  christos   print_usage >&2
     40      1.1  christos   exit 2
     41      1.1  christos }
     42      1.1  christos 
     43      1.1  christos print_usage() {
     44      1.1  christos   cat <<END
     45      1.1  christos Usage:
     46      1.1  christos   test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
     47      1.1  christos               [--expect-failure={yes|no}] [--color-tests={yes|no}]
     48      1.1  christos               [--enable-hard-errors={yes|no}] [--]
     49      1.1  christos               TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
     50      1.1  christos The '--test-name', '--log-file' and '--trs-file' options are mandatory.
     51      1.1  christos END
     52      1.1  christos }
     53      1.1  christos 
     54      1.1  christos test_name=  # Used for reporting.
     55      1.1  christos log_file=   # Where to save the output of the test script.
     56      1.1  christos trs_file=   # Where to save the metadata of the test run.
     57      1.1  christos junit_file= # Where to save pytest junit output.
     58      1.1  christos expect_failure=no
     59      1.1  christos color_tests=no
     60      1.1  christos enable_hard_errors=yes
     61      1.1  christos verbose=no
     62      1.1  christos while test $# -gt 0; do
     63      1.1  christos   case $1 in
     64      1.1  christos     --help)
     65      1.1  christos       print_usage
     66      1.1  christos       exit $?
     67      1.1  christos       ;;
     68      1.1  christos     --version)
     69      1.1  christos       echo "test-driver $scriptversion"
     70      1.1  christos       exit $?
     71      1.1  christos       ;;
     72      1.1  christos     --test-name)
     73      1.1  christos       test_name=$2
     74      1.1  christos       shift
     75      1.1  christos       ;;
     76      1.1  christos     --log-file)
     77      1.1  christos       log_file=$2
     78      1.1  christos       shift
     79      1.1  christos       ;;
     80      1.1  christos     --trs-file)
     81      1.1  christos       trs_file=$2
     82      1.1  christos       junit_file=$(echo $trs_file | sed 's/\.trs$/\.xml/')
     83      1.1  christos       shift
     84      1.1  christos       ;;
     85      1.1  christos     --color-tests)
     86      1.1  christos       color_tests=$2
     87      1.1  christos       shift
     88      1.1  christos       ;;
     89      1.1  christos     --expect-failure)
     90      1.1  christos       expect_failure=$2
     91      1.1  christos       shift
     92      1.1  christos       ;;
     93      1.1  christos     --enable-hard-errors)
     94      1.1  christos       enable_hard_errors=$2
     95      1.1  christos       shift
     96      1.1  christos       ;;
     97      1.1  christos     --verbose)
     98      1.1  christos       verbose=$2
     99      1.1  christos       shift
    100      1.1  christos       ;;
    101      1.1  christos     --)
    102      1.1  christos       shift
    103      1.1  christos       break
    104      1.1  christos       ;;
    105      1.1  christos     -*) usage_error "invalid option: '$1'" ;;
    106      1.1  christos     *) break ;;
    107      1.1  christos   esac
    108      1.1  christos   shift
    109      1.1  christos done
    110      1.1  christos 
    111      1.1  christos missing_opts=
    112      1.1  christos test x"$test_name" = x && missing_opts="$missing_opts --test-name"
    113      1.1  christos test x"$log_file" = x && missing_opts="$missing_opts --log-file"
    114      1.1  christos test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
    115      1.1  christos if test x"$missing_opts" != x; then
    116      1.1  christos   usage_error "the following mandatory options are missing:$missing_opts"
    117      1.1  christos fi
    118      1.1  christos 
    119      1.1  christos if test $# -eq 0; then
    120      1.1  christos   usage_error "missing argument"
    121      1.1  christos fi
    122      1.1  christos 
    123      1.1  christos if test $color_tests = yes; then
    124      1.1  christos   # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
    125      1.1  christos   red='[0;31m' # Red.
    126      1.1  christos   grn='[0;32m' # Green.
    127      1.1  christos   lgn='[1;32m' # Light green.
    128      1.1  christos   blu='[1;34m' # Blue.
    129      1.1  christos   mgn='[0;35m' # Magenta.
    130      1.1  christos   std='[m'     # No color.
    131      1.1  christos else
    132      1.1  christos   red= grn= lgn= blu= mgn= std=
    133      1.1  christos fi
    134      1.1  christos 
    135      1.1  christos do_exit='rm -f $log_file $trs_file $junit_file; (exit $st); exit $st'
    136      1.1  christos trap "st=129; $do_exit" 1
    137      1.1  christos trap "st=130; $do_exit" 2
    138      1.1  christos trap "st=141; $do_exit" 13
    139      1.1  christos trap "st=143; $do_exit" 15
    140      1.1  christos 
    141      1.1  christos # Test script is run here.
    142      1.1  christos if test $verbose = yes; then
    143      1.1  christos   "$@" --junit-xml $PWD/$junit_file 2>&1 | tee $log_file
    144      1.1  christos else
    145      1.1  christos   "$@" --junit-xml $PWD/$junit_file >$log_file 2>&1
    146      1.1  christos fi
    147      1.1  christos 
    148      1.1  christos # Run junit to trs converter script.
    149  1.1.1.3  christos ./convert_junit_to_trs.py $junit_file >$trs_file
    150      1.1  christos estatus=$?
    151      1.1  christos 
    152      1.1  christos if test $enable_hard_errors = no && test $estatus -eq 99; then
    153      1.1  christos   tweaked_estatus=1
    154      1.1  christos else
    155      1.1  christos   tweaked_estatus=$estatus
    156      1.1  christos fi
    157      1.1  christos 
    158      1.1  christos case $tweaked_estatus:$expect_failure in
    159      1.1  christos   0:yes) col=$red res=XPASS recheck=yes gcopy=yes ;;
    160      1.1  christos   0:*) col=$grn res=PASS recheck=no gcopy=no ;;
    161      1.1  christos   77:*) col=$blu res=SKIP recheck=no gcopy=yes ;;
    162      1.1  christos   99:*) col=$mgn res=ERROR recheck=yes gcopy=yes ;;
    163      1.1  christos   *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes ;;
    164      1.1  christos   *:*) col=$red res=FAIL recheck=yes gcopy=yes ;;
    165      1.1  christos esac
    166      1.1  christos 
    167      1.1  christos # Report the test outcome and exit status in the logs, so that one can
    168      1.1  christos # know whether the test passed or failed simply by looking at the '.log'
    169      1.1  christos # file, without the need of also peaking into the corresponding '.trs'
    170      1.1  christos # file (automake bug#11814).
    171      1.1  christos echo "$res $test_name (exit status: $estatus)" >>$log_file
    172      1.1  christos 
    173      1.1  christos # Report outcome to console.
    174      1.1  christos echo "${col}${res}${std}: $test_name"
    175      1.1  christos 
    176      1.1  christos # Register other relevant test metadata.
    177      1.1  christos echo ":global-test-result: $res" >>$trs_file
    178      1.1  christos echo ":recheck: $recheck" >>$trs_file
    179      1.1  christos echo ":copy-in-global-log: $gcopy" >>$trs_file
    180      1.1  christos 
    181      1.1  christos # Local Variables:
    182      1.1  christos # mode: shell-script
    183      1.1  christos # sh-indentation: 2
    184      1.1  christos # eval: (add-hook 'before-save-hook 'time-stamp)
    185      1.1  christos # time-stamp-start: "scriptversion="
    186      1.1  christos # time-stamp-format: "%:y-%02m-%02d.%02H"
    187      1.1  christos # time-stamp-time-zone: "UTC0"
    188      1.1  christos # time-stamp-end: "; # UTC"
    189      1.1  christos # End:
    190