3
# Solaris's /bin/sh is not a POSIX shell, and
4
# it quits when cd fails, even if it is followed by a ||
5
# So enable -e only on POSIX shells
6
(cd /nonexistentdir 2>/dev/null || true) && set -e
10
CLAMSCAN=$TOP/clamscan/clamscan
11
CLAMD=$TOP/clamd/clamd
12
CHECK_CLAMD=$TOP/unit_tests/check_clamd
13
CLAMDSCAN=$TOP/clamdscan/clamdscan
14
TESTFILES=$TOP/test/clam*
15
NFILES=`ls -1 $TESTFILES | wc -l`
18
test -f clamd-test.pid &&
19
pid=`cat clamd-test.pid 2>/dev/null` &&
21
kill -0 $pid 2>/dev/null &&
22
kill $pid 2>/dev/null &&
23
kill -0 $pid 2>/dev/null &&
25
kill -0 $pid 2>/dev/null &&
27
kill -0 $pid 2>/dev/null &&
28
echo "Killing stuck clamd!" &&
29
kill -KILL $pid && exit 109 || true
43
test -f valgrind.log && cat valgrind.log || true
48
# Setup test directory to avoid temporary and output file clashes
50
ulimit -t 120; ulimit -d 512000; ulimit -v 512000;
51
(cd test-$1 2>/dev/null && killclamd || true)
56
cat <<EOF >test-db/test.hdb
57
aa15bcf478d165efd2065190eb473bcb:544:ClamAV-Test-File
59
cat <<EOF >test-clamd.conf
60
LogFile `pwd`/clamd-test.log
66
PidFile `pwd`/clamd-test.pid
67
DatabaseDirectory `pwd`/test-db
68
LocalSocket clamd-test.socket
70
# using different port here to avoid conflicts with system clamd daemon
77
MaxConnectionQueueLength 1024
81
# arg1: expected exitcode
86
$TOP/libtool --mode=execute $WRAPPER $*
88
if test $val -ne $expected; then
89
error "Failed to run $*, expected $expected exitcode, but was $val" >&2;
96
# Run a test and return its exitcode
99
$TOP/libtool --mode=execute $WRAPPER $*
105
# test successfully finished, remove test dir
113
if test "X$unrar_disabled" = "X1" && test `grep -v '\.rar' $1 | grep OK | wc -l` -eq 0
115
error "UNRAR is disabled, won't be able to detect unrar files!"
122
# ----------- valgrind wrapper
124
test "x$VG" = "x1" || { echo "*** valgrind tests skipped by default, use 'make check VG=1' to activate"; exit 77; }
125
export VALGRIND=`which ${VALGRIND-valgrind}`
126
export VALGRIND_COMMON_FLAGS="-v --trace-children=yes --suppressions=$abs_srcdir/valgrind.supp --log-file=valgrind.log --error-exitcode=123 $GENSUPP"
127
export VALGRIND_FLAGS="$VALGRIND_COMMON_FLAGS --track-fds=yes --leak-check=full"
128
export VALGRIND_FLAGS_RACE="$VALGRIND_COMMON_FLAGS --tool=helgrind"
129
test -n "$VALGRIND" || { echo "*** valgrind not found, skipping test"; exit 77; }
130
test -x "$VALGRIND" || { echo "*** valgrind not executable, skipping test"; exit 77; }
138
NRUNS=`grep -a "ERROR SUMMARY" valgrind.log | wc -l`
139
if test $NRUNS -ne `grep -a "ERROR SUMMARY: 0 errors" valgrind.log | wc -l` ||
140
test `grep -a "FATAL:" valgrind.log|wc -l` -ne 0; then
142
die "Valgrind tests failed"
146
# ----------- clamscan tests --------------------------------------------------------
149
if test_run 1 $CLAMSCAN --quiet -dtest-db/test.hdb $TESTFILES --log=clamscan.log; then
150
scan_failed clamscan.log "clamscan didn't detect all testfiles correctly"
152
NINFECTED=`grep "Infected files" clamscan.log | cut -f2 -d: | sed -e 's/ //g'`
153
if test "$NFILES" -ne "0$NINFECTED"; then
154
scan_failed clamscan.log "clamscan didn't detect all testfiles correctly"
157
cat <<EOF >test-db/test.pdb
160
if test_run 0 $CLAMSCAN --quiet -dtest-db $abs_srcdir/input/phish-test-* --log=clamscan2.log; then
162
die "Failed to run clamscan (phish-test)";
165
if test_run 1 $CLAMSCAN --quiet --phishing-ssl --phishing-cloak -dtest-db $abs_srcdir/input/phish-test-* --log=clamscan3.log; then
167
die "Failed to run clamscan (phish-test2)";
170
grep "phish-test-ssl: Phishing.Heuristics.Email.SSL-Spoof FOUND" clamscan3.log >/dev/null || die "phish-test1 failed";
171
grep "phish-test-cloak: Phishing.Heuristics.Email.Cloaked.Null FOUND" clamscan3.log >/dev/null || die "phish-test2 failed";
175
# ----------- clamd tests --------------------------------------------------------
178
cp $abs_srcdir/input/daily.pdb test-db/daily.pdb
179
if test_run 0 $CLAMD -c test-clamd.conf --help >clamd-test.log; then
180
die "Failed to run clamd --help";
182
grep "Clam AntiVirus Daemon" clamd-test.log >/dev/null || die "Wrong --help reply from clamd!";
183
if test_run 0 $CLAMD -c test-clamd.conf >clamd-test.log 2>&1; then
185
die "Failed to run clamd";
189
run_clamdscan_fileonly() {
190
rm -f clamdscan.log clamdscan-multiscan.log
191
$CLAMDSCAN --version --config-file=test-clamd.conf | grep "^ClamAV" >/dev/null || die "clamdscan can't get version of clamd!";
193
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* --log=clamdscan.log
195
die "Failed to run clamdscan!"
197
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* -m --log=clamdscan-multiscan.log
199
die "Failed to run clamdscan (multiscan)!"
205
run_clamdscan_fileonly $*
206
rm -f clamdscan-fdpass.log clamdscan-multiscan-fdpass.log clamdscan-stream.log clamdscan-multiscan-stream.log
208
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* --fdpass --log=clamdscan-fdpass.log
210
die "Failed to run clamdscan (fdpass)!"
212
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* -m --fdpass --log=clamdscan-multiscan-fdpass.log
214
die "Failed to run clamdscan (fdpass + multiscan)!"
216
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* --stream --log=clamdscan-stream.log
218
die "Failed to run clamdscan (instream)!"
220
$CLAMDSCAN --quiet --config-file=test-clamd.conf $* -m --stream --log=clamdscan-multiscan-stream.log
222
die "Failed to run clamdscan (instream + multiscan)!"
229
echo "ClamAV-RELOAD-Test" >reload-testfile
230
run_clamdscan reload-testfile
231
# it is not supposed to detect until we actually put the
232
# signature there and reload!
233
grep "ClamAV-RELOAD-TestFile" clamdscan.log >/dev/null 2>/dev/null && die "RELOAD test(1) failed!"
234
echo "ClamAV-RELOAD-TestFile:0:0:436c616d41562d52454c4f41442d54657374" >test-db/new.ndb
235
$CLAMDSCAN --reload --config-file=test-clamd.conf || die "clamdscan says reload failed!"
236
run_clamdscan reload-testfile
238
grep "ClamAV-RELOAD-TestFile" clamdscan.log >/dev/null 2>/dev/null || die "RELOAD test failed! (after reload)"
239
grep "ClamAV-RELOAD-TestFile" clamdscan-multiscan.log >/dev/null 2>/dev/null || die "RELOAD test failed! (after reload, multiscan)"
242
run_clamdscan_fdpass() {
244
$CLAMDSCAN --quiet --fdpass --config-file=test-clamd.conf - <$1 --log=clamdscan.log
246
die "Failed to run clamdscan (fdpass)!"
254
# Test that all testfiles are detected
255
run_clamdscan $TESTFILES
256
NINFECTED=`grep "Infected files" clamdscan.log | cut -f2 -d:|sed -e 's/ //g'`
257
NINFECTED_MULTI=`grep "Infected files" clamdscan-multiscan.log | cut -f2 -d:|sed -e 's/ //g'`
258
NINFECTED_FDPASS=`grep "Infected files" clamdscan-fdpass.log | cut -f2 -d:|sed -e 's/ //g'`
259
NINFECTED_MULTI_FDPASS=`grep "Infected files" clamdscan-multiscan-fdpass.log | cut -f2 -d:|sed -e 's/ //g'`
260
NINFECTED_STREAM=`grep "Infected files" clamdscan-stream.log | cut -f2 -d:|sed -e 's/ //g'`
261
NINFECTED_MULTI_STREAM=`grep "Infected files" clamdscan-multiscan-stream.log | cut -f2 -d:|sed -e 's/ //g'`
262
if test "$NFILES" -ne "0$NINFECTED"; then
263
scan_failed clamdscan.log "clamd did not detect all testfiles correctly!"
265
if test "$NFILES" -ne "0$NINFECTED_MULTI"; then
266
scan_failed clamdscan-multiscan.log "clamd did not detect all testfiles correctly in multiscan mode!"
268
if test "$NFILES" -ne "0$NINFECTED_FDPASS"; then
269
scan_failed clamdscan-multiscan.log "clamd did not detect all testfiles correctly in fdpass mode!"
271
if test "$NFILES" -ne "0$NINFECTED_MULTI_FDPASS"; then
272
scan_failed clamdscan-multiscan.log "clamd did not detect all testfiles correctly in fdpass+multiscan mode!"
274
# Test HeuristicScanPrecedence off feature
275
run_clamdscan ../clam-phish-exe
276
grep "ClamAV-Test-File" clamdscan.log >/dev/null 2>/dev/null;
277
if test $? -ne 0; then
279
die "HeuristicScanPrecedence off test failed!"
287
# Run clamd test suite
288
test_run_check $CHECK_CLAMD
291
# Test RELOAD command
300
echo "VirusEvent $abs_srcdir/virusaction-test.sh `pwd` \"Virus found: %v\"" >>test-clamd.conf
301
echo "HeuristicScanPrecedence yes" >>test-clamd.conf
303
# Test HeuristicScanPrecedence feature
304
run_clamdscan ../clam-phish-exe
305
grep "Phishing.Heuristics.Email.SpoofedDomain" clamdscan.log >/dev/null 2>/dev/null ||
306
{ cat clamdscan.log; die "HeuristicScanPrecedence on test failed!"; }
308
if grep "^#define HAVE_FD_PASSING 1" $TOP/clamav-config.h >/dev/null; then
309
run_clamdscan_fdpass $TOP/test/clam.exe
310
grep "ClamAV-Test-File" clamdscan.log >/dev/null 2>/dev/null ||
311
{ cat clamdscan.log; die "FDpassing test failed!";}
313
echo "*** No file descriptor passing support, skipping test"
316
# Test VirusEvent feature
317
run_clamdscan_fileonly $TOP/test/clam.exe
318
test -f test-clamd.log || sleep 1
319
grep "Virus found: ClamAV-Test-File.UNOFFICIAL" test-clamd.log >/dev/null 2>/dev/null ||
320
{ cat test-clamd.log || true; die "Virusaction test failed"; }