Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 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: |
| 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 |
| 22 | vpp-make-test() |
| 23 | { |
| 24 | local options |
| 25 | local usage |
| 26 | local all |
| 27 | local debug |
| 28 | local grep_for |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 29 | local show_grep |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 30 | local run_make_test |
| 31 | local old_pwd |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 32 | local test_desc |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 33 | local is_feature="false" |
| 34 | local retry_count=100 |
| 35 | local tester=${GERRIT_USER:-$USER} |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 36 | local jobs="auto" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 37 | |
| 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 46 | options=$(getopt -o "adfg:j:r:" -- "$@") |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 47 | 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 69 | -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 Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 77 | -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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 97 | 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] | 98 | 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 104 | 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 Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 106 | return |
| 107 | fi |
| 108 | |
| 109 | if [ $retry_count -le 0 ] ; then |
| 110 | retry_count=1 |
| 111 | fi |
| 112 | if [ "$is_feature" == "true" ] ; then |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 113 | 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] | 114 | 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 Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 121 | test_desc="'$run_make_test'" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 122 | if [ -n "$grep_for" ] ; then |
Dave Wallace | b4f073c | 2019-12-18 14:06:31 -0500 | [diff] [blame] | 123 | test_desc="$test_desc [grep '$show_grep']" |
Dave Wallace | 535fdba | 2019-11-19 18:49:49 -0500 | [diff] [blame] | 124 | 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 | } |