BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | |
| 19 | # Script containing all functions needed for auto testing of test suites |
| 20 | |
| 21 | echo "Test suite started as: ${BASH_SOURCE[$i+1]} "$1 $2 |
| 22 | |
| 23 | |
| 24 | IMAGE_TAG="" |
| 25 | |
| 26 | paramError=1 |
| 27 | if [ $# -gt 0 ]; then |
| 28 | if [ $1 == "local" ] || [ $1 == "remote" ] || [ $1 == "remote-remove" ] ; then |
| 29 | paramError=0 |
| 30 | fi |
| 31 | fi |
| 32 | if [ $# -eq 2 ]; then |
| 33 | if [ $2 == "auto-clean" ]; then |
| 34 | paramError=0 |
| 35 | fi |
| 36 | fi |
| 37 | if [ $paramError -ne 0 ]; then |
| 38 | echo "Expected arg: local|remote|remote-remove [ auto-clean ]" |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | # Set a description string for the test suite |
| 43 | if [ -z "$TS_ONELINE_DESCR" ]; then |
| 44 | TS_ONELINE_DESCR="<no-description>" |
| 45 | echo "No test suite description found, TC_ONELINE_DESCR should be set on in the test script , using "$TS_ONELINE_DESCR |
| 46 | fi |
| 47 | |
| 48 | TSTEST_START=$SECONDS |
| 49 | |
| 50 | suite_setup() { |
| 51 | ATS=$(basename "${BASH_SOURCE[$i+1]}" .sh) |
| 52 | |
| 53 | echo "#################################################################################################" |
| 54 | echo "################################### Test suite: "$ATS |
| 55 | echo "################################### Started: "$(date) |
| 56 | echo "#################################################################################################" |
| 57 | echo "## Description: " $TS_ONELINE_DESCR |
| 58 | echo "#################################################################################################" |
| 59 | echo "" |
| 60 | echo 0 > .tmp_tcsuite_ctr |
| 61 | echo 0 > .tmp_tcsuite_pass_ctr |
| 62 | echo 0 > .tmp_tcsuite_fail_ctr |
| 63 | rm .tmp_tcsuite_pass &> /dev/null |
| 64 | touch .tmp_tcsuite_pass |
| 65 | rm .tmp_tcsuite_fail &> /dev/null |
| 66 | touch .tmp_tcsuite_fail |
| 67 | } |
| 68 | |
| 69 | __print_err() { |
| 70 | echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]} |
| 71 | } |
| 72 | |
| 73 | run_tc() { |
| 74 | if [ $# -eq 2 ]; then |
| 75 | ./$1 $2 $IMAGE_TAG |
| 76 | elif [ $# -eq 3 ]; then |
| 77 | ./$1 $2 $3 |
| 78 | else |
| 79 | echo -e "Test case \033[31m\033[1m./"$1 $2 $3 "could not be executed.\033[0m" |
| 80 | fi |
| 81 | } |
| 82 | |
| 83 | suite_complete() { |
| 84 | TSTEST_END=$SECONDS |
| 85 | echo "" |
| 86 | echo "#################################################################################################" |
| 87 | echo "################################### Test suite: "$ATS |
| 88 | echo "################################### Ended: "$(date) |
| 89 | echo "#################################################################################################" |
| 90 | echo "## Description: " $TS_ONELINE_DESCR |
| 91 | echo "## Execution time: " $((TSTEST_END-TSTEST_START)) " seconds" |
| 92 | echo "#################################################################################################" |
| 93 | echo "################################### RESULTS" |
| 94 | echo "" |
| 95 | |
| 96 | TCSUITE_CTR=$(< .tmp_tcsuite_ctr) |
| 97 | TCSUITE_PASS_CTR=$(< .tmp_tcsuite_pass_ctr) |
| 98 | TCSUITE_FAIL_CTR=$(< .tmp_tcsuite_fail_ctr) |
| 99 | |
| 100 | total=$((TCSUITE_PASS_CTR+TCSUITE_FAIL_CTR)) |
| 101 | if [ $TCSUITE_CTR -eq 0 ]; then |
| 102 | echo -e "\033[1mNo test cases seem to have executed. Check the script....\033[0m" |
| 103 | elif [ $total != $TCSUITE_CTR ]; then |
| 104 | echo -e "\033[1mTotal number of test cases does not match the sum of passed and failed test cases. Check the script....\033[0m" |
| 105 | fi |
| 106 | echo "Number of test cases : " $TCSUITE_CTR |
| 107 | echo -e "Number of \033[31m\033[1mFAIL\033[0m: " $TCSUITE_FAIL_CTR |
| 108 | echo -e "Number of \033[32m\033[1mPASS\033[0m: " $TCSUITE_PASS_CTR |
| 109 | echo "" |
| 110 | echo "PASS test cases" |
| 111 | cat .tmp_tcsuite_pass |
| 112 | echo "" |
| 113 | echo "FAIL test cases" |
| 114 | cat .tmp_tcsuite_fail |
| 115 | echo "" |
| 116 | |
| 117 | echo "################################### Test suite completed ##############################" |
| 118 | echo "#################################################################################################" |
| 119 | } |