blob: e35d670de16b066748fd1210c30e151fcad70dc5 [file] [log] [blame]
BjornMagnussonXA42dcb262019-04-26 19:29:54 +00001#!/bin/bash
2
3# Script containing all functions needed for auto testing of test suites
4
5echo "Test suite started as: ${BASH_SOURCE[$i+1]} "$1 $2
6
7
8IMAGE_TAG=""
9
10if [ $# -eq 1 ]; then
11 if [ $1 == "local" ] && [ $1 == "remote" ] && [ $1 == "remote-remove" ] ; then
12 IMAGE_TAG="latest"
13 echo "No image tag give, assuming 'latest'"
14 fi
15elif [ $# -eq 2 ] && [ $1 == "local" ]; then
16 IMAGE_TAG=$2
17elif [ $# -eq 2 ] && [ $1 == "remote" ]; then
18 IMAGE_TAG=$2
19elif [ $# -eq 2 ] && [ $1 == "remote-remove" ]; then
20 IMAGE_TAG=$2
21else
22 echo "Expected arg: local [<image-tag>] | remote [<image-tag>] | remote-remove [<image-tag>] | manual-container | manual-app"
23 exit 1
24fi
25
26# Set a description string for the test suite
27if [ -z "$TS_ONELINE_DESCR" ]; then
28 TS_ONELINE_DESCR="<no-description>"
29 echo "No test suite description found, TC_ONELINE_DESCR should be set on in the test script , using "$TS_ONELINE_DESCR
30fi
31
32TSTEST_START=$SECONDS
33
34suite_setup() {
35 ATS=$(basename "${BASH_SOURCE[$i+1]}" .sh)
36
37 echo "#################################################################################################"
38 echo "################################### Test suite: "$ATS
39 echo "################################### Started: "$(date)
40 echo "#################################################################################################"
41 echo "## Description: " $TS_ONELINE_DESCR
42 echo "#################################################################################################"
43 echo ""
44 echo 0 > .tmp_tcsuite_ctr
45 echo 0 > .tmp_tcsuite_pass_ctr
46 echo 0 > .tmp_tcsuite_fail_ctr
47 rm .tmp_tcsuite_pass &> /dev/null
48 touch .tmp_tcsuite_pass
49 rm .tmp_tcsuite_fail &> /dev/null
50 touch .tmp_tcsuite_fail
51}
52
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000053__print_err() {
BjornMagnussonXA42dcb262019-04-26 19:29:54 +000054 echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
55}
56
57run_tc() {
58 if [ $# -eq 2 ]; then
59 ./$1 $2 $IMAGE_TAG
60 elif [ $# -eq 3 ]; then
61 ./$1 $2 $3
62 else
63 echo -e "Test case \033[31m\033[1m./"$1 $2 $3 "could not be executed.\033[0m"
64 fi
65}
66
67suite_complete() {
68 TSTEST_END=$SECONDS
69 echo ""
70 echo "#################################################################################################"
71 echo "################################### Test suite: "$ATS
72 echo "################################### Ended: "$(date)
73 echo "#################################################################################################"
74 echo "## Description: " $TS_ONELINE_DESCR
75 echo "## Execution time: " $((TSTEST_END-TSTEST_START)) " seconds"
76 echo "#################################################################################################"
77 echo "################################### RESULTS"
78 echo ""
79
80 TCSUITE_CTR=$(< .tmp_tcsuite_ctr)
81 TCSUITE_PASS_CTR=$(< .tmp_tcsuite_pass_ctr)
82 TCSUITE_FAIL_CTR=$(< .tmp_tcsuite_fail_ctr)
83
84 total=$((TCSUITE_PASS_CTR+TCSUITE_FAIL_CTR))
85 if [ $TCSUITE_CTR -eq 0 ]; then
86 echo -e "\033[1mNo test cases seem to have executed. Check the script....\033[0m"
87 elif [ $total != $TCSUITE_CTR ]; then
88 echo -e "\033[1mTotal number of test cases does not match the sum of passed and failed test cases. Check the script....\033[0m"
89 fi
90 echo "Number of test cases : " $TCSUITE_CTR
91 echo -e "Number of \033[31m\033[1mFAIL\033[0m: " $TCSUITE_FAIL_CTR
92 echo -e "Number of \033[32m\033[1mPASS\033[0m: " $TCSUITE_PASS_CTR
93 echo ""
94 echo "PASS test cases"
95 cat .tmp_tcsuite_pass
96 echo ""
97 echo "FAIL test cases"
98 cat .tmp_tcsuite_fail
99 echo ""
100
101 echo "################################### Test suite completed ##############################"
102 echo "#################################################################################################"
103}