#!/bin/bash # ffoo test harness # See LICENSE file for copyright and license details. . $TF_DIR/include/common.sh # # Default path to header generator # __TF_HDRCMD="$TF_SUITE/TF_HEADER" __tf_collect_if_needed() { # # Collect artifact if exit status suggests it # # Use test exit status $1 to help decide if artifacts are # needed, and collect them if so. # # If TF_COLLECT is set to "always", collect regardless of # the status. If set to "never", do not collect anything. # The default setting, "auto" collects unless status is 0 # or 1 (pass or bailout); in that case do nothing. # local tes=$1 # test exit status local will # should we collect artifacts? case "$TF_COLLECT:$tes" in always:*) will=true ;; never:*) will=false ;; auto:0) will=false ;; auto:2) will=false ;; auto:*) will=true ;; *) tf_exit_bailout "bad value of TF_COLLECT: $TF_COLLECT" ;; esac $will || return 0 mkdir -p "$artifact_dir/$stamp" cp -r $tmpdir/* "$artifact_dir/$stamp" } __tf_default_header() { # # Create default header # echo "(add $__TF_HDRCMD executable for own header)" } __tf_header() { # # create header to add to output before test # local field local hdrcmd="$__TF_HDRCMD" test -x "$hdrcmd" || hdrcmd="__tf_default_header" $hdrcmd \ | while read field; do test -n "$field" || break tf_think "# $field" done tf_think "" } tf_enum_tests() { # # List what looks like test; relative to $TF_SUITE # tf_debug "TF_SUITE='$TF_SUITE'" test -d $TF_SUITE || return 0 find -L \ $TF_SUITE \ -mindepth 2 \ -maxdepth 2 \ -type f \ -perm /111 \ -name TF_RUN \ | cut -d/ -f2 } tf_run_tests() { # # Discover and run tests # local es=0 # overall exit status local tmpdir="" # test temporary dir local tname="" # test name local tes=0 # test result local stamp="" # test stamp to use as artifact name local tf_dir tf_suite # to keep absolute paths for TF_RUN local artifact_dir="$(readlink -f "$TF_ARTIFACTS")" __tf_header tf_dir="$(readlink -f "$TF_DIR")" tf_suite="$(readlink -f "$TF_SUITE")" es=0 for tname in $(tf_enum_tests | grep -e "$TF_FILTER_TEST"); do tf_think "... $tname" tmpdir=$(mktemp -d) stamp=$(date +artifacts-$tname-%Y%m%d-%H%M%S) cp -r "$TF_SUITE/$tname/"* "$tmpdir" pushd $tmpdir >/dev/null TF_DIR="$tf_dir" TF_SUITE=$tf_suite TF_TNAME="$tname" \ ./TF_RUN tes=$? __tf_collect_if_needed $tes test $tes -gt $es && es=$tes popd >/dev/null rm -rf $tmpdir if test $tes -eq 0; then tf_think "''' $tname ($tes)" else tf_warn "??? $tname ($tes)" fi done return $es }