blob: bae1b6b687e939d88a1c22842cd30c83aace90a3 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/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
21echo "Test suite started as: ${BASH_SOURCE[$i+1]} "$1 $2
22
23
24IMAGE_TAG=""
25
26paramError=1
27if [ $# -gt 0 ]; then
28 if [ $1 == "local" ] || [ $1 == "remote" ] || [ $1 == "remote-remove" ] ; then
29 paramError=0
30 fi
31fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010032if [ $paramError -ne 0 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020033 echo "Expected arg: local|remote|remote-remove"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010034 exit 1
35fi
36
37# Set a description string for the test suite
38if [ -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
41fi
42
43TSTEST_START=$SECONDS
44
45suite_setup() {
46 ATS=$(basename "${BASH_SOURCE[$i+1]}" .sh)
47
48 echo "#################################################################################################"
49 echo "################################### Test suite: "$ATS
50 echo "################################### Started: "$(date)
51 echo "#################################################################################################"
52 echo "## Description: " $TS_ONELINE_DESCR
53 echo "#################################################################################################"
54 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
62}
63
64__print_err() {
65 echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
66}
67
68run_tc() {
69 if [ $# -eq 2 ]; then
70 ./$1 $2 $IMAGE_TAG
71 elif [ $# -eq 3 ]; then
72 ./$1 $2 $3
73 else
74 echo -e "Test case \033[31m\033[1m./"$1 $2 $3 "could not be executed.\033[0m"
75 fi
76}
77
78suite_complete() {
79 TSTEST_END=$SECONDS
80 echo ""
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"
89 echo ""
90
91 TCSUITE_CTR=$(< .tmp_tcsuite_ctr)
92 TCSUITE_PASS_CTR=$(< .tmp_tcsuite_pass_ctr)
93 TCSUITE_FAIL_CTR=$(< .tmp_tcsuite_fail_ctr)
94
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"
100 fi
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
104 echo ""
105 echo "PASS test cases"
106 cat .tmp_tcsuite_pass
107 echo ""
108 echo "FAIL test cases"
109 cat .tmp_tcsuite_fail
110 echo ""
111
112 echo "################################### Test suite completed ##############################"
113 echo "#################################################################################################"
114}