commit 300acf0: [Test] Fix functional tests

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jun 22 12:14:47 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-21 12:18:19 +0100
URL: https://github.com/rspamd/rspamd/commit/300acf008d6d194f0107e293a20cfb88611546e9

[Test] Fix functional tests

---
 contrib/librdns/punycode.c                   | 16 +++---
 src/libcryptobox/curve25519/base_constants.h |  2 +-
 src/libcryptobox/curve25519/ref.c            | 16 +++---
 test/CMakeLists.txt                          |  1 -
 test/rspamd_async_test.c                     | 80 ----------------------------
 test/rspamd_dkim_test.c                      |  2 +-
 test/rspamd_dns_test.c                       | 12 ++---
 test/rspamd_test_suite.c                     |  7 +--
 test/rspamd_upstream_test.c                  | 25 +++++----
 test/tests.h                                 |  3 --
 10 files changed, 38 insertions(+), 126 deletions(-)

diff --git a/contrib/librdns/punycode.c b/contrib/librdns/punycode.c
index 909d0d940..61091b2e4 100644
--- a/contrib/librdns/punycode.c
+++ b/contrib/librdns/punycode.c
@@ -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;
diff --git a/src/libcryptobox/curve25519/base_constants.h b/src/libcryptobox/curve25519/base_constants.h
index 0eaef129b..48adfcf03 100644
--- a/src/libcryptobox/curve25519/base_constants.h
+++ b/src/libcryptobox/curve25519/base_constants.h
@@ -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 },
diff --git a/src/libcryptobox/curve25519/ref.c b/src/libcryptobox/curve25519/ref.c
index 3ccc7ada1..eb89b2cdc 100644
--- a/src/libcryptobox/curve25519/ref.c
+++ b/src/libcryptobox/curve25519/ref.c
@@ -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);
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 10f0a19da..1064a9c76 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -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
index 122cca9c5..000000000
--- a/test/rspamd_async_test.c
+++ /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);
-}
diff --git a/test/rspamd_dkim_test.c b/test/rspamd_dkim_test.c
index 1cb6bf90e..b614e06f7 100644
--- a/test/rspamd_dkim_test.c
+++ b/test/rspamd_dkim_test.c
@@ -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)
diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c
index 8f0baca84..6b12746ae 100644
--- a/test/rspamd_dns_test.c
+++ b/test/rspamd_dns_test.c
@@ -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);
 }
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index 728acd8a2..3cbb81460 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -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 ()) {
diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c
index 28015aaf9..7813f9c22 100644
--- a/test/rspamd_upstream_test.c
+++ b/test/rspamd_upstream_test.c
@@ -16,11 +16,14 @@
 #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);
diff --git a/test/tests.h b/test/tests.h
index 9a70d8d5d..56562ae8c 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -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);
 


More information about the Commits mailing list