summaryrefslogtreecommitdiffstats
path: root/test/rspamd_radix_test.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-15 10:46:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-15 10:46:40 +0100
commit3d36d9cc642c27338cd9fb7bb5f6cdc9da3fb216 (patch)
tree5be031b838e5bf881cc2e8c99c61f8f3d870dcbd /test/rspamd_radix_test.c
parent34b343ece7bc2c8cb868223b8c0a447c279a2f24 (diff)
downloadrspamd-3d36d9cc642c27338cd9fb7bb5f6cdc9da3fb216.tar.gz
rspamd-3d36d9cc642c27338cd9fb7bb5f6cdc9da3fb216.zip
Improve radix trie tests.
Diffstat (limited to 'test/rspamd_radix_test.c')
-rw-r--r--test/rspamd_radix_test.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/test/rspamd_radix_test.c b/test/rspamd_radix_test.c
index 3d37a1106..e7ef9fe98 100644
--- a/test/rspamd_radix_test.c
+++ b/test/rspamd_radix_test.c
@@ -26,7 +26,51 @@
#include "radix.h"
#include "ottery.h"
-const gsize max_elts = 50 * 1024 * 1024;
+const gsize max_elts = 5 * 1024 * 1024;
+
+struct _tv {
+ const char *ip;
+ const char *m;
+ guint32 mask;
+ guint32 addr;
+} test_vec[] = {
+ {"192.168.1.1", "32", 0, 0},
+ {"192.168.1.1", "24", 0, 0},
+ {"192.168.1.1", "8", 0, 0},
+ {"172.16.1.1", "8", 0, 0},
+ {"172.16.1.1", "16", 0, 0},
+ {"172.16.1.1", "24", 0, 0},
+ {"8.8.8.8", "1", 0, 0},
+ {NULL, NULL, 0, 0}
+};
+
+static void
+rspamd_radix_text_vec (void)
+{
+ radix_compressed_t *tree = radix_tree_create_compressed ();
+ struct _tv *t = &test_vec[0];
+ struct in_addr ina;
+
+ while (t->ip != NULL) {
+ inet_aton (t->ip, &ina);
+ t->addr = ina.s_addr;
+ t->mask = strtoul (t->m, NULL, 10);
+ t ++;
+ }
+ t = &test_vec[0];
+
+ while (t->ip != NULL) {
+ radix_insert_compressed (tree, &t->addr, sizeof (guint32), 32 - t->mask, 1);
+ t ++;
+ }
+
+ t = &test_vec[0];
+ while (t->ip != NULL) {
+ g_assert (radix_find_compressed (tree, &t->addr, sizeof (guint32))
+ != RADIX_NO_VALUE);
+ t ++;
+ }
+}
void
rspamd_radix_test_func (void)
@@ -47,12 +91,13 @@ rspamd_radix_test_func (void)
for (i = 0; i < nelts; i ++) {
addrs[i].addr = ottery_rand_uint32 ();
- addrs[i].mask = ottery_rand_range (32) + 1;
+ addrs[i].mask = ottery_rand_range (32);
}
clock_gettime (CLOCK_MONOTONIC, &ts1);
for (i = 0; i < nelts; i ++) {
- radix32tree_insert (tree, addrs[i].addr, addrs[i].mask, 1);
+ guint32 mask = G_MAXUINT32 << (32 - addrs[i].mask);
+ radix32tree_insert (tree, addrs[i].addr, mask, 1);
}
clock_gettime (CLOCK_MONOTONIC, &ts2);
diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
@@ -79,7 +124,32 @@ rspamd_radix_test_func (void)
(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);
+ rspamd_radix_text_vec ();
+ radix_compressed_t *comp_tree = radix_tree_create_compressed ();
+
+ clock_gettime (CLOCK_MONOTONIC, &ts1);
+ for (i = 0; i < nelts; i ++) {
+ radix_insert_compressed (comp_tree, &addrs[i].addr, sizeof (guint32),
+ 32 - 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 (radix_find_compressed (comp_tree, &addrs[i].addr, sizeof (guint32))
+ != 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);
+
+ g_free (addrs);
}