diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-09-12 11:56:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-09-12 11:56:42 +0100 |
commit | 491e42b434921ed3d102956bb7ad1fe3697fef46 (patch) | |
tree | 45986c3764c82d50f4fded5e7c05a25c875adfa9 | |
parent | ad29a3dd73648b23f818d7a62c6424a14a884e10 (diff) | |
download | rspamd-491e42b434921ed3d102956bb7ad1fe3697fef46.tar.gz rspamd-491e42b434921ed3d102956bb7ad1fe3697fef46.zip |
Restore testing framework.
-rw-r--r-- | test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/Makefile.in | 16 | ||||
-rw-r--r-- | test/rspamd_dkim_test.c | 21 | ||||
-rw-r--r-- | test/rspamd_dns_test.c | 115 | ||||
-rw-r--r-- | test/rspamd_expression_test.c | 8 | ||||
-rw-r--r-- | test/rspamd_fuzzy_test.c | 6 | ||||
-rw-r--r-- | test/rspamd_mem_pool_test.c | 6 | ||||
-rw-r--r-- | test/rspamd_memcached_test.c | 85 | ||||
-rw-r--r-- | test/rspamd_rcl_test.c | 196 | ||||
-rw-r--r-- | test/rspamd_rrd_test.c | 2 | ||||
-rw-r--r-- | test/rspamd_statfile_test.c | 16 | ||||
-rw-r--r-- | test/rspamd_test_suite.c | 13 | ||||
-rw-r--r-- | test/rspamd_url_test.c | 8 | ||||
-rw-r--r-- | test/tests.h | 6 |
14 files changed, 93 insertions, 410 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2877ac8fc..0972c506b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,4 @@ SET(TESTSRC rspamd_expression_test.c - rspamd_memcached_test.c rspamd_mem_pool_test.c rspamd_statfile_test.c rspamd_fuzzy_test.c @@ -8,8 +7,7 @@ SET(TESTSRC rspamd_expression_test.c rspamd_dns_test.c rspamd_async_test.c rspamd_dkim_test.c - rspamd_rrd_test.c - rspamd_rcl_test.c) + rspamd_rrd_test.c) ADD_EXECUTABLE(rspamd-test EXCLUDE_FROM_ALL ${TESTSRC}) SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE C) @@ -22,7 +20,6 @@ TARGET_LINK_LIBRARIES(rspamd-test ${CMAKE_REQUIRED_LIBRARIES}) TARGET_LINK_LIBRARIES(rspamd-test rspamd-mime) TARGET_LINK_LIBRARIES(rspamd-test rspamd-server) TARGET_LINK_LIBRARIES(rspamd-test rspamd-util) -TARGET_LINK_LIBRARIES(rspamd-test rspamd-rcl) TARGET_LINK_LIBRARIES(rspamd-test hiredis) IF(HAVE_LIBEVENT2) TARGET_LINK_LIBRARIES(rspamd-test event_pthreads) diff --git a/test/Makefile.in b/test/Makefile.in deleted file mode 100644 index 08f041e4e..000000000 --- a/test/Makefile.in +++ /dev/null @@ -1,16 +0,0 @@ -.PHONY: clean - -all: rspamd_test_suite - -rspamd_test_suite: $(OBJECTS) $(OBJ_DEPENDS) - $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) $(OBJ_DEPENDS) $(LIBS) -o rspamd_test_suite - -run_test: rspamd_test_suite - gtester --verbose -k -o=rspamd_test.xml ./rspamd_test_suite - less rspamd_test.xml && rm -f rspamd_test.xml - -clean: - rm -f *.o rspamd_test_suite *.core rspamd_test.xml - -dist-clean: clean - rm -f Makefile diff --git a/test/rspamd_dkim_test.c b/test/rspamd_dkim_test.c index bd2508262..b0491de0b 100644 --- a/test/rspamd_dkim_test.c +++ b/test/rspamd_dkim_test.c @@ -26,14 +26,13 @@ #include "main.h" #include "dkim.h" -static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; " - "bh=xTpleJNUaXMzaRU2xnfInn4n9hf/UHzWSuYzJ3s2WBc=; " - "b=cPya7FKbcJnCqMlCETci4ZlQTI/Tfw8y1/+AUSU+YBaDgLhsZMDPQMO0zzMvQM+c+E" - "i/J+BAckB9JRyPr9xXtV0ORSmUkFgeMyURopwdNzKQ9UB/JnGHj6i11ceV3b20UAYiIu" - "qrXhJD+YEgHYXVtfzTC4OLTJGjEQguEn2+RtlZV60aWsPizK+mqlVO4G57RGklp0vnqB" - "oc2XUGMVmOaCvVpQkJdJud1r5aKLhr9Bs0sM8/MaYugwmdSk2rLJUMfUPRyUmIGv3BAG" - "bwdvXghyl7HNOqPYwXvk/B8C7++k0VUUOix5M/XrcBMNyJu2fMZJMD8KSn3udFjp9vZ6" - "pRqg=="; +static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; " + "d=highsecure.ru; s=dkim; t=1410516996; " + "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; " + "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; " + "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW" + "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy" + "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;"; extern struct event_base *base; @@ -72,12 +71,12 @@ rspamd_dkim_test_func () cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config)); bzero (cfg, sizeof (struct rspamd_config)); cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); - cfg->dns_retransmits = 10; - cfg->dns_timeout = 1000; + cfg->dns_retransmits = 2; + cfg->dns_timeout = 0.5; pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); - resolver = dns_resolver_init (base, cfg); + resolver = dns_resolver_init (NULL, base, cfg); g_assert (resolver != NULL); diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c index 781b39503..5728b5a2d 100644 --- a/test/rspamd_dns_test.c +++ b/test/rspamd_dns_test.c @@ -1,110 +1,107 @@ -#include "../src/config.h" +#include "config.h" #include "tests.h" -#include "../src/dns.h" -#include "../src/logger.h" -#include "../src/main.h" -#include "../src/events.h" -#include "../src/cfg_file.h" +#include "dns.h" +#include "logger.h" +#include "main.h" +#include "events.h" +#include "cfg_file.h" static guint requests = 0; extern struct event_base *base; +struct rspamd_dns_resolver *resolver; -static void -test_dns_cb (struct rspamd_dns_reply *reply, gpointer arg) +gboolean +session_fin (gpointer unused) { - union rspamd_reply_element *elt; - GList *cur; + struct timeval tv; + + tv.tv_sec = 0; + tv.tv_usec = 0; + event_loopexit (&tv); - msg_debug ("got reply with code %s for request %s", dns_strerror (reply->code), reply->request->requested_name); - if (reply->code == DNS_RC_NOERROR) { - cur = reply->elements; + return TRUE; +} + +static void +test_dns_cb (struct rdns_reply *reply, gpointer arg) +{ + struct rdns_reply_entry *cur; + const struct rdns_request_name *name = + rdns_request_get_name (reply->request, NULL); + + msg_debug ("got reply with code %s for request %s", + rdns_strerror (reply->code), name->name); + if (reply->code == RDNS_RC_NOERROR) { + cur = reply->entries; while (cur) { - elt = cur->data; - switch (reply->request->type) { - case DNS_REQUEST_A: - msg_debug ("got ip: %s", inet_ntoa (elt->a.addr[0])); + switch (cur->type) { + case RDNS_REQUEST_A: + msg_debug ("got ip: %s", inet_ntoa (cur->content.a.addr)); break; - case DNS_REQUEST_PTR: - msg_debug ("got name %s", elt->ptr.name); + case RDNS_REQUEST_PTR: + msg_debug ("got name %s", cur->content.ptr.name); break; - case DNS_REQUEST_TXT: - msg_debug ("got txt %s", elt->txt.data); + case RDNS_REQUEST_TXT: + msg_debug ("got txt %s", cur->content.txt.data); break; - case DNS_REQUEST_SPF: - msg_debug ("got spf %s", elt->spf.data); + case RDNS_REQUEST_SPF: + msg_debug ("got spf %s", cur->content.txt.data); break; - case DNS_REQUEST_SRV: - msg_debug ("got srv pri: %d, weight: %d, port: %d, target: %s", elt->srv.weight, - elt->srv.priority, elt->srv.port, elt->srv.target); + case RDNS_REQUEST_SRV: + msg_debug ("got srv pri: %d, weight: %d, port: %d, target: %s", cur->content.srv.weight, + cur->content.srv.priority, cur->content.srv.port, cur->content.srv.target); break; - case DNS_REQUEST_MX: - msg_debug ("got mx %s:%d", elt->mx.name, elt->mx.priority); + case RDNS_REQUEST_MX: + msg_debug ("got mx %s:%d", cur->content.mx.name, cur->content.mx.priority); break; } - cur = g_list_next (cur); + cur = cur->next; } } if (-- requests == 0) { - destroy_session (reply->request->session); + session_fin (NULL); } } -gboolean -session_fin (gpointer unused) -{ - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = 0; - event_loopexit (&tv); - - return TRUE; -} - void rspamd_dns_test_func () { - struct rspamd_dns_resolver *resolver; + struct rspamd_config *cfg; rspamd_mempool_t *pool; struct rspamd_async_session *s; - struct in_addr ina; cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config)); bzero (cfg, sizeof (struct rspamd_config)); cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); - cfg->dns_retransmits = 10; - cfg->dns_timeout = 1000; + cfg->dns_retransmits = 2; + cfg->dns_timeout = 0.5; pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); s = new_async_session (pool, session_fin, NULL, NULL, NULL); - resolver = dns_resolver_init (base, cfg); - - ina.s_addr = inet_addr ("81.19.70.3"); + resolver = dns_resolver_init (NULL, base, cfg); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_A, "google.com")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_A, "google.com")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_PTR, &ina)); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_PTR, "81.19.70.3")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_MX, "rambler.ru")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_MX, "rambler.ru")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "rambler.ru")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "rambler.ru")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "google.com")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "google.com")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_SPF, "rambler.ru")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_SPF, "rambler.ru")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_SRV, "xmpp-server", "tcp", "jabber.org")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_SRV, "_xmpp-server._tcp.jabber.org")); requests ++; - g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "non-existent.arpa")); + g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_TXT, "non-existent.arpa")); g_assert (resolver != NULL); - - event_loop (0); } diff --git a/test/rspamd_expression_test.c b/test/rspamd_expression_test.c index 2ce9e4f87..f7939bd02 100644 --- a/test/rspamd_expression_test.c +++ b/test/rspamd_expression_test.c @@ -1,7 +1,7 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/cfg_file.h" -#include "../src/expressions.h" +#include "config.h" +#include "main.h" +#include "cfg_file.h" +#include "expressions.h" #include "tests.h" /* Vector of test expressions */ diff --git a/test/rspamd_fuzzy_test.c b/test/rspamd_fuzzy_test.c index a5c76cb34..7bee03164 100644 --- a/test/rspamd_fuzzy_test.c +++ b/test/rspamd_fuzzy_test.c @@ -1,6 +1,6 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/fuzzy.h" +#include "config.h" +#include "main.h" +#include "fuzzy.h" #include "tests.h" static char *s1 = "This is sample test text.\r\n" diff --git a/test/rspamd_mem_pool_test.c b/test/rspamd_mem_pool_test.c index 228644799..ba9a87aeb 100644 --- a/test/rspamd_mem_pool_test.c +++ b/test/rspamd_mem_pool_test.c @@ -1,7 +1,5 @@ - - -#include "../src/config.h" -#include "../src/mem_pool.h" +#include "config.h" +#include "mem_pool.h" #include "tests.h" #define TEST_BUF "test bufffer" diff --git a/test/rspamd_memcached_test.c b/test/rspamd_memcached_test.c deleted file mode 100644 index 0cd42c594..000000000 --- a/test/rspamd_memcached_test.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/cfg_file.h" -#include "../src/memcached.h" -#include "tests.h" - -static const u_char *buf = "test"; - -static void -memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data) -{ - struct timeval tv; - - switch (ctx->op) { - case CMD_CONNECT: - if (error != OK) { - msg_warn ("Connect failed, skipping test"); - memc_close_ctx (ctx); - tv.tv_sec = 0; - tv.tv_usec = 0; - event_loopexit (&tv); - } - msg_debug ("Connect ok"); - memc_set (ctx, ctx->param, 60); - break; - case CMD_READ: - g_assert (error == OK); - g_assert (!memcmp(ctx->param->buf, buf, ctx->param->bufsize)); - msg_debug ("Read ok"); - memc_close_ctx (ctx); - tv.tv_sec = 0; - tv.tv_usec = 0; - event_loopexit (&tv); - break; - case CMD_WRITE: - if (error != OK) { - msg_warn ("Connect failed, skipping test"); - memc_close_ctx (ctx); - tv.tv_sec = 0; - tv.tv_usec = 0; - event_loopexit (&tv); - } - msg_debug ("Write ok"); - ctx->param->buf = g_malloc (sizeof (buf)); - bzero (ctx->param->buf, sizeof (buf)); - memc_get (ctx, ctx->param); - break; - default: - return; - } -} - -void -rspamd_memcached_test_func () -{ - memcached_ctx_t *ctx; - memcached_param_t *param; - struct in_addr addr; - - ctx = g_malloc (sizeof (memcached_ctx_t)); - param = g_malloc (sizeof (memcached_param_t)); - bzero (ctx, sizeof (memcached_ctx_t)); - bzero (param, sizeof (memcached_param_t)); - - event_init (); - - ctx->callback = memcached_callback; - ctx->callback_data = (void *)param; - ctx->protocol = TCP_TEXT; - inet_aton ("127.0.0.1", &addr); - memcpy (&ctx->addr, &addr, sizeof (struct in_addr)); - ctx->port = htons (11211); - ctx->timeout.tv_sec = 1; - ctx->timeout.tv_usec = 0; - ctx->sock = -1; - ctx->options = MEMC_OPT_DEBUG; - rspamd_strlcpy (param->key, buf, sizeof (param->key)); - param->buf = buf; - param->bufsize = strlen (buf); - ctx->param = param; - g_assert (memc_init_ctx (ctx) != -1); - - event_loop (0); -} - diff --git a/test/rspamd_rcl_test.c b/test/rspamd_rcl_test.c deleted file mode 100644 index 778340890..000000000 --- a/test/rspamd_rcl_test.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (c) 2013, Vsevolod Stakhov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "rcl/rcl.h" -#include "main.h" -#include "json/jansson.h" -#include "tests.h" - -const gchar *rcl_test_valid[] = { - /* Json like */ - "{" - "\"key1\": value;" - "\"key1\": value2;" - "\"key1\": \"value;\"" - "}\n", - /* Nginx like */ - "section1 { param1 = value; param2 = value, " - "section3 {param = value; param2 = value, param3 = [\"value1\", value2, 100500]}}\n" - "section2 { param1 = {key = value}, param1 = [\"key\"]}", - /* Numbers */ - "key = 1s\n" - "key2 = 1min\n" - "key3 = 1kb\n" - "key4 = 5M\n" - "key5 = 10mS\n" - "key6 = 10y\n", - /* Strings */ - "key = \"some string\";" - "key1 = /some/path;" - "key3 = 111some," - "key4: s1," - "\"key5\": \"\\n\\r123\"", - "" - "#packagesite http//pkg.freebsd.org/freebsd-9-amd64/latest\n" - "#packagesite http//pkg.freebsd.org/freebsd-9-amd64/latest\n" - "packagesite: http//pkg.freebsd.org/freebsd-9-amd64/latest\n" - "ALIAS : {\n" - " all-depends: query %dn-%dv,\n" - " annotations: info -A,\n" - " build-depends: info -qd,\n" - " download: fetch,\n" - " iinfo: info -i -g -x,\n" - " isearch: search -i -g -x,\n" - " leaf: query -e '%a == 0' '%n-%v',\n" - " leaf: query -e '%a == 0' '%n-%v',\n" - " list: info -ql,\n" - " origin: info -qo,\n" - " provided-depends: info -qb,\n" - " raw: info -R,\n" - " required-depends: info -qr,\n" - " shared-depends: info -qB,\n" - " show: info -f -k,\n" - " size: info -sq,\n" - " }\n" - "\n" - "repo_dirs : [\n" - " /home/bapt,\n" - " /usr/local/etc\n" - "]\n" - "", - /* Macros */ - "section1 {key = value; section {\n" - "param = \"value\";\n" - "param2 = value\n" - "array = [ 1, 1mb, test]}\n" - ".includes \"./test.cfg\"}", - NULL -}; - -static const gchar test_pubkey[] = "" -"-----BEGIN PUBLIC KEY-----\n" -"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlhk2u5nbTVgEskmS+qZcAj339\n" -"bLwEK/TXdd0G3d4BVKpF712frw+YwetRdmRRYL5EdjiF01Bv3s6QmsThAJX/li/c\n" -"Q15YFxhvq9DZ0qJmL7e1NzORo6m/WLRK9wxWA+PXSvSUKrlZ3kt9ygD4z5QZ3/td\n" -"qil9VM6Mz7P1HJ0KywIDAQAB\n" -"-----END PUBLIC KEY-----\n"; - -void -rspamd_rcl_test_func (void) -{ - struct rspamd_cl_parser *parser, *parser2; - rspamd_cl_object_t *obj; - const gchar **cur; - guchar *emitted; - GError *err = NULL; - struct timespec start, end; - gdouble seconds; - json_t *json; - json_error_t jerr; - - cur = rcl_test_valid; - while (*cur != NULL) { - parser = rspamd_cl_parser_new (RSPAMD_CL_FLAG_KEY_LOWERCASE); - rspamd_cl_pubkey_add (parser, test_pubkey, sizeof (test_pubkey) - 1, &err); - g_assert_no_error (err); - g_assert (parser != NULL); - rspamd_cl_parser_add_chunk (parser, *cur, strlen (*cur), &err); - g_assert_no_error (err); - obj = rspamd_cl_parser_get_object (parser, &err); - g_assert_no_error (err); - /* Test config emitting */ - emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_CONFIG); - g_assert (emitted != NULL); - msg_debug ("got config output: %s", emitted); - parser2 = rspamd_cl_parser_new (RSPAMD_CL_FLAG_KEY_LOWERCASE); - g_assert (parser2 != NULL); - rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err); - g_assert_no_error (err); - rspamd_cl_parser_free (parser2); - g_free (emitted); - /* Test json emitted */ - emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_JSON); - g_assert (emitted != NULL); - msg_debug ("got json output: %s", emitted); - parser2 = rspamd_cl_parser_new (RSPAMD_CL_FLAG_KEY_LOWERCASE); - g_assert (parser2 != NULL); - rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err); - g_assert_no_error (err); - rspamd_cl_parser_free (parser2); - g_free (emitted); - /* Compact json */ - emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_JSON_COMPACT); - g_assert (emitted != NULL); - msg_debug ("got json compacted output: %s", emitted); - parser2 = rspamd_cl_parser_new (RSPAMD_CL_FLAG_KEY_LOWERCASE); - g_assert (parser2 != NULL); - rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err); - g_assert_no_error (err); - rspamd_cl_parser_free (parser2); - g_free (emitted); - - /* Cleanup */ - rspamd_cl_parser_free (parser); - rspamd_cl_obj_unref (obj); - cur ++; - } - - /* Load a big json */ - parser = rspamd_cl_parser_new (RSPAMD_CL_FLAG_KEY_LOWERCASE); - clock_gettime (CLOCK_MONOTONIC, &start); - rspamd_cl_parser_add_file (parser, "./rcl_test.json", &err); - g_assert_no_error (err); - obj = rspamd_cl_parser_get_object (parser, &err); - g_assert_no_error (err); - clock_gettime (CLOCK_MONOTONIC, &end); - seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("rcl: parsed json in %.4f seconds", seconds); - /* Test config emitting */ - clock_gettime (CLOCK_MONOTONIC, &start); - emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_CONFIG); - g_assert (emitted != NULL); - clock_gettime (CLOCK_MONOTONIC, &end); - seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("rcl: emitted object in %.4f seconds", seconds); - rspamd_cl_parser_free (parser); - rspamd_cl_obj_unref (obj); - g_free (emitted); - - clock_gettime (CLOCK_MONOTONIC, &start); - json = json_load_file ("./rcl_test.json", &jerr); - g_assert (json != NULL); - clock_gettime (CLOCK_MONOTONIC, &end); - seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("jansson: parsed json in %.4f seconds", seconds); - - clock_gettime (CLOCK_MONOTONIC, &start); - emitted = json_dumps (json, 0); - g_assert (emitted != NULL); - clock_gettime (CLOCK_MONOTONIC, &end); - seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("jansson: emitted object in %.4f seconds", seconds); - - //json_decref (json); - g_free (emitted); -} diff --git a/test/rspamd_rrd_test.c b/test/rspamd_rrd_test.c index 02996bdd9..3c81713c0 100644 --- a/test/rspamd_rrd_test.c +++ b/test/rspamd_rrd_test.c @@ -60,7 +60,7 @@ rspamd_rrd_test_func () /* Reopen */ g_assert ((rrd = rspamd_rrd_open (tmpfile, &err)) != NULL); /* Add some points */ - for (i = 0; i < 100; i += 10) { + for (i = 0; i < 20; i += 10) { sleep (1); t = i; ar.data = &t; diff --git a/test/rspamd_statfile_test.c b/test/rspamd_statfile_test.c index 870a827fa..753782c9c 100644 --- a/test/rspamd_statfile_test.c +++ b/test/rspamd_statfile_test.c @@ -1,7 +1,8 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/statfile.h" +#include "config.h" +#include "main.h" +#include "statfile.h" #include "tests.h" +#include "ottery.h" #define TEST_FILENAME "/tmp/rspamd_test.stat" #define HASHES_NUM 256 @@ -13,17 +14,14 @@ rspamd_statfile_test_func () rspamd_mempool_t *p; stat_file_t *st; uint32_t random_hashes[HASHES_NUM], i, v; - time_t now; + time_t now = time (NULL); p = rspamd_mempool_new (rspamd_mempool_suggest_size ()); umask (S_IWGRP | S_IWOTH); - pool = statfile_pool_new (p, 10 * 1024 * 1024, TRUE); + pool = statfile_pool_new (p, TRUE); - now = time (NULL); - /* Fill random array */ - srand (now); for (i = 0; i < HASHES_NUM; i ++) { - random_hashes[i] = rand (); + random_hashes[i] = ottery_rand_uint32 (); } /* Create new file */ diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 7bd86d483..73580a998 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -1,6 +1,6 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/cfg_file.h" +#include "config.h" +#include "main.h" +#include "cfg_file.h" #include "tests.h" struct rspamd_main *rspamd_main = NULL; @@ -38,15 +38,12 @@ main (int argc, char **argv) else { cfg->log_level = G_LOG_LEVEL_INFO; } + cfg->log_type = RSPAMD_LOG_CONSOLE; /* First set logger to console logger */ - rspamd_set_logger (RSPAMD_LOG_CONSOLE, g_quark_from_static_string("rspamd-test"), rspamd_main); + rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"), rspamd_main); (void)open_log (rspamd_main->logger); g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); -#if 0 - g_test_add_func ("/rspamd/memcached", rspamd_memcached_test_func); -#endif - g_test_add_func ("/rspamd/rcl", rspamd_rcl_test_func); g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func); g_test_add_func ("/rspamd/fuzzy", rspamd_fuzzy_test_func); g_test_add_func ("/rspamd/url", rspamd_url_test_func); diff --git a/test/rspamd_url_test.c b/test/rspamd_url_test.c index 92dc5a0d4..8acc6b324 100644 --- a/test/rspamd_url_test.c +++ b/test/rspamd_url_test.c @@ -1,7 +1,7 @@ -#include "../src/config.h" -#include "../src/main.h" -#include "../src/cfg_file.h" -#include "../src/url.h" +#include "config.h" +#include "main.h" +#include "cfg_file.h" +#include "url.h" #include "tests.h" const char *test_text = diff --git a/test/tests.h b/test/tests.h index dc484dbff..a6779f21a 100644 --- a/test/tests.h +++ b/test/tests.h @@ -8,9 +8,6 @@ /* URL parser test */ void rspamd_url_test_func (void); -/* Memcached library test */ -void rspamd_memcached_test_func (void); - /* Memory pools */ void rspamd_mem_pool_test_func (void); @@ -35,7 +32,4 @@ void rspamd_dkim_test_func (void); /* RRD test */ void rspamd_rrd_test_func (void); -/* RCL test */ -void rspamd_rcl_test_func (void); - #endif |