diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-12-15 04:17:10 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-12-15 04:17:10 +0400 |
commit | fbcc7af8a6bfb2c82d17180358bfdadf0228cddd (patch) | |
tree | 9990eedf87aa69052e646560b34372a9ad85f449 /test | |
parent | ebd09dbe9e4059a6e67a01a0383bed874cdf4d21 (diff) | |
download | rspamd-fbcc7af8a6bfb2c82d17180358bfdadf0228cddd.tar.gz rspamd-fbcc7af8a6bfb2c82d17180358bfdadf0228cddd.zip |
* Add simple test for rrd.
Several fixes to RRD API.
TODO: fix test building
TODO: improve update of rrd files
TODO: rework shared libraries again
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 10 | ||||
-rw-r--r-- | test/rspamd_rrd_test.c | 76 | ||||
-rw-r--r-- | test/rspamd_statfile_test.c | 2 | ||||
-rw-r--r-- | test/rspamd_test_suite.c | 1 | ||||
-rw-r--r-- | test/tests.h | 21 |
5 files changed, 97 insertions, 13 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 322229cad..acf80497a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,17 +7,21 @@ SET(TESTSRC rspamd_expression_test.c rspamd_url_test.c rspamd_dns_test.c rspamd_async_test.c - rspamd_dkim_test.c) + rspamd_dkim_test.c + rspamd_rrd_test.c) ADD_EXECUTABLE(rspamd-test EXCLUDE_FROM_ALL ${TESTSRC}) SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(rspamd-test PROPERTIES COMPILE_FLAGS "-DRSPAMD_TEST") -TARGET_LINK_LIBRARIES(rspamd-test rspamd_lua) -TARGET_LINK_LIBRARIES(rspamd-test rspamdserver) + TARGET_LINK_LIBRARIES(rspamd-test event) TARGET_LINK_LIBRARIES(rspamd-test m) TARGET_LINK_LIBRARIES(rspamd-test ${GLIB2_LIBRARIES}) 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 hiredis) IF(HAVE_LIBEVENT2) TARGET_LINK_LIBRARIES(rspamd-test event_pthreads) ENDIF(HAVE_LIBEVENT2) diff --git a/test/rspamd_rrd_test.c b/test/rspamd_rrd_test.c new file mode 100644 index 000000000..04d523e6c --- /dev/null +++ b/test/rspamd_rrd_test.c @@ -0,0 +1,76 @@ +/* Copyright (c) 2012, 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 "tests.h" +#include "rrd.h" +#include "main.h" + +void +rspamd_rrd_test_func () +{ + gchar tmpfile[PATH_MAX]; + struct rrd_rra_def rra; + struct rrd_ds_def ds; + GArray ar; + struct rspamd_rrd_file *rrd; + gint fd, i; + gdouble t; + + rspamd_snprintf (tmpfile, sizeof (tmpfile), "/tmp/rspamd_rrd.rrd"); + + /* Create sample rrd */ + g_assert ((rrd = rspamd_rrd_create (tmpfile, 1, 1, 5, NULL)) != NULL); + /* Add RRA */ + rspamd_strlcpy (rra.cf_nam, rrd_cf_to_string (RRD_CF_AVERAGE), sizeof (rra.cf_nam)); + rra.pdp_cnt = 1; + rra.row_cnt = 100; + ar.data = &rra; + ar.len = sizeof (rra); + g_assert (rspamd_rrd_add_rra (rrd, &ar, NULL)); + /* Add DS */ + rspamd_strlcpy (ds.dst, rrd_dst_to_string (RRD_DST_ABSOLUTE), sizeof (ds.dst)); + rspamd_strlcpy (ds.ds_nam, "test", sizeof (ds.ds_nam)); + ar.data = &ds; + ar.len = sizeof (ds); + g_assert (rspamd_rrd_add_ds (rrd, &ar, NULL)); + /* Finalize */ + g_assert (rspamd_rrd_finalize (rrd, NULL)); + /* Close */ + rspamd_rrd_close (rrd); + + /* Reopen */ + g_assert ((rrd = rspamd_rrd_open (tmpfile, NULL)) != NULL); + + /* Add some points */ + for (i = 0; i < 200; i ++) { + t = i; + ar.data = &t; + ar.len = sizeof (gdouble); + g_assert (rspamd_rrd_add_record (rrd, 0, &ar, NULL)); + } + + /* Finish */ + rspamd_rrd_close (rrd); + /* unlink (tmpfile); */ +} diff --git a/test/rspamd_statfile_test.c b/test/rspamd_statfile_test.c index 7a36a848d..f8e8a5294 100644 --- a/test/rspamd_statfile_test.c +++ b/test/rspamd_statfile_test.c @@ -17,7 +17,7 @@ rspamd_statfile_test_func () p = memory_pool_new (memory_pool_get_size ()); umask (S_IWGRP | S_IWOTH); - pool = statfile_pool_new (p, 10 * 1024 * 1024); + pool = statfile_pool_new (p, 10 * 1024 * 1024, TRUE); now = time (NULL); /* Fill random array */ diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 283cae57d..b1f273cba 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -70,6 +70,7 @@ main (int argc, char **argv) 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); + g_test_add_func ("/rspamd/rrd", rspamd_rrd_test_func); g_test_run (); diff --git a/test/tests.h b/test/tests.h index 135bfd163..8fb22b656 100644 --- a/test/tests.h +++ b/test/tests.h @@ -6,30 +6,33 @@ */ /* URL parser test */ -void rspamd_url_test_func (); +void rspamd_url_test_func (void); /* Memcached library test */ -void rspamd_memcached_test_func (); +void rspamd_memcached_test_func (void); /* Memory pools */ -void rspamd_mem_pool_test_func (); +void rspamd_mem_pool_test_func (void); /* Expressions */ -void rspamd_expression_test_func (); +void rspamd_expression_test_func (void); /* Fuzzy hashes */ -void rspamd_fuzzy_test_func (); +void rspamd_fuzzy_test_func (void); /* Stat file */ -void rspamd_statfile_test_func (); +void rspamd_statfile_test_func (void); /* DNS resolving */ -void rspamd_dns_test_func (); +void rspamd_dns_test_func (void); /* Async IO */ -void rspamd_async_test_func (); +void rspamd_async_test_func (void); /* DKIM test */ -void rspamd_dkim_test_func (); +void rspamd_dkim_test_func (void); + +/* RRD test */ +void rspamd_rrd_test_func (void); #endif |