source: trunk/test/test.sh@ 19

Last change on this file since 19 was 19, checked in by rainer, 19 years ago

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File size: 12.2 KB
Line 
1#! /bin/sh
2
3isok=`test -t 1 2>&1 | wc -c`
4if [ "$isok" -eq 0 ]; then
5 test -t 1
6 isok=$?
7fi
8
9# The following two are the ANSI sequences for start and end embolden
10if [ x"$isok" = x0 ]; then
11 case $TERM in
12 vt*|ansi*|con*|xterm*|linux*|screen*|rxvt*)
13 S='[1;30m'
14 R=[31m
15 G=[32m
16 B=[36m
17 E=[m
18 ;;
19 *)
20 S=
21 R=
22 G=
23 B=
24 E=
25 ;;
26 esac
27fi
28
29
30usage() {
31 echo "test.sh [options] <test_number> [hostname]"
32 echo " [-q|--quiet|-v|--verbose] [-s|--stoponerr] [--no-cleanup]"
33 echo " [--srcdir=top_srcdir] [--color=always|never|auto]"
34 echo
35 echo " ${S}test.sh 1${E} -- Compile with many different options"
36 echo " ${S}test.sh 2${E} -- Hash function (testrc_1)"
37 echo " ${S}test.sh 3${E} -- Standalone init/check"
38 echo " ${S}test.sh 4${E} -- Microstealth init/check"
39 echo " ${S}test.sh 5${E} -- External program call (testrc_1ext.in)"
40 echo " ${S}test.sh 6${E} -- Controlling the daemon"
41 echo " ${S}test.sh 7${E} -- GnuPG signed files / prelude log"
42
43 echo " ${S}test.sh 10${E} -- Test c/s init/check (testrc_2.in)"
44 echo " ${S}test.sh 11${E} -- Test full c/s init/check (testrc_2.in)"
45 echo " ${S}test.sh 12${E} -- Test full c/s w/gpg (testrc_2.in)"
46 echo " ${S}test.sh 13${E} -- Test full c/s w/mysql (testrc_2.in)"
47 echo " ${S}test.sh 14${E} -- Test full c/s w/postgres (testrc_2.in)"
48 echo " ${S}test.sh all${E} -- All except 12+"
49
50 echo
51 echo "Scripts used by tests (located in ${SCRIPTDIR}):"
52 echo " (1) testcompile.sh (2) testhash.sh (3) testrun_1.sh (4) testrun_1a.sh"
53 echo " (5) testext.sh (6) testtimesrv.sh (7) testrun_1b.sh (10) testrun_2.sh"
54 echo " (11) testrun_2a.sh (12) testrun_2b.sh (13) testrun_2c.sh (14) testrun_2d.sh"
55}
56
57#
58# Option parsing
59#
60verbose=
61quiet=
62stoponerr=
63color=auto
64cleanup=on
65doall=
66
67while [ $# -gt 0 ]
68do
69 case "$1" in
70 -h|--help) usage; exit 0;;
71 -v|--verbose) verbose=on; quiet= ;;
72 -q|--quiet) quiet=on; verbose= ;;
73 -s|--stoponerr) stoponerr=on;;
74 --no-cleanup) cleanup= ;;
75 --really-all) doall=on;;
76 --srcdir=*) TOP_SRCDIR=`echo $1 | sed s,--srcdir=,,`; export TOP_SRCDIR;;
77 --color=*)
78 arg=`echo $1 | sed s,--color=,,`
79 case $arg in
80 auto) ;;
81 never|none|no)
82 S=
83 R=
84 G=
85 B=
86 E=
87 ;;
88 always|yes)
89 S='[1;30m'
90 R=[31m
91 G=[32m
92 G=[36m
93 E=[m
94 ;;
95 *) echo "Invalid argument $1"; exit 1;;
96 esac
97 ;;
98 -*) echo "Invalid argument $1"; exit 1;;
99 *) break;;
100 esac
101 shift
102done
103
104export verbose
105export quiet
106export stoponerr
107export cleanup
108export doall
109export S; export R; export G; export B; export E;
110
111SCRIPTDIR=.
112
113#
114# 'make test' will copy the 'test' subdirectory and replace TEST_SRCDIR
115#
116TEST_SRCDIR="XXXSRCXXX";
117if test "x${TOP_SRCDIR}" = x; then
118 # not within source tree, and not called with 'make testN'
119 if test -f "${TEST_SRCDIR}/src/samhain.c"; then
120 TOP_SRCDIR="${TEST_SRCDIR}"; export TOP_SRCDIR
121 if test -f test/testcompile.sh; then
122 SCRIPTDIR=test
123 fi
124 # not within source tree, not called by 'make', and in 'test' subdir
125 elif test -f "../${TEST_SRCDIR}/src/samhain.c"; then
126 cd ..
127 SCRIPTDIR=test
128 TOP_SRCDIR="${TEST_SRCDIR}"; export TOP_SRCDIR
129 # within source tree, and not called with 'make testN'
130 else
131 if test -f ../src/samhain.c; then
132 cd ..
133 SCRIPTDIR=test
134 TOP_SRCDIR=.
135 export TOP_SRCDIR
136 elif test -f ./src/samhain.c; then
137 SCRIPTDIR=test
138 TOP_SRCDIR=.
139 export TOP_SRCDIR
140 else
141 echo "Please use --srcdir=DIR, where DIR should be the"
142 echo "top directory in the samhain source tree."
143 exit 1
144 fi
145 fi
146else
147 # called by make, or with --srcdir=TOP_SRCDIR
148 if test -f "${TOP_SRCDIR}/src/samhain.c"; then
149 SCRIPTDIR="${TOP_SRCDIR}/test"
150 elif test -f "../${TOP_SRCDIR}/src/samhain.c"; then
151 cd ..; SCRIPTDIR="${TOP_SRCDIR}/test"
152 else
153 echo "Please use --srcdir=DIR, where DIR should be the"
154 echo "top directory in the samhain source tree."
155 exit 1
156 fi
157fi
158
159export SCRIPTDIR
160
161PW_DIR=`pwd`; export PW_DIR
162#
163#
164#
165if test x$UID != x; then
166 TRUST="--with-trusted=0,2,$UID"
167else
168 TRUST="--with-trusted=0,2,500"
169fi
170export TRUST
171#
172# find a good 'make'
173#
174MAKE=`which gmake`
175if test "x$?" = x1 ; then
176 MAKE="make -s"
177else
178 MAKE=`which gmake | sed -e "s%\([a-z:]\) .*%\1%g"`
179 if test "x$MAKE" = x; then
180 MAKE="make -s"
181 elif test "x$MAKE" = xno; then
182 MAKE="make -s"
183 else
184 if test "x$MAKE" = "xwhich:"; then
185 MAKE="make -s"
186 else
187 MAKE="gmake -s"
188 gmake -v >/dev/null 2>&1 || MAKE="make -s"
189 fi
190 fi
191fi
192export MAKE
193
194failcount=0
195okcount=0
196skipcount=0
197global_count=0
198last_count=0
199
200# args: #test, #total, status, optional msg
201log_msg ()
202{
203 if [ x"$COLUMNS" != x ]; then
204 TERMWIDTH=$COLUMNS
205 elif [ x"$COLS" != x ]; then
206 TERMWIDTH=$COLS
207 else
208 TERMWIDTH=80
209 fi
210 cols=66;
211 #
212 if [ $1 -eq 0 ]; then
213 msg=" ${4}"
214 else
215 if [ ${1} -eq 1 ]; then
216 global_count=${last_count}
217 fi
218 let "v = $1 + global_count" >/dev/null
219 last_count=${v}
220 dd=''; if [ $v -lt 10 ]; then dd=" "; fi
221 dt=''; if [ $2 -lt 10 ]; then dt=" "; fi
222 if [ -z "$4" ]; then
223 msg=" test ${dd}${v}/${dt}${2}"
224 else
225 msg=" test ${dd}${v}/${dt}${2} ${4}"
226 fi
227 fi
228 #
229 if [ x"$3" = xfailure ]; then
230 ccode=$R
231 elif [ x"$3" = xsuccess ]; then
232 ccode=$G
233 else
234 ccode=$B
235 fi
236 if [ -z "${R}" ]; then
237 echo " [${3}] ${msg}"
238 else
239 # len=${#...} is not bourne shell
240 # also, need to account for terminal control sequences
241 len=`echo "$msg" | awk '/1;30m/ { print length()-10; }; !/1;30m/ { print length();}'`
242 let "cols = cols - len" >/dev/null
243 moveto='['$cols'C'
244 echo "${msg}${moveto}${ccode}[${3}]${E}"
245 fi
246}
247
248log_fail () {
249 log_msg "$1" "$2" failure "$3";
250 let "failcount = failcount + 1" >/dev/null;
251 test -z "$stoponerr" || exit 1;
252}
253log_ok () {
254 log_msg "$1" "$2" success "$3";
255 let "okcount = okcount + 1" >/dev/null;
256}
257log_skip () {
258 log_msg "$1" "$2" skipped "$3";
259 let "skipcount = skipcount + 1" >/dev/null;
260}
261
262log_msg_fail () { log_msg 0 0 failure "$1"; }
263log_msg_ok () { log_msg 0 0 success "$1"; }
264log_msg_skip () { log_msg 0 0 skipped "$1"; }
265
266log_start () {
267 if [ -z "$quiet" ]; then
268 echo;
269 echo "${S}__ START TEST ${1} __${E}";
270 echo;
271 fi
272}
273log_end () {
274 if [ -n "$verbose" ]; then
275 echo;
276 echo "${S}__ END TEST ${1} __${E}";
277 echo;
278 fi
279}
280
281do_cleanup () {
282 rm -f testrc_1.dyn
283 rm -f testrc_2
284 rm -f ./.samhain_file
285 rm -f ./.samhain_log*
286 rm -f ./.samhain_lock
287 test -d testrun_data && chmod -R 0700 testrun_data
288 rm -rf testrun_data
289 rm -f test_log_db
290 rm -f test_log_prelude
291}
292
293print_summary ()
294{
295 let "gcount = okcount + skipcount + failcount" >/dev/null;
296 [ -z "$quiet" ] && {
297 echo
298 echo "__ ${S}Tests: ${gcount} Ok: ${okcount} Skipped: ${skipcount} Failed: ${failcount}${E}"
299 }
300 if [ $failcount -eq 0 ]; then
301 [ -z "$quiet" ] && { echo "__ ${G}All tests passed successfully.${E}"; echo; }
302 elif [ $failcount -eq 1 ]; then
303 [ -z "$quiet" ] && { echo "__ ${R}There was 1 failure.${E}"; echo; }
304 else
305 [ -z "$quiet" ] && { echo "__ ${R}There were $failcount failures.${E}"; echo; }
306 fi
307 [ -z "$cleanup" ] || do_cleanup;
308}
309
310find_path () { (
311 save_IFS=$IFS; IFS=:
312
313 for dir in $PATH; do
314 IFS=$as_save_IFS
315 test -z "$dir" && dir=.
316 if test -f "$dir/$1"; then
317 echo "$dir/$1";
318 break;
319 fi
320 done
321 IFS=${save_IFS};
322); }
323
324find_hostname () {
325 tmp=`hostname -f 2>/dev/null`
326 if [ $? -ne 0 ]; then
327 tmp=`hostname 2>/dev/null`
328 fi
329 if [ -z "$tmp" ]; then
330 tmp="localhost"
331 fi
332 echo "$tmp"
333}
334
335rm -f ./test_log
336
337# first one is hostname, others are aliases
338#
339hostname=`cat /etc/hosts | egrep "^ *127.0.0.1" | awk '{ print $2 }'`
340if [ x"$hostname" = xlocalhost ]; then
341 hostname="127.0.0.1"
342fi
343
344if test x$1 = x1; then
345 . ${SCRIPTDIR}/testcompile.sh
346 testcompile
347 print_summary
348 exit $?
349fi
350if test x$1 = x2; then
351 . ${SCRIPTDIR}/testhash.sh
352 testhash
353 print_summary
354 exit $?
355fi
356if test x$1 = x3; then
357 . ${SCRIPTDIR}/testrun_1.sh
358 testrun1
359 print_summary
360 exit $?
361fi
362if test x$1 = x4; then
363 . ${SCRIPTDIR}/testrun_1.sh
364 . ${SCRIPTDIR}/testrun_1a.sh
365 testrun1a
366 print_summary
367 exit $?
368fi
369if test x$1 = x5; then
370 . ${SCRIPTDIR}/testext.sh
371 testext0
372 print_summary
373 exit $?
374fi
375if test x$1 = x6; then
376 . ${SCRIPTDIR}/testtimesrv.sh
377 testtime0
378 print_summary
379 exit $?
380fi
381if test x$1 = x7; then
382 . ${SCRIPTDIR}/testrun_1b.sh
383 testrun1b
384 print_summary
385 exit $?
386fi
387if test x$1 = x10; then
388 . ${SCRIPTDIR}/testrun_2.sh
389 testrun2 $hostname
390 print_summary
391 exit $?
392fi
393if test x$1 = x11; then
394 . ${SCRIPTDIR}/testrun_2a.sh
395 testrun2a $hostname
396 print_summary
397 exit $?
398fi
399if test x$1 = x12; then
400 . ${SCRIPTDIR}/testrun_2a.sh
401 . ${SCRIPTDIR}/testrun_2b.sh
402 testrun2b $hostname
403 print_summary
404 exit $?
405fi
406if test x$1 = x13; then
407 . ${SCRIPTDIR}/testrun_2a.sh
408 . ${SCRIPTDIR}/testrun_2c.sh
409 testrun2c $hostname
410 print_summary
411 exit $?
412fi
413if test x$1 = x14; then
414 . ${SCRIPTDIR}/testrun_2a.sh
415 . ${SCRIPTDIR}/testrun_2d.sh
416 testrun2d $hostname
417 print_summary
418 exit $?
419fi
420if test x$1 = xall; then
421 TEST_MAX=0
422 . ${SCRIPTDIR}/testcompile.sh
423 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
424 . ${SCRIPTDIR}/testhash.sh
425 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
426 . ${SCRIPTDIR}/testrun_1.sh
427 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
428 . ${SCRIPTDIR}/testrun_1a.sh
429 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
430 . ${SCRIPTDIR}/testext.sh
431 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
432 . ${SCRIPTDIR}/testtimesrv.sh
433 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
434 . ${SCRIPTDIR}/testrun_1b.sh
435 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
436 . ${SCRIPTDIR}/testrun_2.sh
437 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
438 . ${SCRIPTDIR}/testrun_2a.sh
439 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
440 . ${SCRIPTDIR}/testrun_2b.sh
441 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
442 . ${SCRIPTDIR}/testrun_2c.sh
443 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
444 . ${SCRIPTDIR}/testrun_2d.sh
445 let "TEST_MAX = TEST_MAX + MAXTEST" >/dev/null
446 #
447 # ${SCRIPTDIR}/testtimesrv.sh
448 # ${SCRIPTDIR}/testrun_1b.sh
449 # ${SCRIPTDIR}/testrun_2.sh $2
450 # ${SCRIPTDIR}/testrun_2a.sh $2
451 #
452 MAXTEST=${TEST_MAX}; export MAXTEST
453 testcompile
454 testhash
455 #
456 . ${SCRIPTDIR}/testrun_1.sh
457 MAXTEST=${TEST_MAX}; export MAXTEST
458 testrun1
459 #
460 . ${SCRIPTDIR}/testrun_1a.sh
461 MAXTEST=${TEST_MAX}; export MAXTEST
462 testrun1a
463 #
464 testext0
465 #
466 . ${SCRIPTDIR}/testtimesrv.sh
467 MAXTEST=${TEST_MAX}; export MAXTEST
468 testtime0
469 #
470 . ${SCRIPTDIR}/testrun_1b.sh
471 MAXTEST=${TEST_MAX}; export MAXTEST
472 testrun1b
473 #
474 . ${SCRIPTDIR}/testrun_2.sh
475 MAXTEST=${TEST_MAX}; export MAXTEST
476 testrun2 $hostname
477 #
478 . ${SCRIPTDIR}/testrun_2a.sh
479 MAXTEST=${TEST_MAX}; export MAXTEST
480 testrun2a $hostname
481 #
482 . ${SCRIPTDIR}/testrun_2b.sh
483 MAXTEST=${TEST_MAX}; export MAXTEST
484 testrun2b $hostname
485 #
486 . ${SCRIPTDIR}/testrun_2c.sh
487 MAXTEST=${TEST_MAX}; export MAXTEST
488 testrun2c $hostname
489 #
490 . ${SCRIPTDIR}/testrun_2d.sh
491 MAXTEST=${TEST_MAX}; export MAXTEST
492 testrun2d $hostname
493 #
494 print_summary
495 exit 0
496fi
497
498usage;
499
500exit 1;
501
502__ARCHIVE_FOLLOWS__
503‹-tæCí•MoÓ0Ç#@Høą
504»Å 4Ñ&m׎I9€M›–õeëËÆ6U(MÝÖ[bwv²®œù|ˆ‰ïÀ‰W$ĉ°‚牧ݺŠMHlÈ?µµý÷ËóØqþõ÷™ëû1›;Ê¥ 
505Ò©TXj™yuÒÖŠíiUM*ššÌh©LBMiŠPé„ÕËI'JÀ}›Aš0Ä·?g£ÍÌÊ„G!ÙŒUªÂek6JV5oÂJŸÑ0¬ü€m>X„¢¡*õMÑÊsÇ
506¢î"\§$u¡E‚e
507úî"†{cè0‡
508âÜî#ÀŠáû
509wñ6èaéqä;BÏï"â7P8Ë·Áq­%[Õ
510QHZTª#»[#î8ª–i¿ "ðšj1:€/:é(õ ešJ Šê'Ÿ5Þp]}d32“§! õ±ƒf¢‰×1éљRµÅ¡Lg‚M‘LTlì
511÷Šù!τiŒ1wOi“AË
512Ÿ
513Ü4ج`i#1LDõÃŒœr¶›ØCº–PC±Žœ€qLIY,àêÚD,S:œ
514J« Ž†”ù…
515ÀuM䋡År¹p
516
517xMáúdÑð Ö
518mpÆ-2š­úÑZE“`‹G·dW‹%bóðUmÅ˘{À悙])˜óde`íšÞØxüŽ˜Õ
519–ìK¹lòùú\¶³j®»­:îÌuÞ=7°aäz+k[]gñ|Ü#<ëÄë
520³X±–¶ë{ZE:ÞÊe§ æ«æYé]÷+x­Äží
521„õ=
522ßÊKú
523žÈÿ“jêØÿµt*
524úFÓ€ÿ_Wãÿï?Ÿ}÷|1Š1ï܌æˆï»âçå­IûÅíƒ\XÞW£åiöO¡ˆþ{ÊáÁÁ·ß÷wŠúöËá÷¯‡ûáGyý‡(?ÞŒúüíø|c_ìå/x͋øÀi ß؋—ŠsÉra׊Îhc'Ckt©±#
525Œ9ÂMàá€%Ô£úd®3l-ÑÂvŒ±¶±.
526<7êÍK—H$‰D"‘H$‰D"‘H$‰D"‘H$’
527ø ?:v(
Note: See TracBrowser for help on using the repository browser.