source: trunk/test/test.sh@ 27

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

Support for server-to-server relay and more user policies

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