-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·137 lines (125 loc) · 3.84 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
##################################################################
# Copyright (c) 2012-2014 Unixmedia S.r.l. <[email protected]>
# Copyright (c) 2012-2014 Franco (nextime) Lanza <[email protected]>
#
# Domotika System Domain unit tester [http://trac.unixmedia.it]
#
# This file is part of DMDomain.
#
# DMDomain is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################
ERED='\e[1;31m'
NO_COLOR='\e[0m'
EGREEN='\e[1;32m'
EYELLOW='\e[1;33m'
EBLUE='\e[1;34m'
EMAGENTA='\e[1;35m'
ECYAN='\e[1;36m'
EWHITE='\e[1;37m'
DEBUG="n"
echo
echo -e "$EWHITE\t\t DOMOTIKA DOMAIN TESTER \t\t$NO_COLOR\n"
if [ -f Makefile ] ; then
make clean
make debug
echo
fi
if [ \! -f ./dmdomain ] ; then
echo "dmdomain binary not found"
exit 1
fi
TCOLS=$(stty -a | tr -s ';' '\n' | grep "column" | sed s/'[^[:digit:]]'//g)
PBMIN=0 # progressbar min value
PBMAX=100 # progressbar max value
PBSYM="=" # symbol used for building the progressbar
PBPERCLEN=7 # length of % string, i.e. "[100%] " => 7 chars
# create the progressbar
function GetPBLine()
{
PBVAL=$1 # current progressbar value (function param)
RVAL=$2
PBUCOLS=$(($TCOLS-$PBPERCLEN-7)) # usable columns
PBNUM=$((($PBVAL*$PBUCOLS)/($PBMAX-$PBMIN)))
for((j=0; j<$PBNUM; j++)); do
PBLINE="$PBLINE$PBSYM"
done
PBPERC=$(printf "[%3d%%] " $PBVAL) # i.e. "[ 12%] "
echo -e "${EBLUE}$PBPERC$PBLINE> $2${NO_COLOR}\r"
echo -ne "\033[K$3 $4 $5 $6\r"
echo -ne "\033[1A\r"
}
c=0
o=0
e=0
p=0
RES=""
FILE=$1
if [ x"$1" = x"verbose" ] ; then
FILE=$2
fi
if [ x"$1" = x"debug" ] ; then
FILE=$2
DEBUG="y"
fi
if [ x"$FILE" = x"" ] ; then
FILE="tests/*.list"
else
if [ \! -f $FILE ] ; then
echo "File $FILE doesn't exists"
exit 0
fi
fi
echo -ne "$(GetPBLine $p $c 'Starting...')\r"
tot=`cat $FILE | grep -v "^#" | grep -v "^$" | wc -l`
for i in `cat $FILE | grep -v "^#" | grep -v "^$" `
do
c=$[ c+1 ]
uno=`echo $i | awk -F ':' '{print $1}'`
due=`echo $i | awk -F ':' '{print $2}'`
tre=`echo $i | awk -F ':' '{print $3}'`
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ./dmdomain' \'${uno}\' \'${due}\')\r"
totprova=$(./dmdomain "${uno}" "${due}")
prova=`echo -en "$totprova" | tail -n 1`
if [ "$DEBUG" = "y" ] ; then
echo -en "\n\n DEBUG: \n $totprova \n ------------- \n"
fi
if [ ${prova} != ${tre} ] ; then
RES="${RES}\n${ERED}ERROR: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $prova${EWHITE} (need: $tre)${NO_COLOR}| ./dmdomain '${uno}' '${due}'"
e=$[ e+1 ]
else
o=$[ o+1 ]
if [ "$1" = "verbose" ] || [ "$1" = "debug" ] ; then
RES="${RES}\n${EGREEN}OK: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $prova${EWHITE} (need: $tre)${NO_COLOR}| ./dmdomain '${uno}' '${due}'"
fi
fi
if [ "$DEBUG" = "y" ] ; then
echo -e "$RES"
RES=""
fi
p=$[ c*100/tot ]
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ./dmdomain' ${uno} ${due})\r"
done
echo -ne "$(GetPBLine 100 $c 'Done.')\r"
echo
echo -ne ${RES}
echo
echo "------------------------------------"
echo "FINAL REPORT:"
echo
pok=$[ o*100/tot ]
per=$[ 100-pok ]
echo -e " TESTS:$ECYAN $c$NO_COLOR - OK:$EGREEN $o ($pok%)$NO_COLOR ERRORS:$ERED $e ($per%)$NO_COLOR"
echo
echo "------------------------------------"