1 # Copyright (c) 2021 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
37 local is_feature="false"
39 local tester=${GERRIT_USER:-$USER}
42 if [ -z "$WS_ROOT" ] ; then
43 if [ -d "./extras/bash" ] ; then
44 export WS_ROOT="$(pwd)"
46 echo "ERROR: WS_ROOT is not set!"
49 elif [ ! -d "$WS_ROOT/src/vppinfra" ] ; then
50 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
54 options=$(getopt -o "adfg:j:r:" -- "$@")
55 if [ $? -eq 1 ] ; then
60 while [ -z "$usage" ] ; do
75 grep_for="${1//-/\\-}"
80 if [ $((jobs)) != $jobs ] ; then
81 echo "ERROR: Invalid option value for -j option ($jobs)!"
88 if [ $((retry_count)) != $retry_count ] ; then
89 echo "ERROR: Invalid option value for -r option ($retry_count)!"
101 if [ -n "$usage" ] || [ -z "$1" ] ; then
102 if [ -z "$1" ] ; then
103 echo "ERROR: no testcase specified!"
105 echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-j <jobs>][-r <retry count>] <testcase> [<retry_count>]"
106 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"
112 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)"
117 if [ $retry_count -le 0 ] ; then
120 if [ "$is_feature" == "true" ] ; then
121 run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs"
123 run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
128 line="------------------------------------------------------------------------------"
129 test_desc="'$run_make_test'"
130 if [ -n "$grep_for" ] ; then
131 test_desc="$test_desc [grep '$show_grep']"
133 for ((i=1; i<=retry_count; i++)) ; do
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"
142 if [ -n "$grep_for" ] ; then
143 grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
145 if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
146 if [ -n "$grep_results" ] ; then
151 echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
156 echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
157 echo -e "Hey $tester, Life is good!!! :D\n"
161 # bash function to set up csit python virtual environment
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!"
170 local setup_framework=$WS_ROOT/resources/libraries/python/SetupFramework.py
171 if [ -n "$(grep pip3 $setup_framework)" ]; then
173 local VENV_OPTS="-p python3"
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
182 echo "ERROR: WS_ROOT not set to a CSIT workspace!"
186 # bash function to set up VPP workspace with quicly source code
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."
197 if [ -z "$WS_ROOT" ] ; then
198 if [ -d "./extras/bash" ] ; then
199 export WS_ROOT="$(pwd)"
201 echo "ERROR: WS_ROOT is not set!"
204 elif [ ! -d "$WS_ROOT/extras/bash" ] ; then
205 echo "ERROR: WS_ROOT is not set to a VPP workspace!"
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
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"