2014-09-12 12:56:42 +02:00
|
|
|
#include "config.h"
|
2015-09-22 19:17:24 +02:00
|
|
|
#include "rspamd.h"
|
2015-07-14 15:45:46 +02:00
|
|
|
#include "libstat/stat_api.h"
|
2018-11-21 13:39:15 +01:00
|
|
|
#include "lua/lua_common.h"
|
2008-09-08 16:18:56 +02:00
|
|
|
#include "tests.h"
|
|
|
|
|
2011-05-10 17:15:03 +02:00
|
|
|
struct rspamd_main *rspamd_main = NULL;
|
2012-03-01 17:14:32 +01:00
|
|
|
struct event_base *base = NULL;
|
|
|
|
worker_t *workers[] = { NULL };
|
2010-07-08 18:07:07 +02:00
|
|
|
|
2018-09-19 16:42:38 +02:00
|
|
|
gchar *lua_test = NULL;
|
2018-09-20 12:26:36 +02:00
|
|
|
gchar *lua_test_case = NULL;
|
2018-09-19 16:42:38 +02:00
|
|
|
gboolean verbose = FALSE;
|
|
|
|
|
|
|
|
static GOptionEntry entries[] =
|
|
|
|
{
|
|
|
|
{ "test", 't', 0, G_OPTION_ARG_STRING, &lua_test,
|
|
|
|
"Lua test to run (i.e. selectors.lua)", NULL },
|
2018-09-20 12:26:36 +02:00
|
|
|
{ "test-case", 'c', 0, G_OPTION_ARG_STRING, &lua_test_case,
|
|
|
|
"Lua test to run, lua pattern i.e. \"case .* rcpts\"", NULL },
|
2018-09-19 16:42:38 +02:00
|
|
|
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2008-09-08 16:18:56 +02:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2018-08-20 11:27:12 +02:00
|
|
|
struct rspamd_config *cfg;
|
2018-09-19 16:42:38 +02:00
|
|
|
GOptionContext *context;
|
|
|
|
GError *error = NULL;
|
2008-09-09 16:48:49 +02:00
|
|
|
|
2015-02-28 01:11:56 +01:00
|
|
|
rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
|
|
|
|
memset (rspamd_main, 0, sizeof (struct rspamd_main));
|
2015-08-27 18:31:29 +02:00
|
|
|
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
|
2018-05-24 20:55:37 +02:00
|
|
|
cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
|
2018-11-21 13:39:15 +01:00
|
|
|
cfg->libs_ctx = rspamd_init_libs ();
|
2015-11-20 17:33:34 +01:00
|
|
|
rspamd_main->cfg = cfg;
|
2015-08-27 18:31:29 +02:00
|
|
|
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
|
2015-02-28 01:11:56 +01:00
|
|
|
cfg->log_type = RSPAMD_LOG_CONSOLE;
|
2018-03-30 10:34:34 +02:00
|
|
|
cfg->log_level = G_LOG_LEVEL_MESSAGE;
|
2015-02-27 18:12:41 +01:00
|
|
|
|
2016-12-14 14:42:26 +01:00
|
|
|
rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"),
|
|
|
|
&rspamd_main->logger, rspamd_main->server_pool);
|
2015-02-28 01:11:56 +01:00
|
|
|
(void)rspamd_log_open (rspamd_main->logger);
|
2008-09-08 16:18:56 +02:00
|
|
|
|
2015-02-28 01:11:56 +01:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
2012-03-05 15:58:50 +01:00
|
|
|
|
2018-09-19 16:42:38 +02:00
|
|
|
context = g_option_context_new ("- run rspamd test");
|
|
|
|
g_option_context_add_main_entries (context, entries, NULL);
|
|
|
|
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error)) {
|
|
|
|
fprintf (stderr, "option parsing failed: %s\n", error->message);
|
|
|
|
g_option_context_free (context);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:39:15 +01:00
|
|
|
rspamd_lua_set_path ((lua_State *)cfg->lua_state, NULL, NULL);
|
2012-03-01 17:14:32 +01:00
|
|
|
base = event_init ();
|
2016-01-06 16:25:07 +01:00
|
|
|
rspamd_stat_init (cfg, base);
|
2018-09-19 11:11:52 +02:00
|
|
|
rspamd_url_init (NULL);
|
2012-03-01 17:14:32 +01:00
|
|
|
|
2013-08-21 16:12:24 +02:00
|
|
|
if (g_test_verbose ()) {
|
2010-07-08 18:07:07 +02:00
|
|
|
cfg->log_level = G_LOG_LEVEL_DEBUG;
|
2016-12-14 14:42:26 +01:00
|
|
|
rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"),
|
|
|
|
&rspamd_main->logger, rspamd_main->server_pool);
|
2015-02-28 01:11:56 +01:00
|
|
|
(void)rspamd_log_reopen (rspamd_main->logger);
|
2010-07-08 18:07:07 +02:00
|
|
|
}
|
2015-02-28 01:11:56 +01:00
|
|
|
|
2011-05-10 17:15:03 +02:00
|
|
|
g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
|
2010-07-08 18:07:07 +02:00
|
|
|
|
2008-09-21 23:08:41 +02:00
|
|
|
g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func);
|
2014-09-12 13:18:55 +02:00
|
|
|
g_test_add_func ("/rspamd/radix", rspamd_radix_test_func);
|
2010-07-08 18:07:07 +02:00
|
|
|
g_test_add_func ("/rspamd/dns", rspamd_dns_test_func);
|
2012-05-29 01:07:23 +02:00
|
|
|
g_test_add_func ("/rspamd/dkim", rspamd_dkim_test_func);
|
2012-12-15 01:17:10 +01:00
|
|
|
g_test_add_func ("/rspamd/rrd", rspamd_rrd_test_func);
|
2014-11-02 19:38:43 +01:00
|
|
|
g_test_add_func ("/rspamd/upstream", rspamd_upstream_test_func);
|
2014-12-17 18:27:57 +01:00
|
|
|
g_test_add_func ("/rspamd/shingles", rspamd_shingles_test_func);
|
2015-02-04 18:05:53 +01:00
|
|
|
g_test_add_func ("/rspamd/http", rspamd_http_test_func);
|
2015-02-28 01:11:56 +01:00
|
|
|
g_test_add_func ("/rspamd/lua", rspamd_lua_test_func);
|
2015-05-07 13:25:11 +02:00
|
|
|
g_test_add_func ("/rspamd/cryptobox", rspamd_cryptobox_test_func);
|
2016-04-08 22:30:14 +02:00
|
|
|
g_test_add_func ("/rspamd/heap", rspamd_heap_test_func);
|
2018-08-20 11:27:12 +02:00
|
|
|
g_test_add_func ("/rspamd/lua_pcall", rspamd_lua_lua_pcall_vs_resume_test_func);
|
2008-09-08 16:18:56 +02:00
|
|
|
|
2016-04-28 10:18:00 +02:00
|
|
|
#if 0
|
|
|
|
g_test_add_func ("/rspamd/url", rspamd_url_test_func);
|
|
|
|
g_test_add_func ("/rspamd/statfile", rspamd_statfile_test_func);
|
|
|
|
g_test_add_func ("/rspamd/aio", rspamd_async_test_func);
|
|
|
|
#endif
|
2008-09-08 16:18:56 +02:00
|
|
|
g_test_run ();
|
2015-03-05 19:58:00 +01:00
|
|
|
rspamd_regexp_library_finalize ();
|
2014-09-18 15:16:46 +02:00
|
|
|
|
2009-09-14 17:11:19 +02:00
|
|
|
return 0;
|
2008-09-08 16:18:56 +02:00
|
|
|
}
|