]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Fix functional tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 21 Jun 2019 11:18:19 +0000 (12:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jun 2019 09:57:29 +0000 (10:57 +0100)
contrib/librdns/punycode.c
src/libcryptobox/curve25519/base_constants.h
src/libcryptobox/curve25519/ref.c
test/CMakeLists.txt
test/rspamd_async_test.c [deleted file]
test/rspamd_dkim_test.c
test/rspamd_dns_test.c
test/rspamd_test_suite.c
test/rspamd_upstream_test.c
test/tests.h

index 909d0d940c6eebb43727f0a6dda29736102c9907..61091b2e46e7cec964fa60f8a33e8b8c15971357 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 #include "dns_private.h"
-static const unsigned base = 36;
+static const unsigned event_loop = 36;
 static const unsigned t_min = 1;
 static const unsigned t_max = 26;
 static const unsigned skew = 38;
@@ -61,11 +61,11 @@ adapt (unsigned int delta, unsigned int numpoints, int first)
        }
        delta += delta / numpoints;
        k = 0;
-       while (delta > ((base - t_min) * t_max) / 2) {
-               delta /= base - t_min;
-               k += base;
+       while (delta > ((event_loop - t_min) * t_max) / 2) {
+               delta /= event_loop - t_min;
+               k += event_loop;
        }
-       return k + (((base - t_min + 1) * delta) / (delta + skew));
+       return k + (((event_loop - t_min + 1) * delta) / (delta + skew));
 }
 
 /**
@@ -139,7 +139,7 @@ rdns_punycode_label_toascii (const uint32_t *in, size_t in_len, char *out,
                        else if (in[i] == n) {
                                unsigned int q = delta;
                                unsigned int k;
-                               for (k = base;; k += base) {
+                               for (k = event_loop;; k += event_loop) {
                                        unsigned int t;
                                        if (k <= bias) {
                                                t = t_min;
@@ -156,8 +156,8 @@ rdns_punycode_label_toascii (const uint32_t *in, size_t in_len, char *out,
                                        if (o >= *out_len) {
                                                return -1;
                                        }
-                                       out[o++] = digit (t + ((q - t) % (base - t)));
-                                       q = (q - t) / (base - t);
+                                       out[o++] = digit (t + ((q - t) % (event_loop - t)));
+                                       q = (q - t) / (event_loop - t);
                                }
                                if (o >= *out_len) {
                                        return -1;
index 0eaef129b9721fd901ca9c0bfbe26c89371b9628..48adfcf0361c61456ccc6dc04363e5c9a2935b37 100644 (file)
@@ -1,4 +1,4 @@
-static const ge_precomp base[32][8] = {
+static const ge_precomp event_loop[32][8] = {
 {
  {
   { 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 },
index 3ccc7ada174a2b265d429a36b3ee174a19ed4f5b..eb89b2cdcd5bef3a1ac41ad7925879ddd6b93f71 100644 (file)
@@ -1601,14 +1601,14 @@ static void ge_select(ge_precomp *t, int pos, signed char b)
        unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
 
        ge_precomp_0 (t);
-       cmov (t, &base[pos][0], equal (babs, 1));
-       cmov (t, &base[pos][1], equal (babs, 2));
-       cmov (t, &base[pos][2], equal (babs, 3));
-       cmov (t, &base[pos][3], equal (babs, 4));
-       cmov (t, &base[pos][4], equal (babs, 5));
-       cmov (t, &base[pos][5], equal (babs, 6));
-       cmov (t, &base[pos][6], equal (babs, 7));
-       cmov (t, &base[pos][7], equal (babs, 8));
+       cmov (t, &event_loop[pos][0], equal (babs, 1));
+       cmov (t, &event_loop[pos][1], equal (babs, 2));
+       cmov (t, &event_loop[pos][2], equal (babs, 3));
+       cmov (t, &event_loop[pos][3], equal (babs, 4));
+       cmov (t, &event_loop[pos][4], equal (babs, 5));
+       cmov (t, &event_loop[pos][5], equal (babs, 6));
+       cmov (t, &event_loop[pos][6], equal (babs, 7));
+       cmov (t, &event_loop[pos][7], equal (babs, 8));
        fe_copy (minust.yplusx, t->yminusx);
        fe_copy (minust.yminusx, t->yplusx);
        fe_neg (minust.xy2d, t->xy2d);
index 10f0a19da866fefe99ee3b96c7a833aa7ef4bbff..1064a9c766e81458076c759210a3476c34463d99 100644 (file)
@@ -2,7 +2,6 @@ SET(TESTSRC             rspamd_mem_pool_test.c
                                rspamd_statfile_test.c
                                rspamd_url_test.c
                                rspamd_dns_test.c
-                               rspamd_async_test.c
                                rspamd_dkim_test.c
                                rspamd_rrd_test.c
                                rspamd_radix_test.c
diff --git a/test/rspamd_async_test.c b/test/rspamd_async_test.c
deleted file mode 100644 (file)
index 122cca9..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "config.h"
-#include "rspamd.h"
-#include "aio_event.h"
-#include "unix-std.h"
-
-extern struct ev_loop *base;
-
-static void
-aio_read_cb (gint fd, gint res, gsize len, gpointer data, gpointer ud)
-{
-       guchar *p = data;
-       guint i;
-
-       g_assert (res > 0);
-
-       g_assert (len == BUFSIZ);
-       for (i = 0; i < len; i ++) {
-               g_assert (p[i] == 0xef);
-       }
-
-       event_base_loopbreak (base);
-}
-
-static void
-aio_write_cb (gint fd, gint res, gsize len, gpointer data, gpointer ud)
-{
-       struct aio_context *aio_ctx = ud;
-       gchar *testbuf;
-
-       g_assert (res > 0);
-
-       g_assert (posix_memalign ((void **)&testbuf, 512, BUFSIZ) == 0);
-
-       g_assert (rspamd_aio_read (fd, testbuf, BUFSIZ, 0, aio_ctx, aio_read_cb, aio_ctx) != -1);
-}
-
-void
-rspamd_async_test_func ()
-{
-       struct aio_context *aio_ctx;
-       gchar *tmpfile;
-       static gchar testbuf[BUFSIZ];
-       gint fd, afd, ret;
-
-       aio_ctx = rspamd_aio_init (base);
-
-       g_assert (aio_ctx != NULL);
-
-       fd = g_file_open_tmp ("raXXXXXX", &tmpfile, NULL);
-       g_assert (fd != -1);
-
-       afd = rspamd_aio_open (aio_ctx, tmpfile, O_RDWR);
-       g_assert (fd != -1);
-
-       /* Write some data */
-       memset (testbuf, 0xef, sizeof (testbuf));
-       ret = rspamd_aio_write (afd, testbuf, sizeof (testbuf), 0, aio_ctx, aio_write_cb, aio_ctx);
-       g_assert (ret != -1);
-
-       event_base_loop (base, 0);
-
-       close (afd);
-       close (fd);
-       unlink (tmpfile);
-}
index 1cb6bf90e4663de7a054f094ab727ee2c43b01af..b614e06f7e2b46122cd74c4e3ba891033a3335c1 100644 (file)
@@ -26,7 +26,7 @@ static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; "
                "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy"
                "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;";
 
