source: trunk/test/testext.sh@ 21

Last change on this file since 21 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: 2.8 KB
Line 
1#! /bin/sh
2
3MAXTEST=1; export MAXTEST
4
5testext0 ()
6{
7 COMP=`which gcc`
8 if test "x$?" = x1 ; then
9 COMP="cc"
10 else
11 COMP=`which gcc | sed -e "s%\([a-z:]\) .*%\1%g"`
12 if test "x$COMP" = x; then
13 COMP="cc"
14 elif test "x$COMP" = xno; then
15 COMP="cc"
16 else
17 if test "x$COMP" = "xwhich:"; then
18 COMP="cc"
19 else
20 COMP="gcc"
21 gcc -v >/dev/null 2>&1 || COMP="gcc"
22 fi
23 fi
24 fi
25 log_start "EXTERNAL PROGRAM"
26 [ -z "$verbose" ] || echo MAKE is $MAKE
27 [ -z "$verbose" ] || { echo COMP is $COMP; echo; }
28 #
29 # standalone compilation
30 #
31 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
32 #
33 if test -r "Makefile"; then
34 ${MAKE} distclean >/dev/null
35 fi
36 #
37 ${TOP_SRCDIR}/configure --quiet --enable-debug --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$PW_DIR/testrc_1ext --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file
38 #
39 if test x$? = x0; then
40 [ -z "$verbose" ] || log_msg_ok "configure...";
41 $MAKE > /dev/null
42 if test x$? = x0; then
43 [ -z "$verbose" ] || log_msg_ok "make...";
44 else
45 [ -z "$quiet" ] && log_msg_fail "make...";
46 return 1
47 fi
48
49 else
50 [ -z "$quiet" ] && log_msg_fail "configure...";
51 return 1
52 fi
53 #
54 # prepare the program
55 #
56 cat test/test_ext.c.in | sed -e "s%MYPWDIR%$PW_DIR/test_ext.res%g" > test_ext.c
57
58 ${COMP} -o test_ext test_ext.c
59 if test "x$?" != x0; then
60 log_msg_fail "${COMP} -o test_ext test_ext.c"
61 return 1
62 fi
63 chmod +rx test_ext
64 if test "x$?" != x0; then
65 log_msg_fail "chmod +rx test_ext"
66 return 1
67 fi
68
69 # compute checksum and fix config file
70 #
71 cp test/testrc_1ext.in testrc_1ext
72 CHKSUM=`./samhain -H $PW_DIR/test_ext | awk '{ print $2$3$4$5$6$7}'`
73 echo "OpenCommand=$PW_DIR/test_ext" >> testrc_1ext
74 echo "SetType=log" >> testrc_1ext
75 echo "SetChecksum=$CHKSUM" >> testrc_1ext
76 echo "SetFilterOr=ALERT" >> testrc_1ext
77
78 rm -f $PW_DIR/test_ext.res
79 rm -f $PW_DIR/pdbg.child
80 rm -f $PW_DIR/pdbg.main
81 ./samhain -p none
82
83 # The shell is too fast ...
84 sleep 1
85 [ -z "$verbose" ] || {
86 echo;
87 echo "${S}Logged by external C program test_ext (filtered: ALERT only):${E}";
88 echo;
89 cat $PW_DIR/test_ext.res
90 echo
91 }
92
93 tmp=`cat $PW_DIR/test_ext.res | wc -l`
94 if [ $tmp -eq 4 ]; then
95 tmp=`egrep 'RECV: \[EOF\]' $PW_DIR/test_ext.res | wc -l`
96 if [ $tmp -eq 2 ]; then
97 tmp=`egrep 'RECV: ALERT' $PW_DIR/test_ext.res | wc -l`
98 if [ $tmp -eq 2 ]; then
99 log_ok 1 ${MAXTEST};
100 else
101 log_fail 1 ${MAXTEST};
102 fi
103 else
104 log_fail 1 ${MAXTEST};
105 fi
106 else
107 log_fail 1 ${MAXTEST};
108 fi
109
110 rm -f $PW_DIR/.samhain_file
111 rm -f $LOGFILE
112 rm -f $PW_DIR/.samhain_lock
113
114 log_end "EXTERNAL PROGRAM"
115}
116
Note: See TracBrowser for help on using the repository browser.