blob: 777dd947bb054c57d9c6a9ebc2ad624a1d82b283 [file] [log] [blame]
Dave Wallaced7b9af42021-01-14 15:03:07 -05001# Copyright (c) 2021 Cisco and/or its affiliates.
Dave Wallace535fdba2019-11-19 18:49:49 -05002# 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
Dave Wallace535fdba2019-11-19 18:49:49 -050018# 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
21vpp-make-test()
22{
23 local options
24 local usage
25 local all
26 local debug
27 local grep_for
Dave Wallaceb4f073c2019-12-18 14:06:31 -050028 local show_grep
Dave Wallace535fdba2019-11-19 18:49:49 -050029 local run_make_test
30 local old_pwd
Dave Wallaceb4f073c2019-12-18 14:06:31 -050031 local test_desc
Dave Wallace78545882021-05-19 17:01:55 -040032 local grep_results
33 local result
34 local fail
35 local i
36 local line
Dave Wallace535fdba2019-11-19 18:49:49 -050037 local is_feature="false"
38 local retry_count=100
39 local tester=${GERRIT_USER:-$USER}
Dave Wallaceb4f073c2019-12-18 14:06:31 -050040 local jobs="auto"
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +000041
Dave Wallace535fdba2019-11-19 18:49:49 -050042 if [ -z "$WS_ROOT" ] ; then
Dave Wallace78545882021-05-19 17:01:55 -040043 if [ -d "./extras/bash" ] ; then
44 export WS_ROOT="$(pwd)"
45 else
46 echo "ERROR: WS_ROOT is not set!"
47 return
48 fi
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +000049 elif [ ! -d "$WS_ROOT/src/vppinfra" ] ; then
Dave Wallace535fdba2019-11-19 18:49:49 -050050 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
51 return
52 fi
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +000053
Dave Wallaceb4f073c2019-12-18 14:06:31 -050054 options=$(getopt -o "adfg:j:r:" -- "$@")
Dave Wallace535fdba2019-11-19 18:49:49 -050055 if [ $? -eq 1 ] ; then
56 usage=true
57 else
58 eval set -- $options
59 fi
60 while [ -z "$usage" ] ; do
61 case "$1" in
62 -a)
63 all="-all"
64 ;;
65 -d)
66 debug="-debug"
67 ;;
68 -f)
69 is_feature="true"
70 retry_count=1
71 ;;
72 -g)
73 shift
74 show_grep=$1
75 grep_for="${1//-/\\-}"
76 ;;
Dave Wallaceb4f073c2019-12-18 14:06:31 -050077 -j)
78 shift
79 jobs=$1
80 if [ $((jobs)) != $jobs ] ; then
81 echo "ERROR: Invalid option value for -j option ($jobs)!"
82 usage=true;
83 fi
84 ;;
Dave Wallace535fdba2019-11-19 18:49:49 -050085 -r)
86 shift
87 retry_count=$1
88 if [ $((retry_count)) != $retry_count ] ; then
89 echo "ERROR: Invalid option value for -r option ($retry_count)!"
90 usage=true;
91 fi
92 ;;
93 --)
94 shift
95 break
96 ;;
97 esac
98 shift
99 done
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +0000100
Dave Wallace535fdba2019-11-19 18:49:49 -0500101 if [ -n "$usage" ] || [ -z "$1" ] ; then
102 if [ -z "$1" ] ; then
103 echo "ERROR: no testcase specified!"
104 fi
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500105 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 -0500106 echo " -a Run extended tests"
107 echo " -d Run vpp debug image (i.e. with ASSERTS)"
108 echo " -f Testcase is a feature set (e.g. tcp)"
109 echo " -g <text> Text to grep for in log, FAIL on match."
110 echo " Enclose <text> in single quotes when it contains any dashes:"
111 echo " e.g. vpp-make-test -g 'goof-bad-' test_xyz"
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500112 echo " -j <# jobs> Set TEST_JOBS (default = auto) for feature set"
113 echo " -r <retry count> Retry Count (default = 100 for individual test | 1 for feature set)"
Dave Wallace535fdba2019-11-19 18:49:49 -0500114 return
115 fi
116
117 if [ $retry_count -le 0 ] ; then
118 retry_count=1
119 fi
120 if [ "$is_feature" == "true" ] ; then
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500121 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs"
Dave Wallace535fdba2019-11-19 18:49:49 -0500122 else
123 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
124 fi
125
126 old_pwd=$(pwd)
127 cd $WS_ROOT
128 line="------------------------------------------------------------------------------"
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500129 test_desc="'$run_make_test'"
Dave Wallace535fdba2019-11-19 18:49:49 -0500130 if [ -n "$grep_for" ] ; then
Dave Wallaceb4f073c2019-12-18 14:06:31 -0500131 test_desc="$test_desc [grep '$show_grep']"
Dave Wallace535fdba2019-11-19 18:49:49 -0500132 fi
133 for ((i=1; i<=retry_count; i++)) ; do
134 echo -e "\n$line"
135 echo -e "ITERATION [$i/$retry_count]: $test_desc\n$line"
136 result=$($run_make_test)
137 if [ ! -d /tmp/vpp-unittest* ] ; then
138 echo -e "\nERROR: No testcase(s) executed!\n"
139 return
140 fi
141 echo "$result"
142 if [ -n "$grep_for" ] ; then
143 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
144 fi
145 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
146 if [ -n "$grep_results" ] ; then
147 fail="FAIL (grep)"
148 else
149 fail="FAIL"
150 fi
151 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
152 return
153 fi
154 done
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +0000155
Dave Wallace535fdba2019-11-19 18:49:49 -0500156 echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
157 echo -e "Hey $tester, Life is good!!! :D\n"
158 cd $old_pwd
159}
Andrew Yourtchenkobe360ee2020-04-29 16:48:24 +0000160
161# bash function to set up csit python virtual environment
162csit-env()
163{
164 if [ -f "$WS_ROOT/VPP_REPO_URL" ] && [ -f "$WS_ROOT/requirements.txt" ]; then
165 if [ -n "$(declare -f deactivate)" ]; then
166 echo "Deactivating Python Virtualenv!"
167 deactivate
168 fi
169 local PIP=pip
170 local setup_framework=$WS_ROOT/resources/libraries/python/SetupFramework.py
171 if [ -n "$(grep pip3 $setup_framework)" ]; then
172 PIP=pip3
173 local VENV_OPTS="-p python3"
174 fi
175 export CSIT_DIR=$WS_ROOT
176 export PYTHONPATH=$CSIT_DIR
177 rm -rf $PYTHONPATH/env && virtualenv $VENV_OPTS $PYTHONPATH/env \
178 && source $PYTHONPATH/env/bin/activate \
179 && $PIP install --upgrade -r $PYTHONPATH/requirements.txt \
180 && $PIP install --upgrade -r $PYTHONPATH/tox-requirements.txt
181 else
182 echo "ERROR: WS_ROOT not set to a CSIT workspace!"
183 fi
184}
Dave Wallaceab755a32021-05-19 21:47:00 -0400185
186# bash function to set up VPP workspace with quicly source code
187set-quicly-ws ()
188{
189 local ext_quicly_version_file="/opt/vpp/external/x86_64/include/quicly/version.h"
190 if [ ! -f "$ext_quicly_version_file" ] ; then
191 echo -e "\nCannot find quicly version file: $ext_quicly_version_file"
192 echo -e "\nPlease run VPP 'make install-ext-deps' to install it."
193 return
194 fi
195
196 if [ -d "$1" ]; then
197 if [ -z "$WS_ROOT" ] ; then
198 if [ -d "./extras/bash" ] ; then
199 export WS_ROOT="$(pwd)"
200 else
201 echo "ERROR: WS_ROOT is not set!"
202 return
203 fi
204 elif [ ! -d "$WS_ROOT/extras/bash" ] ; then
205 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
206 return
207 fi
208 export WS_QUICLY="$1"
209 export QUICLY_LIBRARY="$WS_QUICLY/libquicly.a"
210 export QUICLY_INCLUDE_DIR="$WS_QUICLY/include"
211 export WS_PICOTLS="$WS_QUICLY/deps/picotls"
212 export PICOTLS_INCLUDE_DIR="$WS_PICOTLS/include"
213 export PICOTLS_CORE_LIBRARY="$WS_PICOTLS/libpicotls-core.a"
214 export PICOTLS_OPENSSL_LIBRARY="$WS_PICOTLS/libpicotls-openssl.a"
215 export VPP_EXTRA_CMAKE_ARGS="-DQUICLY_LIBRARY=$QUICLY_LIBRARY -DQUICLY_INCLUDE_DIR=$QUICLY_INCLUDE_DIR -DPICOTLS_CORE_LIBRARY=$PICOTLS_CORE_LIBRARY -DPICOTLS_OPENSSL_LIBRARY=$PICOTLS_OPENSSL_LIBRARY -DPICOTLS_INCLUDE_DIR=$PICOTLS_INCLUDE_DIR"
216 local quicly_ws_version_file="$QUICLY_INCLUDE_DIR/quicly/version.h"
217 cp -f $ext_quicly_version_file $quicly_ws_version_file
218 local expected_quicly_version="$(grep 'set(EXPECTED_QUICLY_VERSION' $WS_ROOT/src/plugins/quic/CMakeLists.txt | cut -d'"' -f2)"
219 sed -ie "s/LIBQUICLY_VERSION \".*\"/LIBQUICLY_VERSION \"$expected_quicly_version\"/" $quicly_ws_version_file
220 else
221 echo -e "\nUsage: set-quicly-ws <path-to-quicly>"
222 echo -e "\nPrerequisites:"
223 echo -e "\n1. Clone quicly repo:\n git clone https://github.com/h2o/quicly"
224 echo -e "\n2. Build quicly and picotls following instructions in:"
225 echo " .../quicly/README.md"
226 echo " .../quicly/deps/picotls/README.md"
227 echo -e "\n3. Run set-quicly-ws <path-to-quicly>"
228 echo -e "\n4. Build vpp as desired\n"
229 fi;
230}