-extern struct ev_loop *base;
+extern struct ev_loop *event_loop;
 
 static void
 test_key_handler (rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_context_t *ctx, gpointer ud, GError *err)
index 8f0baca846b25861a6ceb9c9a4c8a0c3bec4a8fd..6b12746aed598659b23e755e2fcf63e26ded0b4b 100644 (file)
@@ -8,17 +8,13 @@
 #include "cfg_file.h"
 
 static guint requests = 0;
-extern struct ev_loop *base;
+extern struct ev_loop *event_loop;
 struct rspamd_dns_resolver *resolver;
 
 gboolean
 session_fin (gpointer unused)
 {
-       struct timeval tv;
-
-       tv.tv_sec = 0;
-       tv.tv_usec = 0;
-       event_loopexit (&tv);
+       ev_break (event_loop, EVBREAK_ALL);
 
        return TRUE;
 }
@@ -82,7 +78,7 @@ rspamd_dns_test_func ()
 
        s = rspamd_session_create (pool, session_fin, NULL, NULL, NULL);
 
-       resolver = rspamd_dns_resolver_init (NULL, base, cfg);
+       resolver = rspamd_dns_resolver_init (NULL, event_loop, cfg);
 
        requests ++;
        g_assert (rspamd_dns_resolver_request (resolver, s, pool, test_dns_cb, NULL, RDNS_REQUEST_A, "google.com"));
@@ -104,5 +100,5 @@ rspamd_dns_test_func ()
 
        g_assert (resolver != NULL);
 
-       event_loop (0);
+       ev_run (event_loop, 0);
 }
index 728acd8a22122989b6c845ac3cef9aee531ae50c..3cbb81460459f70011b2faf023c2aafbf73c0907 100644 (file)
@@ -3,9 +3,10 @@
 #include "libstat/stat_api.h"
 #include "lua/lua_common.h"
 #include "tests.h"
+#include "contrib/libev/ev.h"
 
 struct rspamd_main             *rspamd_main = NULL;
