-
Notifications
You must be signed in to change notification settings - Fork 10
/
ktestsctl
executable file
·200 lines (178 loc) · 3.87 KB
/
ktestsctl
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
. etc/config
### version for this script
VERSION='1.0.1'
LOGDATE=`date`
### return non-zero code if at least one test failed
TESTS_FAILED=0
ktestsctl_usage() {
cat <<EOF
$0 [options] cmd [params]
Options:
-m | --mysql ..... prepare mysql database
-q | --quiet ..... execution of unit tests in silent mode
-w | --wait ...... wait at the end of running the unit tests
...... (for docker it requires interactive mode: docker run -i ...)
Commands:
-- command 'run' --
run .............. run all tests
run <filter> ..... run tests with a filter on unit names
run <unitname> ... run the test unit
-- command 'help' --
help ............. print the help text
-- command 'version' --
version .......... print the version string
Version: $0 ${VERSION}
EOF
}
ktestsctl_mysqld_alive() {
mysqladmin -h localhost ping
}
# prepare mysql server
ktestsctl_mysql() {
echo "=== unit tests - prepare mysql server ==="
if [ -f /etc/redhat-release ] ; then
mysqld_safe &
else
/usr/sbin/mysqld &
fi
sleep 5
count=0
until ( ktestsctl_mysqld_alive )
do
((count++))
if [ ${count} -gt 50 ]
then
echo "error: mysqld did not become ready in time"
exit 1
fi
sleep 0.1
done
sleep 1
mysqladmin -u root password "${DBROOTPW}"
INSTALL_EXTRA_TABLES=yes INSTALL_PRESENCE_TABLES=yes \
INSTALL_DBUID_TABLES=yes CHARSET="latin1" kamdbctl create
}
# execute one or more test units
ktestsrun() {
echo "=== unit tests execution start ==="
echo "running test units at: ${LOGDATE}" >${LOGFILE}
echo "" >>${LOGFILE}
if [ $# -lt 1 ] ; then
UNITSLIST=`find units/t* -maxdepth 1 -type d`
else
UNITSLIST=`find units/${1}* -maxdepth 1 -type d`
fi
for tdir in ${UNITSLIST} ; do
if [[ ${tdir} =~ $(echo ^units\/\($(paste -sd'|' excludeunits.txt)\)$) ]]; then
echo
echo "Skipping ${tdir} as requested..."
continue
fi
if [[ -d "${tdir}" && ! -L "${tdir}" ]]; then
tname=`basename ${tdir}`
texec="${tname}.sh"
tpath="${tdir}/${texec}"
if [[ -f "${tpath}" && -x "${tpath}" ]]; then
echo
tsummary=""
if [[ -f "${tdir}/README.md" ]]; then
tsummary=`grep "^Summary: " ${tdir}/README.md | cut -c10-`
fi
if [[ ! -z "${tsummary}" ]]; then
echo "* test unit ${tname}: ${tsummary}" | tee -a ${LOGFILE}
fi
echo "test unit ${tname}: running ..."
cd ${tdir}
if [ "${UNITOUTPUT}" == "no" ]; then
# save stdout and stderr, then redirect to /dev/null
exec 3>&1 4>&2 >/dev/null 2>&1
fi
./${texec}
ret=$?
if [ "${UNITOUTPUT}" == "no" ]; then
# restore stdout and stderr
exec 1>&3 2>&4
fi
cd ../..
if [ ! "$ret" -eq 0 ] ; then
echo "- test unit ${tname}: failed" | tee -a ${LOGFILE}
TESTS_FAILED=1
else
echo "- test unit ${tname}: ok" | tee -a ${LOGFILE}
fi
fi
fi
done
sleep 1
echo
echo "=== unit tests execution report ==="
echo
cat ${LOGFILE}
echo
echo "=== unit tests execution end ==="
echo
}
#
##### ================================================ #####
### evaluate first the options
CMDPARAMS=()
KTESTSWAIT="no"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-m|--mysql)
ktestsctl_mysql
shift
;;
-q|--quiet)
UNITOUTPUT="no"
shift
;;
-w|--wait)
KTESTSWAIT="yes"
shift
;;
*)
CMDPARAMS+=("$1")
shift
;;
esac
done
set -- "${CMDPARAMS[@]}" # restore positional parameters
### main command switch
#
echo
if [ -n "${KAMRUN}" ] ; then
mkdir -p ${KAMRUN}
chmod a+w ${KAMRUN}
fi
case $1 in
run)
if [ $# -lt 2 ] ; then
ktestsrun
else
ktestsrun "${2}"
fi
if [ "${KTESTSWAIT}" == "yes" ]; then
echo
echo "=== waiting ..."
echo "=== this option requires to use 'docker run -i ...''"
echo "=== to exit: press any key and <enter>"
read -rs -n 1 key
fi
exit $TESTS_FAILED
;;
help)
ktestsctl_usage
exit 1
;;
version)
echo "$0 $VERSION"
;;
*)
ktestsctl_usage
exit 1
;;
esac