source: trunk/test/test.sh@ 22

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

Minor code revisions.

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