blob: 597b749a94dd16f0b493fbc1e27b10d848cca93f [file] [log] [blame]
Dave Wallace535fdba2019-11-19 18:49:49 -05001# 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:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
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.
13
14
15# This file is meant to be sourced in a .bashrc file to add useful
16# bash functions to an interactive shell
17
18
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
22vpp-make-test()
23{
24 local options
25 local usage
26 local all
27 local debug
28 local grep_for
Dave Wallaceb4f073c2019-12-18 14:06:31 -050029 local show_grep
Dave Wallace535fdba2019-11-19 18:49:49 -050030 local run_make_test
31 local old_pwd
Dave Wallaceb4f073c2019-12-18 14:06:31 -050032 local test_desc
Dave Wallace535fdba2019-11-19 18:49:49 -050033 local is_feature="false"
34 local retry_count=100
35 local tester=${GERRIT_USER:-$USER}
Dave Wallaceb4f073c2019-12-18 14:06:31 -050036 local jobs="auto"
Dave Wallace535fdba2019-11-19 18:49:49 -050037
38 if [ -z "$WS_ROOT" ] ; then
39 echo "ERROR: WS_ROOT is not set!"
40 return
41 elif [ -z "$(find $WS_ROOT -type d -name vppinfra)" ] ; then
42 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
43 return
44 fi
45
Dave Wallaceb4f073c2019-12-18 14:06:31 -050046 options=$(getopt -o "adfg:j:r:" -- "$@")
Dave Wallace535fdba2019-11-19 18:49:49 -050047 if [ $? -eq 1 ] ; then
48 usage=true
49 else
50 eval set -- $options
51 fi
52 while [ -z "$usage" ] ; do
53 case "$1" in
54 -a)
55 all="-all"
56 ;;
57 -d)
58 debug="-debug"
59 ;;
60 -f)
61 is_feature="true"
62 retry_count=1
63 ;;
64 -g)
65 shift
66 show_grep=$1
67 grep_for="${1//-/\\-}"
68 ;;
Dave Wallaceb4f073c2019-12-18 14:06:31 -050069 -j)
70 shift
71 jobs=$1
72 if [ $((jobs)) != $jobs ] ; then
73 echo "ERROR: Invalid option value for -j option ($jobs)!"
74 usage=true;
75 fi
76 ;;
Dave Wallace535fdba2019-11-19 18:49:49 -050077 -r)
78 shift
79 retry_count=$1
80 if [ $((retry_count)) != $retry_count ] ; then
81 echo "ERROR: Invalid option value for -r option ($retry_count)!"
82 usage=true;
83 fi
84 ;;
85 --)
86 shift
87 break
88 ;;
89 esac
90 shift
91 done
92
93 if [ -n "$usage" ] || [ -z "$1" ] ; then
94 if [ -z "$1" ] ; then
95 echo "ERROR: no testcase specified!"
96 fi
Dave Wallaceb4f073c2019-12-18 14:06:31 -050097 echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-j <jobs>][-r <retry count>] <testcase> [<retry_count>]"
Dave Wallace535fdba2019-11-19 18:49:49 -050098 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"
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500104 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)"
Dave Wallace535fdba2019-11-19 18:49:49 -0500106 return
107 fi
108
109 if [ $retry_count -le 0 ] ; then
110 retry_count=1
111 fi
112 if [ "$is_feature" == "true" ] ; then
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500113 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs"
Dave Wallace535fdba2019-11-19 18:49:49 -0500114 else
115 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
116 fi
117
118 old_pwd=$(pwd)
119 cd $WS_ROOT
120 line="------------------------------------------------------------------------------"
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500121 test_desc="'$run_make_test'"
Dave Wallace535fdba2019-11-19 18:49:49 -0500122 if [ -n "$grep_for" ] ; then
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500123 test_desc="$test_desc [grep '$show_grep']"
Dave Wallace535fdba2019-11-19 18:49:49 -0500124 fi
125 for ((i=1; i<=retry_count; i++)) ; do
126 echo -e "\n$line"
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"
131 return
132 fi
133 echo "$result"
134 if [ -n "$grep_for" ] ; then
135 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
136 fi
137 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
138 if [ -n "$grep_results" ] ; then
139 fail="FAIL (grep)"
140 else
141 fail="FAIL"
142 fi
143 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
144 return
145 fi
146 done
147
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"
150 cd $old_pwd
151}