1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
15 # This file is meant to be sourced in a .bashrc file to add useful
16 # bash functions to an interactive shell
19 # Bash function to run vpp 'make test' testcases
20 # repeatedly, stopping on test failure or when
21 # a test log contains the optionally specified text
31 local is_feature="false"
33 local tester=${GERRIT_USER:-$USER}
35 if [ -z "$WS_ROOT" ] ; then
36 echo "ERROR: WS_ROOT is not set!"
38 elif [ -z "$(find $WS_ROOT -type d -name vppinfra)" ] ; then
39 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
43 options=$(getopt -o "adfg:r:" -- "$@")
44 if [ $? -eq 1 ] ; then
49 while [ -z "$usage" ] ; do
64 grep_for="${1//-/\\-}"
69 if [ $((retry_count)) != $retry_count ] ; then
70 echo "ERROR: Invalid option value for -r option ($retry_count)!"
82 if [ -n "$usage" ] || [ -z "$1" ] ; then
84 echo "ERROR: no testcase specified!"
86 echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-r <retry count>] <testcase> [<retry_count>]"
87 echo " -a Run extended tests"
88 echo " -d Run vpp debug image (i.e. with ASSERTS)"
89 echo " -f Testcase is a feature set (e.g. tcp)"
90 echo " -g <text> Text to grep for in log, FAIL on match."
91 echo " Enclose <text> in single quotes when it contains any dashes:"
92 echo " e.g. vpp-make-test -g 'goof-bad-' test_xyz"
93 echo " -r <retry count> Retry Count (default = 100 for individual | 1 for feature)"
97 if [ $retry_count -le 0 ] ; then
100 if [ "$is_feature" == "true" ] ; then
101 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=auto"
103 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
108 line="------------------------------------------------------------------------------"
109 local test_desc="'$run_make_test'"
110 if [ -n "$grep_for" ] ; then
111 test_desc="$test_desc [grep $show_grep]"
113 for ((i=1; i<=retry_count; i++)) ; do
115 echo -e "ITERATION [$i/$retry_count]: $test_desc\n$line"
116 result=$($run_make_test)
117 if [ ! -d /tmp/vpp-unittest* ] ; then
118 echo -e "\nERROR: No testcase(s) executed!\n"
122 if [ -n "$grep_for" ] ; then
123 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
125 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
126 if [ -n "$grep_results" ] ; then
131 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
136 echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
137 echo -e "Hey $tester, Life is good!!! :D\n"
140 export -f vpp-make-test