git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4752 77e5149b-7576-45b1-b177-96237e5ba77b
Török Edvin authored on 2009/02/13 00:50:41... | ... |
@@ -1,3 +1,10 @@ |
1 |
+Thu Feb 12 17:11:16 EET 2009 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * Makefile.in, unit_tests/Makefile.am, unit_tests/Makefile.in, |
|
4 |
+ unit_tests/check_clamd.c, unit_tests/check_clamd.sh, |
|
5 |
+ unit_tests/checks.h, unit_tests/checks_common.h: initial version of |
|
6 |
+ clamd proto tests |
|
7 |
+ |
|
1 | 8 |
Thu Feb 12 14:15:14 EET 2009 (edwin) |
2 | 9 |
------------------------------------ |
3 | 10 |
* clamd/session.c: actually use the flags we calculated! |
... | ... |
@@ -66,7 +66,7 @@ DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ |
66 | 66 |
$(top_srcdir)/docs/man/freshclam.1.in \ |
67 | 67 |
$(top_srcdir)/docs/man/freshclam.conf.5.in \ |
68 | 68 |
$(top_srcdir)/docs/man/sigtool.1.in AUTHORS COPYING ChangeLog \ |
69 |
- INSTALL NEWS config/config.guess config/config.rpath \ |
|
69 |
+ INSTALL NEWS TODO config/config.guess config/config.rpath \ |
|
70 | 70 |
config/config.sub config/depcomp config/install-sh \ |
71 | 71 |
config/ltmain.sh config/missing |
72 | 72 |
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
... | ... |
@@ -15,21 +15,25 @@ else |
15 | 15 |
TESTS_ENVIRONMENT += export unrar_disabled=1; |
16 | 16 |
endif |
17 | 17 |
TESTS = $(programs) $(scripts) |
18 |
-check_PROGRAMS = $(programs) |
|
18 |
+check_PROGRAMS = $(programs) check_clamd |
|
19 | 19 |
check_SCRIPTS = $(scripts) |
20 | 20 |
|
21 | 21 |
if HAVE_LIBCHECK |
22 |
-check_clamav_SOURCES = check_clamav.c checks.h $(top_builddir)/libclamav/clamav.h\ |
|
22 |
+check_clamav_SOURCES = check_clamav.c checks.h checks_common.h $(top_builddir)/libclamav/clamav.h\ |
|
23 | 23 |
check_jsnorm.c check_str.c check_regex.c\ |
24 | 24 |
check_disasm.c check_uniq.c check_matchers.c\ |
25 | 25 |
check_htmlnorm.c |
26 | 26 |
check_clamav_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" |
27 | 27 |
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@ |
28 |
+check_clamd_SOURCES = check_clamd.c checks_common.h |
|
29 |
+check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" |
|
30 |
+check_clamd_LDADD = @CHECK_LIBS@ @CLAMD_LIBS@ |
|
28 | 31 |
else |
32 |
+check_clamd_SOURCES = check_clamav_skip.c |
|
29 | 33 |
check_clamav_SOURCES = check_clamav_skip.c |
30 | 34 |
endif |
31 | 35 |
|
32 |
-check_clamd.sh: $(top_builddir)/test/clam.exe |
|
36 |
+check_clamd.sh: $(top_builddir)/test/clam.exe check_clamd |
|
33 | 37 |
check_clamscan.sh: $(top_builddir)/test/clam.exe |
34 | 38 |
|
35 | 39 |
$(top_builddir)/test/clam.exe: |
... | ... |
@@ -34,7 +34,7 @@ host_triplet = @host@ |
34 | 34 |
target_triplet = @target@ |
35 | 35 |
@ENABLE_UNRAR_FALSE@am__append_1 = export unrar_disabled=1; |
36 | 36 |
TESTS = $(am__EXEEXT_1) $(scripts) |
37 |
-check_PROGRAMS = $(am__EXEEXT_1) |
|
37 |
+check_PROGRAMS = $(am__EXEEXT_1) check_clamd$(EXEEXT) |
|
38 | 38 |
subdir = unit_tests |
39 | 39 |
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in |
40 | 40 |
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
... | ... |
@@ -53,9 +53,9 @@ CONFIG_HEADER = $(top_builddir)/clamav-config.h |
53 | 53 |
CONFIG_CLEAN_FILES = |
54 | 54 |
am__EXEEXT_1 = check_clamav$(EXEEXT) |
55 | 55 |
am__check_clamav_SOURCES_DIST = check_clamav_skip.c check_clamav.c \ |
56 |
- checks.h $(top_builddir)/libclamav/clamav.h check_jsnorm.c \ |
|
57 |
- check_str.c check_regex.c check_disasm.c check_uniq.c \ |
|
58 |
- check_matchers.c check_htmlnorm.c |
|
56 |
+ checks.h checks_common.h $(top_builddir)/libclamav/clamav.h \ |
|
57 |
+ check_jsnorm.c check_str.c check_regex.c check_disasm.c \ |
|
58 |
+ check_uniq.c check_matchers.c check_htmlnorm.c |
|
59 | 59 |
@HAVE_LIBCHECK_FALSE@am_check_clamav_OBJECTS = \ |
60 | 60 |
@HAVE_LIBCHECK_FALSE@ check_clamav-check_clamav_skip.$(OBJEXT) |
61 | 61 |
@HAVE_LIBCHECK_TRUE@am_check_clamav_OBJECTS = \ |
... | ... |
@@ -70,6 +70,14 @@ am__check_clamav_SOURCES_DIST = check_clamav_skip.c check_clamav.c \ |
70 | 70 |
check_clamav_OBJECTS = $(am_check_clamav_OBJECTS) |
71 | 71 |
@HAVE_LIBCHECK_TRUE@check_clamav_DEPENDENCIES = \ |
72 | 72 |
@HAVE_LIBCHECK_TRUE@ $(top_builddir)/libclamav/libclamav.la |
73 |
+am__check_clamd_SOURCES_DIST = check_clamav_skip.c check_clamd.c \ |
|
74 |
+ checks_common.h |
|
75 |
+@HAVE_LIBCHECK_FALSE@am_check_clamd_OBJECTS = \ |
|
76 |
+@HAVE_LIBCHECK_FALSE@ check_clamd-check_clamav_skip.$(OBJEXT) |
|
77 |
+@HAVE_LIBCHECK_TRUE@am_check_clamd_OBJECTS = \ |
|
78 |
+@HAVE_LIBCHECK_TRUE@ check_clamd-check_clamd.$(OBJEXT) |
|
79 |
+check_clamd_OBJECTS = $(am_check_clamd_OBJECTS) |
|
80 |
+check_clamd_DEPENDENCIES = |
|
73 | 81 |
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) |
74 | 82 |
depcomp = $(SHELL) $(top_srcdir)/config/depcomp |
75 | 83 |
am__depfiles_maybe = depfiles |
... | ... |
@@ -82,8 +90,9 @@ CCLD = $(CC) |
82 | 82 |
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ |
83 | 83 |
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ |
84 | 84 |
$(LDFLAGS) -o $@ |
85 |
-SOURCES = $(check_clamav_SOURCES) |
|
86 |
-DIST_SOURCES = $(am__check_clamav_SOURCES_DIST) |
|
85 |
+SOURCES = $(check_clamav_SOURCES) $(check_clamd_SOURCES) |
|
86 |
+DIST_SOURCES = $(am__check_clamav_SOURCES_DIST) \ |
|
87 |
+ $(am__check_clamd_SOURCES_DIST) |
|
87 | 88 |
ETAGS = etags |
88 | 89 |
CTAGS = ctags |
89 | 90 |
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) |
... | ... |
@@ -253,13 +262,17 @@ TESTS_ENVIRONMENT = export abs_srcdir=$(abs_srcdir) AWK=$(AWK); \ |
253 | 253 |
$(am__append_1) |
254 | 254 |
check_SCRIPTS = $(scripts) |
255 | 255 |
@HAVE_LIBCHECK_FALSE@check_clamav_SOURCES = check_clamav_skip.c |
256 |
-@HAVE_LIBCHECK_TRUE@check_clamav_SOURCES = check_clamav.c checks.h $(top_builddir)/libclamav/clamav.h\ |
|
256 |
+@HAVE_LIBCHECK_TRUE@check_clamav_SOURCES = check_clamav.c checks.h checks_common.h $(top_builddir)/libclamav/clamav.h\ |
|
257 | 257 |
@HAVE_LIBCHECK_TRUE@ check_jsnorm.c check_str.c check_regex.c\ |
258 | 258 |
@HAVE_LIBCHECK_TRUE@ check_disasm.c check_uniq.c check_matchers.c\ |
259 | 259 |
@HAVE_LIBCHECK_TRUE@ check_htmlnorm.c |
260 | 260 |
|
261 | 261 |
@HAVE_LIBCHECK_TRUE@check_clamav_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" |
262 | 262 |
@HAVE_LIBCHECK_TRUE@check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@ |
263 |
+@HAVE_LIBCHECK_FALSE@check_clamd_SOURCES = check_clamav_skip.c |
|
264 |
+@HAVE_LIBCHECK_TRUE@check_clamd_SOURCES = check_clamd.c checks_common.h |
|
265 |
+@HAVE_LIBCHECK_TRUE@check_clamd_CPPFLAGS = -I$(top_srcdir) @CHECK_CPPFLAGS@ -DSRCDIR=\"$(abs_srcdir)\" |
|
266 |
+@HAVE_LIBCHECK_TRUE@check_clamd_LDADD = @CHECK_LIBS@ @CLAMD_LIBS@ |
|
263 | 267 |
CLEANFILES = lcov.out *.gcno *.gcda *.log $(FILES) test-stderr.log clamscan.log valgrind-*.log duma.log duma2.log clamscan2.log |
264 | 268 |
EXTRA_DIST = .split $(srcdir)/*.ref input test-clamd.conf test-freshclam.conf valgrind.supp virusaction-test.sh $(scripts) preload_run.sh |
265 | 269 |
@ENABLE_COVERAGE_TRUE@LCOV_OUTPUT = lcov.out |
... | ... |
@@ -311,6 +324,9 @@ clean-checkPROGRAMS: |
311 | 311 |
check_clamav$(EXEEXT): $(check_clamav_OBJECTS) $(check_clamav_DEPENDENCIES) |
312 | 312 |
@rm -f check_clamav$(EXEEXT) |
313 | 313 |
$(LINK) $(check_clamav_OBJECTS) $(check_clamav_LDADD) $(LIBS) |
314 |
+check_clamd$(EXEEXT): $(check_clamd_OBJECTS) $(check_clamd_DEPENDENCIES) |
|
315 |
+ @rm -f check_clamd$(EXEEXT) |
|
316 |
+ $(LINK) $(check_clamd_OBJECTS) $(check_clamd_LDADD) $(LIBS) |
|
314 | 317 |
|
315 | 318 |
mostlyclean-compile: |
316 | 319 |
-rm -f *.$(OBJEXT) |
... | ... |
@@ -327,6 +343,8 @@ distclean-compile: |
327 | 327 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_regex.Po@am__quote@ |
328 | 328 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_str.Po@am__quote@ |
329 | 329 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_uniq.Po@am__quote@ |
330 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamd-check_clamav_skip.Po@am__quote@ |
|
331 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamd-check_clamd.Po@am__quote@ |
|
330 | 332 |
|
331 | 333 |
.c.o: |
332 | 334 |
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
... | ... |
@@ -475,6 +493,34 @@ check_clamav-check_htmlnorm.obj: check_htmlnorm.c |
475 | 475 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
476 | 476 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamav_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o check_clamav-check_htmlnorm.obj `if test -f 'check_htmlnorm.c'; then $(CYGPATH_W) 'check_htmlnorm.c'; else $(CYGPATH_W) '$(srcdir)/check_htmlnorm.c'; fi` |
477 | 477 |
|
478 |
+check_clamd-check_clamav_skip.o: check_clamav_skip.c |
|
479 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT check_clamd-check_clamav_skip.o -MD -MP -MF $(DEPDIR)/check_clamd-check_clamav_skip.Tpo -c -o check_clamd-check_clamav_skip.o `test -f 'check_clamav_skip.c' || echo '$(srcdir)/'`check_clamav_skip.c |
|
480 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamd-check_clamav_skip.Tpo $(DEPDIR)/check_clamd-check_clamav_skip.Po |
|
481 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_clamav_skip.c' object='check_clamd-check_clamav_skip.o' libtool=no @AMDEPBACKSLASH@ |
|
482 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
483 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o check_clamd-check_clamav_skip.o `test -f 'check_clamav_skip.c' || echo '$(srcdir)/'`check_clamav_skip.c |
|
484 |
+ |
|
485 |
+check_clamd-check_clamav_skip.obj: check_clamav_skip.c |
|
486 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT check_clamd-check_clamav_skip.obj -MD -MP -MF $(DEPDIR)/check_clamd-check_clamav_skip.Tpo -c -o check_clamd-check_clamav_skip.obj `if test -f 'check_clamav_skip.c'; then $(CYGPATH_W) 'check_clamav_skip.c'; else $(CYGPATH_W) '$(srcdir)/check_clamav_skip.c'; fi` |
|
487 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamd-check_clamav_skip.Tpo $(DEPDIR)/check_clamd-check_clamav_skip.Po |
|
488 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_clamav_skip.c' object='check_clamd-check_clamav_skip.obj' libtool=no @AMDEPBACKSLASH@ |
|
489 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
490 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o check_clamd-check_clamav_skip.obj `if test -f 'check_clamav_skip.c'; then $(CYGPATH_W) 'check_clamav_skip.c'; else $(CYGPATH_W) '$(srcdir)/check_clamav_skip.c'; fi` |
|
491 |
+ |
|
492 |
+check_clamd-check_clamd.o: check_clamd.c |
|
493 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT check_clamd-check_clamd.o -MD -MP -MF $(DEPDIR)/check_clamd-check_clamd.Tpo -c -o check_clamd-check_clamd.o `test -f 'check_clamd.c' || echo '$(srcdir)/'`check_clamd.c |
|
494 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamd-check_clamd.Tpo $(DEPDIR)/check_clamd-check_clamd.Po |
|
495 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_clamd.c' object='check_clamd-check_clamd.o' libtool=no @AMDEPBACKSLASH@ |
|
496 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
497 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o check_clamd-check_clamd.o `test -f 'check_clamd.c' || echo '$(srcdir)/'`check_clamd.c |
|
498 |
+ |
|
499 |
+check_clamd-check_clamd.obj: check_clamd.c |
|
500 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT check_clamd-check_clamd.obj -MD -MP -MF $(DEPDIR)/check_clamd-check_clamd.Tpo -c -o check_clamd-check_clamd.obj `if test -f 'check_clamd.c'; then $(CYGPATH_W) 'check_clamd.c'; else $(CYGPATH_W) '$(srcdir)/check_clamd.c'; fi` |
|
501 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamd-check_clamd.Tpo $(DEPDIR)/check_clamd-check_clamd.Po |
|
502 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_clamd.c' object='check_clamd-check_clamd.obj' libtool=no @AMDEPBACKSLASH@ |
|
503 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
504 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(check_clamd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o check_clamd-check_clamd.obj `if test -f 'check_clamd.c'; then $(CYGPATH_W) 'check_clamd.c'; else $(CYGPATH_W) '$(srcdir)/check_clamd.c'; fi` |
|
505 |
+ |
|
478 | 506 |
mostlyclean-libtool: |
479 | 507 |
-rm -f *.lo |
480 | 508 |
|
... | ... |
@@ -740,7 +786,7 @@ check_clamd.sh: $(FILES) |
740 | 740 |
$(FILES) : |
741 | 741 |
cat $(SPLIT_DIR)/split.$@aa $(SPLIT_DIR)/split.$@ab > $@ |
742 | 742 |
|
743 |
-check_clamd.sh: $(top_builddir)/test/clam.exe |
|
743 |
+check_clamd.sh: $(top_builddir)/test/clam.exe check_clamd |
|
744 | 744 |
check_clamscan.sh: $(top_builddir)/test/clam.exe |
745 | 745 |
|
746 | 746 |
$(top_builddir)/test/clam.exe: |
747 | 747 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,153 @@ |
0 |
+#if HAVE_CONFIG_H |
|
1 |
+#include "clamav-config.h" |
|
2 |
+#endif |
|
3 |
+ |
|
4 |
+#include <stdio.h> |
|
5 |
+#include <stdlib.h> |
|
6 |
+#include <string.h> |
|
7 |
+#include <errno.h> |
|
8 |
+#include <signal.h> |
|
9 |
+#ifdef HAVE_SYS_TYPES_H |
|
10 |
+#include <sys/types.h> |
|
11 |
+#endif |
|
12 |
+#include <sys/socket.h> |
|
13 |
+#include <sys/un.h> |
|
14 |
+#include <check.h> |
|
15 |
+#include "checks_common.h" |
|
16 |
+#include "libclamav/version.h" |
|
17 |
+ |
|
18 |
+#ifdef CHECK_HAVE_LOOPS |
|
19 |
+ |
|
20 |
+static int sockd; |
|
21 |
+#define SOCKET "clamd-test.socket" |
|
22 |
+static void conn_setup(void) |
|
23 |
+{ |
|
24 |
+ int rc; |
|
25 |
+ struct sockaddr_un nixsock; |
|
26 |
+ memset((void *)&nixsock, 0, sizeof(nixsock)); |
|
27 |
+ nixsock.sun_family = AF_UNIX; |
|
28 |
+ strncpy(nixsock.sun_path, SOCKET, sizeof(nixsock.sun_path)); |
|
29 |
+ |
|
30 |
+ sockd = socket(AF_UNIX, SOCK_STREAM, 0); |
|
31 |
+ fail_unless_fmt(sockd != -1, "Unable to create socket: %s\n", strerror(errno)); |
|
32 |
+ |
|
33 |
+ rc = connect(sockd, (struct sockaddr *)&nixsock, sizeof(nixsock)); |
|
34 |
+ fail_unless_fmt(rc != -1, "Unable to connect(): %s\n", strerror(errno)); |
|
35 |
+ |
|
36 |
+ signal(SIGPIPE, SIG_IGN); |
|
37 |
+} |
|
38 |
+ |
|
39 |
+static void conn_teardown(void) |
|
40 |
+{ |
|
41 |
+ if (sockd != -1) |
|
42 |
+ close(sockd); |
|
43 |
+} |
|
44 |
+ |
|
45 |
+#ifndef REPO_VERSION |
|
46 |
+#define REPO_VERSION VERSION |
|
47 |
+#endif |
|
48 |
+static struct basic_test { |
|
49 |
+ const char *command; |
|
50 |
+ const char *reply; |
|
51 |
+} basic_tests[] = { |
|
52 |
+ {"PING", "PONG"}, |
|
53 |
+ {"RELOAD","RELOADING"}, |
|
54 |
+ {"VERSION", "ClamAV "REPO_VERSION""VERSION_SUFFIX} |
|
55 |
+}; |
|
56 |
+ |
|
57 |
+static void *recvfull(int sd, size_t *len) |
|
58 |
+{ |
|
59 |
+ char *buf = NULL; |
|
60 |
+ size_t off = 0; |
|
61 |
+ int rc; |
|
62 |
+ |
|
63 |
+ *len = 0; |
|
64 |
+ do { |
|
65 |
+ if (off + BUFSIZ > *len) { |
|
66 |
+ *len += BUFSIZ+1; |
|
67 |
+ buf = realloc(buf, *len); |
|
68 |
+ fail_unless(!!buf, "Cannot realloc buffer\n"); |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ rc = recv(sd, buf + off, BUFSIZ, 0); |
|
72 |
+ fail_unless_fmt(rc != -1, "recv() failed: %s\n", strerror(errno)); |
|
73 |
+ off += rc; |
|
74 |
+ } while (rc); |
|
75 |
+ buf[*len] = '\0'; |
|
76 |
+ *len = off; |
|
77 |
+ return buf; |
|
78 |
+} |
|
79 |
+ |
|
80 |
+static void test_command(const char *cmd, size_t len, const char *expect, size_t expect_len) |
|
81 |
+{ |
|
82 |
+ void *recvdata; |
|
83 |
+ int rc; |
|
84 |
+ rc = send(sockd, cmd, len, 0); |
|
85 |
+ fail_unless_fmt(rc != -1, "Unable to send(): %s\n", strerror(errno)); |
|
86 |
+ |
|
87 |
+ recvdata = recvfull(sockd, &len); |
|
88 |
+ |
|
89 |
+ fail_unless_fmt(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s\n", |
|
90 |
+ len, expect_len, recvdata); |
|
91 |
+ |
|
92 |
+ rc = memcmp(recvdata, expect, expect_len); |
|
93 |
+ fail_unless_fmt(!rc, "Wrong reply for command %s: |%s|, expected: |%s|\n", cmd, recvdata, expect); |
|
94 |
+ free(recvdata); |
|
95 |
+} |
|
96 |
+ |
|
97 |
+START_TEST (test_basic_commands) |
|
98 |
+{ |
|
99 |
+ int rc; |
|
100 |
+ struct basic_test *test = &basic_tests[_i]; |
|
101 |
+ size_t len; |
|
102 |
+ char nsend[BUFSIZ], nreply[BUFSIZ]; |
|
103 |
+ /* send the command the "old way" */ |
|
104 |
+ conn_setup(); |
|
105 |
+ snprintf(nreply, sizeof(nreply), "%s\n", test->reply); |
|
106 |
+ test_command(test->command, strlen(test->command), nreply, strlen(nreply)); |
|
107 |
+ conn_teardown(); |
|
108 |
+ |
|
109 |
+ /* send nCOMMAND */ |
|
110 |
+ conn_setup(); |
|
111 |
+ snprintf(nsend, sizeof(nsend), "n%s\n", test->command); |
|
112 |
+ test_command(nsend, strlen(nsend), nreply, strlen(nreply)); |
|
113 |
+ conn_teardown(); |
|
114 |
+ |
|
115 |
+ /* send zCOMMAND */ |
|
116 |
+ conn_setup(); |
|
117 |
+ snprintf(nsend, sizeof(nsend), "z%s\0", test->command); |
|
118 |
+ test_command(nsend, strlen(nsend)+1, test->reply, strlen(test->reply)+1); |
|
119 |
+ conn_teardown(); |
|
120 |
+} |
|
121 |
+END_TEST |
|
122 |
+ |
|
123 |
+static Suite *test_clamd_suite(void) |
|
124 |
+{ |
|
125 |
+ Suite *s = suite_create("clamd"); |
|
126 |
+ TCase *tc_commands = tcase_create("clamd commands"); |
|
127 |
+ suite_add_tcase(s, tc_commands); |
|
128 |
+ tcase_add_loop_test(tc_commands, test_basic_commands, 0, sizeof(basic_tests)/sizeof(basic_tests[0])); |
|
129 |
+ |
|
130 |
+ return s; |
|
131 |
+} |
|
132 |
+ |
|
133 |
+int main(void) |
|
134 |
+{ |
|
135 |
+ int nf; |
|
136 |
+ Suite *s = test_clamd_suite(); |
|
137 |
+ SRunner *sr = srunner_create(s); |
|
138 |
+ srunner_set_log(sr, "test-clamd.log"); |
|
139 |
+ srunner_run_all(sr, CK_NORMAL); |
|
140 |
+ nf = srunner_ntests_failed(sr); |
|
141 |
+ srunner_free(sr); |
|
142 |
+ return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
|
143 |
+} |
|
144 |
+ |
|
145 |
+#else |
|
146 |
+int main(void) |
|
147 |
+{ |
|
148 |
+ puts("\n*** Check version too old, clamd tests not run!\n"); |
|
149 |
+ /* tell automake the test was skipped */ |
|
150 |
+ return 77; |
|
151 |
+} |
|
152 |
+#endif |
... | ... |
@@ -1,18 +1,7 @@ |
1 | 1 |
#ifndef CHECKS_H |
2 | 2 |
#define CHECKS_H |
3 | 3 |
|
4 |
-#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 3)) |
|
5 |
-#define CHECK_HAVE_LOOPS |
|
6 |
-#endif |
|
7 |
- |
|
8 |
-#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 0)) |
|
9 |
-#define fail_unless_fmt fail_unless |
|
10 |
-#define fail_fmt fail |
|
11 |
-#else |
|
12 |
-#define fail_unless_fmt(cond, msg, ...) fail_unless(cond, msg) |
|
13 |
-#define fail_fmt(msg, ...) fail(msg) |
|
14 |
-#endif |
|
15 |
- |
|
4 |
+#include "checks_common.h" |
|
16 | 5 |
Suite *test_jsnorm_suite(void); |
17 | 6 |
Suite *test_str_suite(void); |
18 | 7 |
Suite *test_regex_suite(void); |
19 | 8 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,16 @@ |
0 |
+#ifndef CHECKS_COMMON_H |
|
1 |
+#define CHECKS_COMMON_H |
|
2 |
+ |
|
3 |
+#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 3)) |
|
4 |
+#define CHECK_HAVE_LOOPS |
|
5 |
+#endif |
|
6 |
+ |
|
7 |
+#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 0)) |
|
8 |
+#define fail_unless_fmt fail_unless |
|
9 |
+#define fail_fmt fail |
|
10 |
+#else |
|
11 |
+#define fail_unless_fmt(cond, msg, ...) fail_unless(cond, msg) |
|
12 |
+#define fail_fmt(msg, ...) fail(msg) |
|
13 |
+#endif |
|
14 |
+ |
|
15 |
+#endif |