diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-09-12 12:18:55 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-09-12 12:18:55 +0100 |
commit | aa48f9df195306f11b0b2a20541c97578a65cfbc (patch) | |
tree | 88b004077ce48327bc3ce23ec549515a7276014a /test | |
parent | 491e42b434921ed3d102956bb7ad1fe3697fef46 (diff) | |
download | rspamd-aa48f9df195306f11b0b2a20541c97578a65cfbc.tar.gz rspamd-aa48f9df195306f11b0b2a20541c97578a65cfbc.zip |
Add radix trie test suite.
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/rspamd_radix_test.c | 85 | ||||
-rw-r--r-- | test/rspamd_test_suite.c | 1 | ||||
-rw-r--r-- | test/tests.h | 3 |
4 files changed, 92 insertions, 2 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0972c506b..0767825f0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,12 +2,13 @@ SET(TESTSRC rspamd_expression_test.c rspamd_mem_pool_test.c rspamd_statfile_test.c rspamd_fuzzy_test.c - rspamd_test_suite.c rspamd_url_test.c rspamd_dns_test.c rspamd_async_test.c rspamd_dkim_test.c - rspamd_rrd_test.c) + rspamd_rrd_test.c + rspamd_radix_test.c + rspamd_test_suite.c) ADD_EXECUTABLE(rspamd-test EXCLUDE_FROM_ALL ${TESTSRC}) SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE C) diff --git a/test/rspamd_radix_test.c b/test/rspamd_radix_test.c new file mode 100644 index 000000000..3d37a1106 --- /dev/null +++ b/test/rspamd_radix_test.c @@ -0,0 +1,85 @@ +/* Copyright (c) 2014, 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 "main.h" +#include "radix.h" +#include "ottery.h" + +const gsize max_elts = 50 * 1024 * 1024; + +void +rspamd_radix_test_func (void) +{ + radix_tree_t *tree = radix_tree_create (); + struct { + guint32 addr; + guint32 mask; + } *addrs; + gsize nelts, i; + struct timespec ts1, ts2; + double diff; + + g_assert (tree != NULL); + nelts = max_elts; + /* First of all we generate many elements and push them to the array */ + addrs = g_malloc (nelts * sizeof (addrs[0])); + + for (i = 0; i < nelts; i ++) { + addrs[i].addr = ottery_rand_uint32 (); + addrs[i].mask = ottery_rand_range (32) + 1; + } + + clock_gettime (CLOCK_MONOTONIC, &ts1); + for (i = 0; i < nelts; i ++) { + radix32tree_insert (tree, addrs[i].addr, addrs[i].mask, 1); + } + clock_gettime (CLOCK_MONOTONIC, &ts2); + diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */ + (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */ + + msg_info ("Added %z elements in %.6f ms", nelts, diff); + + clock_gettime (CLOCK_MONOTONIC, &ts1); + for (i = 0; i < nelts; i ++) { + g_assert (radix32tree_find (tree, addrs[i].addr) != RADIX_NO_VALUE); + } + clock_gettime (CLOCK_MONOTONIC, &ts2); + diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */ + (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */ + + msg_info ("Checked %z elements in %.6f ms", nelts, diff); + + clock_gettime (CLOCK_MONOTONIC, &ts1); + for (i = 0; i < nelts; i ++) { + radix32tree_delete (tree, addrs[i].addr, addrs[i].mask); + } + clock_gettime (CLOCK_MONOTONIC, &ts2); + diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */ + (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */ + + msg_info ("Deleted %z elements in %.6f ms", nelts, diff); + g_free (addrs); + + radix_tree_free (tree); +} diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 73580a998..864d5a419 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -49,6 +49,7 @@ main (int argc, char **argv) g_test_add_func ("/rspamd/url", rspamd_url_test_func); g_test_add_func ("/rspamd/expression", rspamd_expression_test_func); g_test_add_func ("/rspamd/statfile", rspamd_statfile_test_func); + g_test_add_func ("/rspamd/radix", rspamd_radix_test_func); g_test_add_func ("/rspamd/dns", rspamd_dns_test_func); g_test_add_func ("/rspamd/aio", rspamd_async_test_func); g_test_add_func ("/rspamd/dkim", rspamd_dkim_test_func); diff --git a/test/tests.h b/test/tests.h index a6779f21a..129068920 100644 --- a/test/tests.h +++ b/test/tests.h @@ -20,6 +20,9 @@ void rspamd_fuzzy_test_func (void); /* Stat file */ void rspamd_statfile_test_func (void); +/* Radix test */ +void rspamd_radix_test_func (void); + /* DNS resolving */ void rspamd_dns_test_func (void); |