You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd_test_suite.c 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "config.h"
  2. #include "rspamd.h"
  3. #include "libstat/stat_api.h"
  4. #include "lua/lua_common.h"
  5. #include "tests.h"
  6. struct rspamd_main *rspamd_main = NULL;
  7. struct event_base *base = NULL;
  8. worker_t *workers[] = { NULL };
  9. gchar *lua_test = NULL;
  10. gchar *lua_test_case = NULL;
  11. gboolean verbose = FALSE;
  12. static GOptionEntry entries[] =
  13. {
  14. { "test", 't', 0, G_OPTION_ARG_STRING, &lua_test,
  15. "Lua test to run (i.e. selectors.lua)", NULL },
  16. { "test-case", 'c', 0, G_OPTION_ARG_STRING, &lua_test_case,
  17. "Lua test to run, lua pattern i.e. \"case .* rcpts\"", NULL },
  18. { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
  19. };
  20. int
  21. main (int argc, char **argv)
  22. {
  23. struct rspamd_config *cfg;
  24. GOptionContext *context;
  25. GError *error = NULL;
  26. rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
  27. memset (rspamd_main, 0, sizeof (struct rspamd_main));
  28. rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
  29. cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
  30. cfg->libs_ctx = rspamd_init_libs ();
  31. rspamd_main->cfg = cfg;
  32. cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
  33. cfg->log_type = RSPAMD_LOG_CONSOLE;
  34. cfg->log_level = G_LOG_LEVEL_MESSAGE;
  35. rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"),
  36. &rspamd_main->logger, rspamd_main->server_pool);
  37. (void)rspamd_log_open (rspamd_main->logger);
  38. g_test_init (&argc, &argv, NULL);
  39. context = g_option_context_new ("- run rspamd test");
  40. g_option_context_add_main_entries (context, entries, NULL);
  41. if (!g_option_context_parse (context, &argc, &argv, &error)) {
  42. fprintf (stderr, "option parsing failed: %s\n", error->message);
  43. g_option_context_free (context);
  44. exit (1);
  45. }
  46. rspamd_lua_set_path ((lua_State *)cfg->lua_state, NULL, NULL);
  47. base = event_init ();
  48. rspamd_stat_init (cfg, base);
  49. rspamd_url_init (NULL);
  50. if (g_test_verbose ()) {
  51. cfg->log_level = G_LOG_LEVEL_DEBUG;
  52. rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"),
  53. &rspamd_main->logger, rspamd_main->server_pool);
  54. (void)rspamd_log_reopen (rspamd_main->logger);
  55. }
  56. g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
  57. g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func);
  58. g_test_add_func ("/rspamd/radix", rspamd_radix_test_func);
  59. g_test_add_func ("/rspamd/dns", rspamd_dns_test_func);
  60. g_test_add_func ("/rspamd/dkim", rspamd_dkim_test_func);
  61. g_test_add_func ("/rspamd/rrd", rspamd_rrd_test_func);
  62. g_test_add_func ("/rspamd/upstream", rspamd_upstream_test_func);
  63. g_test_add_func ("/rspamd/shingles", rspamd_shingles_test_func);
  64. g_test_add_func ("/rspamd/http", rspamd_http_test_func);
  65. g_test_add_func ("/rspamd/lua", rspamd_lua_test_func);
  66. g_test_add_func ("/rspamd/cryptobox", rspamd_cryptobox_test_func);
  67. g_test_add_func ("/rspamd/heap", rspamd_heap_test_func);
  68. g_test_add_func ("/rspamd/lua_pcall", rspamd_lua_lua_pcall_vs_resume_test_func);
  69. #if 0
  70. g_test_add_func ("/rspamd/url", rspamd_url_test_func);
  71. g_test_add_func ("/rspamd/statfile", rspamd_statfile_test_func);
  72. g_test_add_func ("/rspamd/aio", rspamd_async_test_func);
  73. #endif
  74. g_test_run ();
  75. rspamd_regexp_library_finalize ();
  76. return 0;
  77. }