forked from nexlab/dmdomain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmysql.sh
executable file
·108 lines (99 loc) · 3.3 KB
/
testmysql.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
#!/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"
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="tests/*.list"
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:' \'$uno\' \'$due\')\r "
totprova=$(mysql -u$1 -p$2 -e "SELECT IF((select DMDOMAIN('${due}', '${uno}')), TRUE, FALSE)" domotika | tail -n 1)
if [ "$totprova" = "0" ] ; then
provata="False"
else
provata="True"
fi
if [ ${provata} != ${tre} ] ; then
RES="${RES}\n${ERED}ERROR: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $provata${EWHITE} (need: $tre)${NO_COLOR}"
e=$[ e+1 ]
#echo
#echo
#echo
#echo $(mysql -u$1 -p$2 -e "SELECT IF((select DMDOMAIN('${due}', '${uno}')), TRUE, FALSE)" domotika )
else
o=$[ o+1 ]
fi
p=$[ c*100/tot ]
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ' \'$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 "------------------------------------"