Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 09/10] test: factor out swim from fakeev.h/.c files
Date: Tue,  1 Dec 2020 00:56:18 +0100	[thread overview]
Message-ID: <c3250cd522427b5d081928631115ece3b8a657b4.1606780408.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1606780408.git.v.shpilevoy@tarantool.org>

SWIM unit tests contain a special library for emulating the event
loop: swim_test_ev. It provides API similar to libev, but
implemented entirely in user-space, including clock functions.

The latter is the most important point, as the original libev
does not allow to define your own timing functions - internally it
relies on select/kqueue/epoll/poll/select/... with true clock.

Because of that it is impossible to perform long tests with the
original libev, which could last for minutes or even tens of
seconds if their count is big. swim_test_ev uses virtual time,
where hours can be played in milliseconds.

--

This commit extracts all swim code to swim_test_ev.c. Now this
file is nothing but an implementation of swim_ev.h on top of
fakeev API.

Fakeev, in turn, does not depend on SWIM anymore, and can be moved
to fakesys library.

Part of #5303
---
 test/unit/CMakeLists.txt |  6 ++--
 test/unit/fakeev.c       | 35 -----------------------
 test/unit/fakeev.h       | 13 +++++++++
 test/unit/swim_test_ev.c | 62 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 38 deletions(-)
 create mode 100644 test/unit/swim_test_ev.c

diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 436178280..7f64f9685 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -240,16 +240,16 @@ target_link_libraries(sio.test unit core)
 add_executable(crypto.test crypto.c core_test_utils.c)
 target_link_libraries(crypto.test crypto unit)
 
-add_executable(swim.test swim.c swim_test_transport.c fakeev.c
+add_executable(swim.test swim.c swim_test_transport.c fakeev.c swim_test_ev.c
                swim_test_utils.c ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim.test unit fakesys swim)
 
-add_executable(swim_proto.test swim_proto.c swim_test_transport.c fakeev.c
+add_executable(swim_proto.test swim_proto.c swim_test_transport.c fakeev.c swim_test_ev.c
                swim_test_utils.c ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim_proto.test unit fakesys swim)
 
 add_executable(swim_errinj.test swim_errinj.c swim_test_transport.c
-               fakeev.c swim_test_utils.c
+               fakeev.c swim_test_ev.c swim_test_utils.c
                ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim_errinj.test unit fakesys swim)
 
diff --git a/test/unit/fakeev.c b/test/unit/fakeev.c
index 20de35d7f..20fab916b 100644
--- a/test/unit/fakeev.c
+++ b/test/unit/fakeev.c
@@ -30,7 +30,6 @@
  */
 #include "fakeev.h"
 #include "trivia/util.h"
-#include "swim/swim_ev.h"
 #include "tarantool_ev.h"
 #define HEAP_FORWARD_DECLARATION
 #include "salad/heap.h"
@@ -269,10 +268,6 @@ fakeev_time(void)
 	return watch;
 }
 
-/**
- * Start of a timer generates a delayed event. If a timer is
- * already started - nothing happens.
- */
 void
 fakeev_timer_start(struct ev_loop *loop, struct ev_timer *base)
 {
@@ -353,33 +348,3 @@ fakeev_free(void)
 	mh_i64ptr_delete(events_hash);
 	ev_loop_destroy(test_loop);
 }
-
-double
-swim_time(void)
-{
-	return fakeev_time();
-}
-
-void
-swim_ev_timer_start(struct ev_loop *loop, struct ev_timer *watcher)
-{
-	return fakeev_timer_start(loop, watcher);
-}
-
-void
-swim_ev_timer_again(struct ev_loop *loop, struct ev_timer *watcher)
-{
-	return fakeev_timer_again(loop, watcher);
-}
-
-void
-swim_ev_timer_stop(struct ev_loop *loop, struct ev_timer *watcher)
-{
-	return fakeev_timer_stop(loop, watcher);
-}
-
-struct ev_loop *
-swim_loop(void)
-{
-	return fakeev_loop();
-}
diff --git a/test/unit/fakeev.h b/test/unit/fakeev.h
index b50fe5b3d..89954b2e1 100644
--- a/test/unit/fakeev.h
+++ b/test/unit/fakeev.h
@@ -30,6 +30,7 @@
  * SUCH DAMAGE.
  */
 struct ev_loop;
+struct ev_timer;
 
 /**
  * Fakeev implements a 'fake' event loop with bogus clock to speed up events
@@ -94,6 +95,18 @@ fakeev_time(void);
 struct ev_loop *
 fakeev_loop(void);
 
+/** Emulator of ev_timer_start(). */
+void
+fakeev_timer_start(struct ev_loop *loop, struct ev_timer *base);
+
+/** Emulator of ev_timer_again(). */
+void
+fakeev_timer_again(struct ev_loop *loop, struct ev_timer *base);
+
+/** Emulator of ev_timer_stop(). */
+void
+fakeev_timer_stop(struct ev_loop *loop, struct ev_timer *base);
+
 /**
  * Stop the event loop after @a delay fake seconds. It does not
  * affect other events, so the loop can stop earlier multiple
diff --git a/test/unit/swim_test_ev.c b/test/unit/swim_test_ev.c
new file mode 100644
index 000000000..876aa4eea
--- /dev/null
+++ b/test/unit/swim_test_ev.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010-2020, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. 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 BY <COPYRIGHT HOLDER> ``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
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS 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 "swim/swim_ev.h"
+#include "fakeev.h"
+
+double
+swim_time(void)
+{
+	return fakeev_time();
+}
+
+void
+swim_ev_timer_start(struct ev_loop *loop, struct ev_timer *watcher)
+{
+	return fakeev_timer_start(loop, watcher);
+}
+
+void
+swim_ev_timer_again(struct ev_loop *loop, struct ev_timer *watcher)
+{
+	return fakeev_timer_again(loop, watcher);
+}
+
+void
+swim_ev_timer_stop(struct ev_loop *loop, struct ev_timer *watcher)
+{
+	return fakeev_timer_stop(loop, watcher);
+}
+
+struct ev_loop *
+swim_loop(void)
+{
+	return fakeev_loop();
+}
-- 
2.24.3 (Apple Git-128)

  parent reply	other threads:[~2020-11-30 23:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 23:56 [Tarantool-patches] [PATCH 00/10] Raft module, part 3 - fake network and libev for Raft and SWIM Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 01/10] test: stop using swim_transport.addr as in-param Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 10/10] fakesys: move fakeev to fakesys library Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 02/10] test: factor out swim from libc emulation funcs Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 03/10] test: rename fake libc network methods to fakenet Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 04/10] test: move fake network code to fakenet.c/.h files Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 05/10] test: factor out swim from " Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 06/10] fakesys: introduce fake system library Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 07/10] test: rename fake libev methods to fakeev Vladislav Shpilevoy
2020-11-30 23:56 ` [Tarantool-patches] [PATCH 08/10] test: move fake libev code to fakeev.c/.h files Vladislav Shpilevoy
2020-11-30 23:56 ` Vladislav Shpilevoy [this message]
2020-12-01 13:42 ` [Tarantool-patches] [PATCH 00/10] Raft module, part 3 - fake network and libev for Raft and SWIM Serge Petrenko
2020-12-01 22:33 ` Vladislav Shpilevoy
2020-12-04  0:35 ` Alexander V. Tikhonov
2020-12-04 22:53   ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c3250cd522427b5d081928631115ece3b8a657b4.1606780408.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 09/10] test: factor out swim from fakeev.h/.c files' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox