fix unit tests when mpool is activated

git-svn: trunk@4323
0.95
Török Edvin 17 years ago
parent 7a81091e7f
commit 563582a1ec
  1. 9
      ChangeLog
  2. 3
      contrib/clamdtop/TODO
  3. 3
      libclamav/libclamav.map
  4. 10
      libclamav/matcher-ac.c
  5. 9
      libclamav/matcher-bm.c
  6. 1
      libclamav/regex_list.c
  7. 29
      unit_tests/check_clamav.c
  8. 6
      unit_tests/check_htmlnorm.c
  9. 15
      unit_tests/check_jsnorm.c
  10. 12
      unit_tests/check_matchers.c
  11. 9
      unit_tests/check_regex.c
  12. 4
      unit_tests/checks.h

@ -1,3 +1,12 @@
Sat Nov 1 19:52:25 EET 2008 (edwin)
------------------------------------
* libclamav/libclamav.map, libclamav/matcher-ac.c,
libclamav/matcher-bm.c, libclamav/regex_list.c,
unit_tests/check_clamav.c, unit_tests/check_htmlnorm.c,
unit_tests/check_jsnorm.c, unit_tests/check_matchers.c,
unit_tests/check_regex.c, unit_tests/checks.h: fix unit tests when
mpool is activated
Sat Nov 1 03:51:58 CET 2008 (acab)
-----------------------------------
* mempool: New configure option --enable-mempool (requires mmap)

@ -0,0 +1,3 @@
monitor more than one remote clamd
write a manpage
consider writing a GUI using Tk 8.5 (version 8.5 has much nicer widgets than 8.4)

@ -118,6 +118,9 @@ CLAMAV_PRIVATE {
cli_bm_scanbuff;
cli_bm_free;
html_screnc_decode;
mp_create;
mp_destroy;
mp_free;
local:
*;
};

