+# Trap "command not found" and make the script fail
+trap_fnc() {
+
+ if [ $? -eq 127 ]; then
+ echo -e $RED"Function not found, setting script to FAIL"$ERED
+ ((RES_CONF_FAIL++))
+ __print_current_stats
+ fi
+}
+trap trap_fnc ERR
+
+# Trap to kill subprocess for stats collection (if running)
+trap_fnc2() {
+ if [ $COLLECT_RUNTIME_STATS_PID -ne 0 ]; then
+ kill $COLLECT_RUNTIME_STATS_PID
+ fi
+}
+trap trap_fnc2 EXIT
+
+# Counter for tests
+TEST_SEQUENCE_NR=1
+
+# Function to log the start of a test case
+__log_test_start() {
+ TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
+ echo -e $BOLD"TEST $TEST_SEQUENCE_NR (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ $EBOLD
+ echo "TEST $TEST_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): ${FUNCNAME[1]}" $@ >> $HTTPLOG
+ ((RES_TEST++))
+ ((TEST_SEQUENCE_NR++))
+}
+
+# Function to print current statistics
+__print_current_stats() {
+ if [ $PRINT_CURRENT_STATS -ne 0 ]; then
+ echo " Current stats - exe-time, tests, passes, fails, conf fails, deviations: $(($SECONDS-$TCTEST_START)), $RES_TEST, $RES_PASS, $RES_FAIL, $RES_CONF_FAIL, $RES_DEVIATION"
+ fi
+}
+
+# General function to log a failed test case
+__log_test_fail_general() {
+ echo -e $RED" FAIL."$1 $ERED
+ ((RES_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a test case failed due to incorrect response code
+__log_test_fail_status_code() {
+ echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
+ ((RES_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a test case failed due to incorrect response body
+__log_test_fail_body() {
+ echo -e $RED" FAIL, returned body not correct"$ERED
+ ((RES_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a test case that is not supported
+__log_test_fail_not_supported() {
+ echo -e $RED" FAIL, function not supported"$ERED
+ ((RES_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# General function to log a passed test case
+__log_test_pass() {
+ if [ $# -gt 0 ]; then
+ echo $@
+ fi
+ ((RES_PASS++))
+ echo -e $GREEN" PASS"$EGREEN
+ __print_current_stats
+}
+
+#Counter for configurations
+CONF_SEQUENCE_NR=1
+
+# Function to log the start of a configuration setup
+__log_conf_start() {
+ TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
+ echo -e $BOLD"CONF $CONF_SEQUENCE_NR (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ $EBOLD
+ echo "CONF $CONF_SEQUENCE_NR - ${TIMESTAMP}: (${BASH_LINENO[1]}): "${FUNCNAME[1]} $@ >> $HTTPLOG
+ ((CONF_SEQUENCE_NR++))
+}
+
+# Function to log a failed configuration setup
+__log_conf_fail_general() {
+ echo -e $RED" FAIL."$1 $ERED
+ ((RES_CONF_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a failed configuration setup due to incorrect response code
+__log_conf_fail_status_code() {
+ echo -e $RED" FAIL. Exepected status "$1", got "$2 $3 $ERED
+ ((RES_CONF_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a failed configuration setup due to incorrect response body
+__log_conf_fail_body() {
+ echo -e $RED" FAIL, returned body not correct"$ERED
+ ((RES_CONF_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a configuration that is not supported
+__log_conf_fail_not_supported() {
+ echo -e $RED" FAIL, function not supported"$ERED$@
+ ((RES_CONF_FAIL++))
+ __print_current_stats
+ __check_stop_at_error
+}
+
+# Function to log a passed configuration setup
+__log_conf_ok() {
+ if [ $# -gt 0 ]; then
+ echo $@
+ fi
+ echo -e $GREEN" OK"$EGREEN
+ __print_current_stats
+}
+
+# Function to collect stats on endpoints
+# args: <app-id> <end-point-no> <http-operation> <end-point-url> <http-status> [<count>]
+__collect_endpoint_stats() {
+ if [ $COLLECT_ENDPOINT_STATS -eq 0 ]; then
+ return
+ fi
+ ENDPOINT_COUNT=1
+ if [ $# -gt 5 ]; then
+ ENDPOINT_COUNT=$6
+ fi
+ ENDPOINT_STAT_FILE=$TESTLOGS/$ATC/endpoint_$ATC_$1_$2".log"
+ ENDPOINT_POS=0
+ ENDPOINT_NEG=0
+ if [ -f $ENDPOINT_STAT_FILE ]; then
+ ENDPOINT_VAL=$(< $ENDPOINT_STAT_FILE)
+ ENDPOINT_POS=$(echo $ENDPOINT_VAL | cut -f4 -d ' ' | cut -f1 -d '/')
+ ENDPOINT_NEG=$(echo $ENDPOINT_VAL | cut -f5 -d ' ' | cut -f1 -d '/')
+ fi
+
+ if [ $5 -ge 200 ] && [ $5 -lt 300 ]; then
+ let ENDPOINT_POS=ENDPOINT_POS+$ENDPOINT_COUNT
+ else
+ let ENDPOINT_NEG=ENDPOINT_NEG+$ENDPOINT_COUNT
+ fi
+
+ printf '%-2s %-10s %-45s %-16s %-16s' "#" "$3" "$4" "$ENDPOINT_POS/$ENDPOINT_POS" "$ENDPOINT_NEG/$ENDPOINT_NEG" > $ENDPOINT_STAT_FILE
+}
+
+# Function to collect stats on endpoints
+# args: <app-id> <image-info>
+__collect_endpoint_stats_image_info() {
+ if [ $COLLECT_ENDPOINT_STATS -eq 0 ]; then
+ return
+ fi
+ ENDPOINT_STAT_FILE=$TESTLOGS/$ATC/imageinfo_$ATC_$1".log"
+ echo $POLICY_AGENT_IMAGE > $ENDPOINT_STAT_FILE
+}
+