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