3 # ============LICENSE_START===============================================
4 # Copyright (C) 2023 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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
19 # Script containing all functions needed for auto testing of test suites
21 echo "Test suite started as: ${BASH_SOURCE[$i+1]} "$1 $2
28 if [ $1 == "local" ] || [ $1 == "remote" ] || [ $1 == "remote-remove" ] ; then
32 if [ $paramError -ne 0 ]; then
33 echo "Expected arg: local|remote|remote-remove"
37 # Set a description string for the test suite
38 if [ -z "$TS_ONELINE_DESCR" ]; then
39 TS_ONELINE_DESCR="<no-description>"
40 echo "No test suite description found, TC_ONELINE_DESCR should be set on in the test script , using "$TS_ONELINE_DESCR
46 ATS=$(basename "${BASH_SOURCE[$i+1]}" .sh)
48 echo "#################################################################################################"
49 echo "################################### Test suite: "$ATS
50 echo "################################### Started: "$(date)
51 echo "#################################################################################################"
52 echo "## Description: " $TS_ONELINE_DESCR
53 echo "#################################################################################################"
55 echo 0 > .tmp_tcsuite_ctr
56 echo 0 > .tmp_tcsuite_pass_ctr
57 echo 0 > .tmp_tcsuite_fail_ctr
58 rm .tmp_tcsuite_pass &> /dev/null
59 touch .tmp_tcsuite_pass
60 rm .tmp_tcsuite_fail &> /dev/null
61 touch .tmp_tcsuite_fail
65 echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
71 elif [ $# -eq 3 ]; then
74 echo -e "Test case \033[31m\033[1m./"$1 $2 $3 "could not be executed.\033[0m"
81 echo "#################################################################################################"
82 echo "################################### Test suite: "$ATS
83 echo "################################### Ended: "$(date)
84 echo "#################################################################################################"
85 echo "## Description: " $TS_ONELINE_DESCR
86 echo "## Execution time: " $((TSTEST_END-TSTEST_START)) " seconds"
87 echo "#################################################################################################"
88 echo "################################### RESULTS"
91 TCSUITE_CTR=$(< .tmp_tcsuite_ctr)
92 TCSUITE_PASS_CTR=$(< .tmp_tcsuite_pass_ctr)
93 TCSUITE_FAIL_CTR=$(< .tmp_tcsuite_fail_ctr)
95 total=$((TCSUITE_PASS_CTR+TCSUITE_FAIL_CTR))
96 if [ $TCSUITE_CTR -eq 0 ]; then
97 echo -e "\033[1mNo test cases seem to have executed. Check the script....\033[0m"
98 elif [ $total != $TCSUITE_CTR ]; then
99 echo -e "\033[1mTotal number of test cases does not match the sum of passed and failed test cases. Check the script....\033[0m"
101 echo "Number of test cases : " $TCSUITE_CTR
102 echo -e "Number of \033[31m\033[1mFAIL\033[0m: " $TCSUITE_FAIL_CTR
103 echo -e "Number of \033[32m\033[1mPASS\033[0m: " $TCSUITE_PASS_CTR
105 echo "PASS test cases"
106 cat .tmp_tcsuite_pass
108 echo "FAIL test cases"
109 cat .tmp_tcsuite_fail
111 if [ $TCSUITE_FAIL_CTR -ne 0 ]; then
112 echo "################################### Test suite completed with Tests FAIL ##############################"
113 echo "#################################################################################################"
115 echo "################################### Test suite completed ##############################"
116 echo "#################################################################################################"
119 exit $TCSUITE_FAIL_CTR