Dave Wallace | d7b9af4 | 2021-01-14 15:03:07 -0500 | [diff] [blame] | 1 | # Copyright (c) 2021 Cisco and/or its affiliates. |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 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 | |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 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 |
| 21 | vpp-make-test() |
| 22 | { |
| 23 | local options |
| 24 | local usage |
| 25 | local all |
| 26 | local debug |
| 27 | local grep_for |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 28 | local show_grep |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 29 | local run_make_test |
| 30 | local old_pwd |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 31 | local test_desc |
Dave Wallace | 7854588 | 2021-05-19 17:01:55 -0400 | [diff] [blame] | 32 | local grep_results |
| 33 | local result |
| 34 | local fail |
| 35 | local i |
| 36 | local line |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 37 | local is_feature="false" |
| 38 | local retry_count=100 |
| 39 | local tester=${GERRIT_USER:-$USER} |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 40 | local jobs="auto" |
Andrew Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 41 | |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 42 | if [ -z "$WS_ROOT" ] ; then |
Dave Wallace | 7854588 | 2021-05-19 17:01:55 -0400 | [diff] [blame] | 43 | 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 Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 49 | elif [ ! -d "$WS_ROOT/src/vppinfra" ] ; then |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 50 | echo "ERROR: WS_ROOT is not set to a VPP workspace!" |
| 51 | return |
| 52 | fi |
Andrew Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 53 | |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 54 | options=$(getopt -o "adfg:j:r:" -- "$@") |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 55 | 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 77 | -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 Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 85 | -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 Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 100 | |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 101 | if [ -n "$usage" ] || [ -z "$1" ] ; then |
| 102 | if [ -z "$1" ] ; then |
| 103 | echo "ERROR: no testcase specified!" |
| 104 | fi |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 105 | echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-j <jobs>][-r <retry count>] <testcase> [<retry_count>]" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 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" |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 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)" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 114 | return |
| 115 | fi |
| 116 | |
| 117 | if [ $retry_count -le 0 ] ; then |
| 118 | retry_count=1 |
| 119 | fi |
| 120 | if [ "$is_feature" == "true" ] ; then |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 121 | run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=$jobs" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 122 | 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 129 | test_desc="'$run_make_test'" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 130 | if [ -n "$grep_for" ] ; then |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 131 | test_desc="$test_desc [grep '$show_grep']" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 132 | 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 Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 155 | |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 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" |
| 158 | cd $old_pwd |
| 159 | } |
Andrew Yourtchenko | be360ee | 2020-04-29 16:48:24 +0000 | [diff] [blame] | 160 | |
| 161 | # bash function to set up csit python virtual environment |
| 162 | csit-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 Wallace | ab755a3 | 2021-05-19 21:47:00 -0400 | [diff] [blame] | 185 | |
| 186 | # bash function to set up VPP workspace with quicly source code |
| 187 | set-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 | } |