-struct ev_loop              *base = NULL;
+struct ev_loop              *event_loop = NULL;
 worker_t *workers[] = { NULL };
 
 gchar *lua_test = NULL;
@@ -54,8 +55,8 @@ main (int argc, char **argv)
        }
 
        rspamd_lua_set_path ((lua_State *)cfg->lua_state, NULL, NULL);
-       base = event_init ();
-       rspamd_stat_init (cfg, base);
+       event_loop = ev_default_loop (EVFLAG_SIGNALFD|EVBACKEND_ALL);
+       rspamd_stat_init (cfg, event_loop);
        rspamd_url_init (NULL);
 
        if (g_test_verbose ()) {
index 28015aaf99c2350983da58f9b257fa7b2d59c872..7813f9c228f908abde0b916bfc2225ed2e5809d4 100644 (file)
 #include "config.h"
 #include "rspamd.h"
 #include "ottery.h"
+#include "contrib/libev/ev.h"
+
 #include <math.h>
 
 const char *test_upstream_list = "microsoft.com:443:1,google.com:80:2,kernel.org:443:3";
 const char *new_upstream_list = "freebsd.org:80";
 char test_key[32];
+extern struct ev_loop *event_loop;
 
 static void
 rspamd_upstream_test_method (struct upstream_list *ls,
@@ -42,9 +45,9 @@ rspamd_upstream_test_method (struct upstream_list *ls,
 }
 
 static void
-rspamd_upstream_timeout_handler (int fd, short what, void *arg)
+rspamd_upstream_timeout_handler (EV_P_ ev_timer *w, int revents)
 {
-       struct rspamd_dns_resolver *resolver = (struct rspamd_dns_resolver *)arg;
+       struct rspamd_dns_resolver *resolver = (struct rspamd_dns_resolver *)w->data;
 
        rdns_resolver_release (resolver->r);
 }
@@ -54,14 +57,12 @@ rspamd_upstream_test_func (void)
 {
        struct upstream_list *ls, *nls;
        struct upstream *up, *upn;
-       struct ev_loop *ev_base = event_init ();
        struct rspamd_dns_resolver *resolver;
        struct rspamd_config *cfg;
        gint i, success = 0;
        const gint assumptions = 100500;
        gdouble p;
-       struct event ev;
-       struct timeval tv;
+       static ev_timer ev;
        rspamd_inet_addr_t *addr, *next_addr, *paddr;
 
        cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_SKIP_LUA);
@@ -71,8 +72,8 @@ rspamd_upstream_test_func (void)
        cfg->upstream_revive_time = 0.5;
        cfg->upstream_error_time = 2;
 
-       resolver = rspamd_dns_resolver_init (NULL, ev_base, cfg);
-       rspamd_upstreams_library_config (cfg, cfg->ups_ctx, ev_base, resolver->r);
+       resolver = rspamd_dns_resolver_init (NULL, event_loop, cfg);
+       rspamd_upstreams_library_config (cfg, cfg->ups_ctx, event_loop, resolver->r);
 
        /*
         * Test v4/v6 priorities
@@ -161,8 +162,8 @@ rspamd_upstream_test_func (void)
 
 
        /* Upstream fail test */
-       evtimer_set (&ev, rspamd_upstream_timeout_handler, resolver);
-       event_base_set (ev_base, &ev);
+       ev.data = resolver;
+       ev_timer_init (&ev, rspamd_upstream_timeout_handler, 2.0, 0.0);
 
        up = rspamd_upstream_get (ls, RSPAMD_UPSTREAM_MASTER_SLAVE, NULL, 0);
        for (i = 0; i < 100; i ++) {
@@ -170,11 +171,9 @@ rspamd_upstream_test_func (void)
        }
        g_assert (rspamd_upstreams_alive (ls) == 2);
 
-       tv.tv_sec = 2;
-       tv.tv_usec = 0;
-       event_add (&ev, &tv);
+       ev_timer_start (event_loop, &ev);
 
-       event_base_loop (ev_base, 0);
+       ev_run (event_loop, 0);
        g_assert (rspamd_upstreams_alive (ls) == 3);
 
        rspamd_upstreams_destroy (ls);
index 9a70d8d5df9ce470c24f4ecc63db5f3a8b766b08..56562ae8cb99af618d6fcfbf0a68592854c14a38 100644 (file)
@@ -20,9 +20,6 @@ void rspamd_radix_test_func (void);
 /* DNS resolving */
 void rspamd_dns_test_func (void);
 
-/* Async IO */
-void rspamd_async_test_func (void);
-
 /* DKIM test */
 void rspamd_dkim_test_func (void);