@ -26,6 +26,13 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
/* TODO: this should be in a common header */
#ifndef CL_DEBUG
#define NDEBUG
#endif
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -300,6 +307,9 @@ int cli_ac_buildtrie(struct cli_matcher *root)
int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth)
{
#ifdef USE_MPOOL
assert(root->mempool && "mempool must be initialized");
#endif
root->ac_root = (struct cli_ac_node *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
if(!root->ac_root) {

@ -22,8 +22,11 @@
#include "clamav-config.h"
#endif
#ifndef CL_DEBUG
#define NDEBUG
#endif
#include <stdio.h>
#include <assert.h>
#include "clamav.h"
#include "memory.h"
#include "others.h"
@ -98,7 +101,9 @@ int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern)
int cli_bm_init(struct cli_matcher *root)
{
uint16_t i, size = HASH(255, 255, 255) + 1;
#ifdef USE_MPOOL
assert (root->mempool && "mempool must be initialized");
#endif
if(!(root->bm_shift = (uint8_t *) mp_calloc(root->mempool, size, sizeof(uint8_t))))
return CL_EMEM;

@ -360,6 +360,7 @@ int init_regex_list(struct regex_matcher* matcher)
#ifdef USE_MPOOL
matcher->mempool = mp;
matcher->suffixes.mempool = mp;
assert(mp && "mempool must be initialized");
#endif
if((rc = cli_ac_init(&matcher->suffixes, 2, 32))) {
return rc;

@ -375,6 +375,35 @@ void diff_files(int fd, int ref_fd)
free(ref);
}
#ifdef USE_MEMPOOL
static mp_t *pool;
#else
static void *pool;
#endif
struct cli_dconf *dconf;
void dconf_setup(void)
{
pool = NULL;
dconf = NULL;
#ifdef USE_MEMPOOL
pool = mp_create();
fail_unless(!!pool, "unable to create pool");
#endif
dconf = cli_mp_dconf_init(pool);
fail_unless(!!dconf, "failed to init dconf");
}
void dconf_teardown(void)
{
mp_free(pool, dconf);
#ifdef USE_MEMPOOL
if (pool)
mp_destroy(pool);
#endif
}
int main(int argc, char **argv)
{
int nf;

@ -28,19 +28,17 @@
#include "../libclamav/others.h"
static char *dir;
static struct cli_dconf *dconf;
static void htmlnorm_setup(void)
{
dconf = cli_dconf_init();
dconf_setup();
dir = cli_gentemp(NULL);
fail_unless(!!dconf, "failed to init dconf");
fail_unless(!!dir, "cli_gentemp failed");
}
static void htmlnorm_teardown(void)
{
free(dconf);
dconf_teardown();
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
free(dir);
dir = NULL;

@ -180,16 +180,13 @@ START_TEST (js_begin_end)
{
char buf[16384] = "</script>";
size_t p;
struct cli_dconf *dconf = cli_dconf_init();
fail_unless(!!dconf, "failed to init dconf");
for(p=strlen(buf); p < 8191; p++) {
buf[p++] = 'a';
buf[p] = ' ';
}
strncpy(buf + 8192, " stuff stuff <script language='javascript'> function () {}", 8192);
fail_unless(html_normalise_mem((unsigned char*)buf, sizeof(buf), NULL, NULL, dconf) == 1, "normalise");
free(dconf);
}
END_TEST
@ -198,12 +195,10 @@ START_TEST (multiple_scripts)
char buf[] = "</script> stuff"\
"<script language='Javascript'> function foo() {} </script>"\
"<script language='Javascript'> function bar() {} </script>";
struct cli_dconf *dconf = cli_dconf_init();
fail_unless(!!dconf, "failed to init dconf");
fail_unless(html_normalise_mem((unsigned char*)buf, sizeof(buf), NULL, NULL, dconf) == 1, "normalise");
/* TODO: test that both had been normalized */
free(dconf);
}
END_TEST
@ -427,7 +422,6 @@ END_TEST
START_TEST (screnc_infloop)
{
char buf[24700] = "<%@ language='jscript.encode'>";
struct cli_dconf *dconf = cli_dconf_init();
size_t p;
fail_unless(!!dconf, "failed to init dconf");
@ -439,7 +433,6 @@ START_TEST (screnc_infloop)
}
strncpy(buf+24626,"#@~^ ", 10);
fail_unless(html_normalise_mem((unsigned char*)buf, sizeof(buf), NULL, NULL, dconf) == 1, "normalise");
free(dconf);
}
END_TEST
@ -497,14 +490,12 @@ Suite *test_jsnorm_suite(void)
#endif
tcase_add_test(tc_jsnorm_tokenizer, js_buffer);
tc_jsnorm_bugs = tcase_create("jsnorm bugs");
tc_jsnorm_bugs = tcase_create("bugs");
suite_add_tcase (s, tc_jsnorm_bugs);
tcase_add_checked_fixture(tc_jsnorm_bugs, dconf_setup, dconf_teardown);
tcase_add_test(tc_jsnorm_bugs, js_begin_end);
tcase_add_test(tc_jsnorm_bugs, multiple_scripts);
tc_screnc_infloop = tcase_create("screnc infloop bug");
suite_add_tcase (s, tc_screnc_infloop);
tcase_add_test(tc_screnc_infloop, screnc_infloop);
tcase_add_test(tc_jsnorm_bugs, screnc_infloop);
return s;
}

@ -61,6 +61,9 @@ START_TEST (test_ac_scanbuff) {
fail_unless(root != NULL, "root == NULL");
root->ac_only = 1;
#ifdef USE_MEMPOOL
root->mempool = mp_create();
#endif
ret = cli_ac_init(root, AC_DEFAULT_MIN_DEPTH, AC_DEFAULT_MAX_DEPTH);
fail_unless(ret == CL_SUCCESS, "cli_ac_init() failed");
@ -83,6 +86,9 @@ START_TEST (test_ac_scanbuff) {
cli_ac_freedata(&mdata);
cli_ac_free(root);
#ifdef USE_MEMPOOL
mp_destroy(root->mempool);
#endif
free(root);
}
END_TEST
@ -96,6 +102,9 @@ START_TEST (test_bm_scanbuff) {
root = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher));
fail_unless(root != NULL, "root == NULL");
#ifdef USE_MEMPOOL
root->mempool = mp_create();
#endif
ret = cli_bm_init(root);
fail_unless(ret == CL_SUCCESS, "cli_bm_init() failed");
@ -110,6 +119,9 @@ START_TEST (test_bm_scanbuff) {
fail_unless(ret == CL_VIRUS, "cli_bm_scanbuff() failed");
fail_unless(!strncmp(virname, "Sig2", 4), "Incorrect signature matched in cli_bm_scanbuff()\n");
cli_bm_free(root);
#ifdef USE_MEMPOOL
mp_destroy(root->mempool);
#endif
free(root);
}
END_TEST

@ -153,13 +153,20 @@ static struct regex_matcher matcher;
static void rsetup(void)
{
int rc = init_regex_list(&matcher);
int rc;
#ifdef USE_MEMPOOL
matcher.mempool = mp_create();
#endif
rc = init_regex_list(&matcher);
fail_unless(rc == 0, "init_regex_list");
}
static void rteardown(void)
{
regex_list_done(&matcher);
#ifdef USE_MEMPOOL
mp_destroy(matcher.mempool);
#endif
}
static const struct rtest {

@ -25,4 +25,8 @@ int open_testfile(const char *name);
void diff_files(int fd, int reffd);
void diff_file_mem(int fd, const char *ref, size_t len);
extern struct cli_dconf *dconf;
void dconf_setup(void);
void dconf_teardown(void);
#endif

Loading…
Cancel
Save