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
33 local is_feature="false"
35 local tester=${GERRIT_USER:-$USER}
38 if [ -z "$WS_ROOT" ] ; then
39 echo "ERROR: WS_ROOT is not set!"
41 elif [ -z "$(find $WS_ROOT -type d -name vppinfra)" ] ; then
42 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
46 options=$(getopt -o "adfg:j:r:" -- "$@")
47 if [ $? -eq 1 ] ; then
52 while [ -z "$usage" ] ; do
67 grep_for="${1//-/\\-}"
72 if [ $((jobs)) != $jobs ] ; then
73 echo "ERROR: Invalid option value for -j option ($jobs)!"
80 if [ $((retry_count)) != $retry_count ] ; then
81 echo "ERROR: Invalid option value for -r option ($retry_count)!"
93 if [ -n "$usage" ] || [ -z "$1" ] ; then
95 echo "ERROR: no testcase specified!"
97 echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-j <jobs>][-r <retry count>] <testcase> [<retry_count>]"
98 echo " -a Run extended tests"
99 echo " -d Run vpp debug image (i.e. with ASSERTS)"
100 echo " -f Testcase is a feature set (e.g. tcp)"
101 echo " -g <text> Text to grep for in log, FAIL on match."
102 echo " Enclose <text> in single quotes when it contains any dashes:"
103 echo " e.g. vpp-make-test -g 'goof-bad-' test_xyz"
104 echo " -j <# jobs> Set TEST_JOBS (default = auto) for feature set"
105 echo " -r <retry count> Retry Count (default = 100 for individual test | 1 for feature set)"
109 if [ $retry_count -le 0 ] ; then
112 if [ "$is_feature" == "true" ] ; then
113 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs"
115 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
120 line="------------------------------------------------------------------------------"
121 test_desc="'$run_make_test'"
122 if [ -n "$grep_for" ] ; then
123 test_desc="$test_desc [grep '$show_grep']"
125 for ((i=1; i<=retry_count; i++)) ; do
127 echo -e "ITERATION [$i/$retry_count]: $test_desc\n$line"
128 result=$($run_make_test)
129 if [ ! -d /tmp/vpp-unittest* ] ; then
130 echo -e "\nERROR: No testcase(s) executed!\n"
134 if [ -n "$grep_for" ] ; then
135 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
137 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
138 if [ -n "$grep_results" ] ; then
143 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
148 echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
149 echo -e "Hey $tester, Life is good!!! :D\n"