# Copyright (c) 2019 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# This file is meant to be sourced in a .bashrc file to add useful
# bash functions to an interactive shell


# Bash function to run vpp 'make test' testcases
# repeatedly, stopping on test failure or when
# a test log contains the optionally specified text
vpp-make-test()
{
    local options
    local usage
    local all
    local debug
    local grep_for
    local run_make_test
    local old_pwd
    local is_feature="false"
    local retry_count=100
    local tester=${GERRIT_USER:-$USER}
    
    if [ -z "$WS_ROOT" ] ; then
        echo "ERROR: WS_ROOT is not set!"
        return
    elif [ -z "$(find $WS_ROOT -type d -name vppinfra)" ] ; then
        echo "ERROR: WS_ROOT is not set to a VPP workspace!"
        return
    fi
    
    options=$(getopt -o "adfg:r:" -- "$@")
    if [ $? -eq 1 ] ; then
        usage=true
    else
        eval set -- $options
    fi
    while [ -z "$usage" ] ; do
        case "$1" in
            -a)
                all="-all"
                ;;
            -d)
                debug="-debug"
                ;;
            -f)
                is_feature="true"
                retry_count=1
                ;;
            -g)
                shift
                show_grep=$1
                grep_for="${1//-/\\-}"
                ;;
            -r)
                shift
                retry_count=$1
                if [ $((retry_count)) != $retry_count ] ; then
                    echo "ERROR: Invalid option value for -r option ($retry_count)!"
                    usage=true;
                fi
                ;;
            --)
                shift
                break
                ;;
        esac
        shift
    done
    
    if [ -n "$usage" ] || [ -z "$1" ] ; then
        if [ -z "$1" ] ; then
            echo "ERROR: no testcase specified!"
        fi
        echo "Usage: vpp-make-test [-a][-d][-f][-g <text>][-r <retry count>] <testcase> [<retry_count>]"
        echo "         -a                Run extended tests"
        echo "         -d                Run vpp debug image (i.e. with ASSERTS)"
        echo "         -f                Testcase is a feature set (e.g. tcp)"
        echo "         -g <text>         Text to grep for in log, FAIL on match."
        echo "                           Enclose <text> in single quotes when it contains any dashes:"
        echo "                           e.g.  vpp-make-test -g 'goof-bad-' test_xyz"
        echo "         -r <retry count>  Retry Count (default = 100 for individual | 1 for feature)"
        return
    fi

    if [ $retry_count -le 0 ] ; then
        retry_count=1
    fi
    if [ "$is_feature" == "true" ] ; then
        run_make_test="make test$all$debug TEST=$1 SANITY=no TEST_JOBS=auto"
    else
        run_make_test="make test$all$debug TEST=*.*.$1 SANITY=no"
    fi

    old_pwd=$(pwd)
    cd $WS_ROOT
    line="------------------------------------------------------------------------------"
    local test_desc="'$run_make_test'"
    if [ -n "$grep_for" ] ; then
        test_desc="$test_desc [grep $show_grep]"
    fi
    for ((i=1; i<=retry_count; i++)) ; do
        echo -e "\n$line"
        echo -e "ITERATION [$i/$retry_count]: $test_desc\n$line"
        result=$($run_make_test)
        if [ ! -d /tmp/vpp-unittest* ] ; then
            echo -e "\nERROR: No testcase(s) executed!\n"
            return
        fi
        echo "$result"
        if [ -n "$grep_for" ] ; then
            grep_results=$(grep -sHn $grep_for /tmp/vpp-u*/log.txt)
        fi
        if [ -n "$(echo $result | grep FAILURE)" ] || [ -n "$grep_results" ] ; then
            if [ -n "$grep_results" ] ; then
                fail="FAIL (grep)"
            else
                fail="FAIL"
            fi
            echo -e "\n$line\n$fail [$i/$retry_count]: $test_desc\n$line\n"
            return
        fi
    done
    
    echo -e "\n$line\nPASS [$((i-1))/$retry_count]: $test_desc\n$line\n"
    echo -e "Hey $tester, Life is good!!! :D\n"
    cd $old_pwd
}
export -f vpp-make-test
