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
18 # Bash function to run vpp 'make test' testcases
19 # repeatedly, stopping on test failure or when
20 # a test log contains the optionally specified text
32 local is_feature="false"
34 local tester=${GERRIT_USER:-$USER}
37 if [ -z "$WS_ROOT" ] ; then
38 echo "ERROR: WS_ROOT is not set!"
40 elif [ ! -d "$WS_ROOT/src/vppinfra" ] ; then
41 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
45 options=$(getopt -o "adfg:j:r:" -- "$@")
46 if [ $? -eq 1 ] ; then
51 while [ -z "$usage" ] ; do
66 grep_for="${1//-/\\-}"
71 if [ $((jobs)) != $jobs ] ; then
72 echo "ERROR: Invalid option value for -j option ($jobs)!"
79 if [ $((retry_count)) != $retry_count ] ; then
80 echo "ERROR: Invalid option value for -r option ($retry_count)!"
92 if [ -n "$usage" ] || [ -z "$1" ] ; then
94 echo "ERROR: no testcase specified!"
96 echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-j <jobs>][-r <retry count>] <testcase> [<retry_count>]"
97 echo " -a Run extended tests"
98 echo " -d Run vpp debug image (i.e. with ASSERTS)"
99 echo " -f Testcase is a feature set (e.g. tcp)"
100 echo " -g <text> Text to grep for in log, FAIL on match."
101 echo " Enclose <text> in single quotes when it contains any dashes:"
102 echo " e.g. vpp-make-test -g 'goof-bad-' test_xyz"
103 echo " -j <# jobs> Set TEST_JOBS (default = auto) for feature set"
104 echo " -r <retry count> Retry Count (default = 100 for individual test | 1 for feature set)"
108 if [ $retry_count -le 0 ] ; then
111 if [ "$is_feature" == "true" ] ; then
112 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs"
114 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
119 line="------------------------------------------------------------------------------"
120 test_desc="'$run_make_test'"
121 if [ -n "$grep_for" ] ; then
122 test_desc="$test_desc [grep '$show_grep']"
124 for ((i=1; i<=retry_count; i++)) ; do
126 echo -e "ITERATION [$i/$retry_count]: $test_desc\n$line"
127 result=$($run_make_test)
128 if [ ! -d /tmp/vpp-unittest* ] ; then
129 echo -e "\nERROR: No testcase(s) executed!\n"
133 if [ -n "$grep_for" ] ; then
134 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
136 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
137 if [ -n "$grep_results" ] ; then
142 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
147 echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
148 echo -e "Hey $tester, Life is good!!! :D\n"
152 # bash function to set up csit python virtual environment
155 if [ -f "$WS_ROOT/VPP_REPO_URL" ] && [ -f "$WS_ROOT/requirements.txt" ]; then
156 if [ -n "$(declare -f deactivate)" ]; then
157 echo "Deactivating Python Virtualenv!"
161 local setup_framework=$WS_ROOT/resources/libraries/python/SetupFramework.py
162 if [ -n "$(grep pip3 $setup_framework)" ]; then
164 local VENV_OPTS="-p python3"
166 export CSIT_DIR=$WS_ROOT
167 export PYTHONPATH=$CSIT_DIR
168 rm -rf $PYTHONPATH/env && virtualenv $VENV_OPTS $PYTHONPATH/env \
169 && source $PYTHONPATH/env/bin/activate \
170 && $PIP install --upgrade -r $PYTHONPATH/requirements.txt \
171 && $PIP install --upgrade -r $PYTHONPATH/tox-requirements.txt
173 echo "ERROR: WS_ROOT not set to a CSIT workspace!"
177 # bash function to set up jenkins sandbox environment
179 # See LF Sandbox documentation:
180 # https://docs.releng.linuxfoundation.org/en/latest/jenkins-sandbox.html
183 # 1. Create jenkins sandbox token and add it to your local jenkins.ini file
184 # Either specify the location of the init file in $JENKINS_INI or
185 # JENKINS_INI will be initialized to either
186 # ~/.config/jenkins_jobs/jenkins.ini
187 # $WS_ROOT/jenkins.ini
188 # 2. Clone ci-management workspace from gerrit.fd.io
189 # 3. export WS_ROOT=<local ci-management workspace>
192 if [ -z "$WS_ROOT" ] ; then
193 echo "ERROR: WS_ROOT is not set!"
195 elif [ ! -d "$WS_ROOT/jjb" ] ; then
196 echo "ERROR: WS_ROOT is not set to a ci-management workspace!"
200 if [ -n "$(declare -f deactivate)" ]; then
201 echo "Deactivating Python Virtualenv!"
205 if [ -z "$JENKINS_INI" ] ; then
206 local user_jenkins_ini="/home/$USER/.config/jenkins_jobs/jenkins.ini"
207 if [ -f "$user_jenkins_ini" ] ; then
208 export JENKINS_INI=$user_jenkins_ini
209 elif [ -f "$WS_ROOT/jenkins.ini" ] ; then
210 export JENKINS_INI="$WS_ROOT/jenkins.ini"
212 echo "ERROR: Unable to find 'jenkins.ini'!"
215 echo "Exporting JENKINS_INI=$JENKINS_INI"
216 elif [ ! -f "$JENKINS_INI" ] ; then
217 echo "ERROR: file specified in JENKINS_INI ($JENKINS_INI) not found!"
221 if [ -n "$(declare -f deactivate)" ]; then
222 echo "Deactivating Python Virtualenv!"
226 git submodule update --init --recursive
228 local VENV_DIR=$WS_ROOT/venv
230 && python3 -m venv $VENV_DIR \
231 && source $VENV_DIR/bin/activate \
232 && pip3 install wheel \
233 && pip3 install jenkins-job-builder==3.0.2
235 alias jjsb='jenkins-jobs --conf $JENKINS_INI'
236 function jjsb-test() {
237 if [ -z "$(which jenkins-jobs 2>&1)" ] ; then
238 echo "jenkins-jobs not found! Run jjb-sandbox-env to activate."
241 if [ -z "$1" ] ; then
242 echo "Usage: $FUNCNAME <jenkins-job-name>"
246 && jenkins-jobs --conf $JENKINS_INI test $WS_ROOT/jjb $@
248 function jjsb-update() {
249 if [ -z "$(which jenkins-jobs 2>&1)" ] ; then
250 echo "jenkins-jobs not found! Run jjb-sandbox-env to activate."
253 if [ -z "$1" ] ; then
254 echo "Usage: $FUNCNAME <jenkins-job-name>"
258 && jenkins-jobs --conf $JENKINS_INI update $WS_ROOT/jjb $@
260 jenkins-jobs --version