1#!/bin/sh 2# 3# Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, You can obtain one at http://mozilla.org/MPL/2.0/. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15# PERFORMANCE OF THIS SOFTWARE. 16# 17# Script used to execute unit tests described by the Atffile in the current 18# directory. It exits with return value of atf-run, which will be 0 if all 19# tests passed, non-zero otherwise. 20# 21 22# Add configured path to ATF tools, atf-run and atf-report 23PATH="@ATF_BIN@:${PATH}" 24export PATH 25ATFRUN=`type atf-run 2>/dev/null | awk '{print $3}'` 26KYUA=`type kyua 2>/dev/null | awk '{print $3}'` 27 28# colors if not outputting to a dumb terminal and stdout is a tty 29if test "$TERM" != dumb && { test -t 1; } 2>/dev/null; then \ 30 red='\033[0;31m' 31 green='\033[0;32m' 32 noclr='\033[0m' 33 34 # if echo supports -e, we must use it to set colors 35 # (output will be "" if its supported) 36 if [ -z "`echo -e`" ] 37 then 38 dash_e="-e" 39 fi 40fi; 41 42header="====================================================" 43 44status=0 45if [ -n "@UNITTESTS@" -a -x "$ATFRUN" -a -f Atffile ] 46then 47 # run the tests 48 echo "Running unit tests..." 49 atf-run > atf.out 50 status=$? 51 52 # set color based on success/failure 53 if [ $status -eq 0 ] 54 then 55 color=$green 56 else 57 color=$red 58 fi 59 60 # spit out the test report 61 # We print everything upto the summary in 62 # "no color". Print the summary in our 63 # result color. 64 cat atf.out | atf-report | while read line 65 do 66 cnt=`echo $line | grep -c "Summary"` 67 if [ $cnt -eq 1 ] 68 then 69 echo $dash_e $color$header 70 fi 71 echo $line; 72 done 73 echo $dash_e $header$noclr 74 75 # clean up unless there were test failures 76 if [ $status -eq 0 ] 77 then 78 rm -f atf.out 79 fi 80elif [ -n "@UNITTESTS@" -a -x "$KYUA" -a -f Kyuafile ] 81then 82 echo "Running unit tests..." 83 kyua --logfile kyua.log test 84 status=$? 85 86 kyua report 87 88 if [ $status -eq 0 ] 89 then 90 rm -f kyua.log 91 fi 92fi 93exit $status 94