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 06/10] fakesys: introduce fake system library
Date: Tue,  1 Dec 2020 00:56:15 +0100	[thread overview]
Message-ID: <1ce64b4dec76df9f69b5e75be529d240cff1b0e7.1606780408.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1606780408.git.v.shpilevoy@tarantool.org>

Fakesys is going to be a collection of fake implementations of
deep system things such as libev and libc.

The fake subsystems will provide API just like their original
counterparts (except for function names), but with full control of
their behaviour in user-space for the sake of unit testing.

This commit introduces first part of fakesys - a subset of libc
network API: sendto(), recvfrom(), bind(), close(), getifaddrs().

Main features of fakenet are:

- Integration with event loop via fakenet_loop_update(). Although
  this could be also considered an issue if it will be ever
  necessary to implement fake epoll, or sockets not bound to any
  event loop;

- Filters to decide which packets to drop depending on their src,
  dst, and content;

- Socket block to suspend packets delivery until the socket is
  unblocked.

Fakenet implements connection-less API, for UDP sockets. This is
exactly what is needed in SWIM.

Raft fake transport will need reliable sockets with broadcast API.
Reliability can be ensured by setting drop rate to 0 (which is
default). Broadcast functionality is already present - there is a
broadcast interface in fakenet_getifaddrs() result.

Part of #5303
---
 src/lib/CMakeLists.txt                   |  1 +
 src/lib/fakesys/CMakeLists.txt           |  7 +++++++
 {test/unit => src/lib/fakesys}/fakenet.c |  0
 {test/unit => src/lib/fakesys}/fakenet.h |  0
 test/unit/CMakeLists.txt                 | 12 ++++++------
 test/unit/swim_test_transport.c          |  2 +-
 test/unit/swim_test_utils.h              |  2 +-
 7 files changed, 16 insertions(+), 8 deletions(-)
 create mode 100644 src/lib/fakesys/CMakeLists.txt
 rename {test/unit => src/lib/fakesys}/fakenet.c (100%)
 rename {test/unit => src/lib/fakesys}/fakenet.h (100%)

diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index cabbe3d89..06f935f3e 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -15,6 +15,7 @@ add_subdirectory(swim)
 add_subdirectory(mpstream)
 add_subdirectory(vclock)
 add_subdirectory(raft)
+add_subdirectory(fakesys)
 if(ENABLE_BUNDLED_MSGPUCK)
     add_subdirectory(msgpuck EXCLUDE_FROM_ALL)
 endif()
diff --git a/src/lib/fakesys/CMakeLists.txt b/src/lib/fakesys/CMakeLists.txt
new file mode 100644
index 000000000..b4d6af817
--- /dev/null
+++ b/src/lib/fakesys/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(lib_sources
+    fakenet.c
+)
+
+set_source_files_compile_flags(${lib_sources})
+add_library(fakesys STATIC ${lib_sources})
+target_link_libraries(fakesys core)
diff --git a/test/unit/fakenet.c b/src/lib/fakesys/fakenet.c
similarity index 100%
rename from test/unit/fakenet.c
rename to src/lib/fakesys/fakenet.c
diff --git a/test/unit/fakenet.h b/src/lib/fakesys/fakenet.h
similarity index 100%
rename from test/unit/fakenet.h
rename to src/lib/fakesys/fakenet.h
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 00f5e89a3..e6a79e911 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -240,18 +240,18 @@ 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 fakenet.c swim_test_transport.c swim_test_ev.c
+add_executable(swim.test swim.c swim_test_transport.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 swim)
+target_link_libraries(swim.test unit fakesys swim)
 
-add_executable(swim_proto.test swim_proto.c fakenet.c swim_test_transport.c swim_test_ev.c
+add_executable(swim_proto.test swim_proto.c swim_test_transport.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 swim)
+target_link_libraries(swim_proto.test unit fakesys swim)
 
-add_executable(swim_errinj.test swim_errinj.c fakenet.c swim_test_transport.c
+add_executable(swim_errinj.test swim_errinj.c swim_test_transport.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 swim)
+target_link_libraries(swim_errinj.test unit fakesys swim)
 
 add_executable(merger.test merger.test.c)
 target_link_libraries(merger.test unit core box)
diff --git a/test/unit/swim_test_transport.c b/test/unit/swim_test_transport.c
index d2c39da5b..c27603709 100644
--- a/test/unit/swim_test_transport.c
+++ b/test/unit/swim_test_transport.c
@@ -30,7 +30,7 @@
  */
 #include <assert.h>
 #include <string.h>
-#include "fakenet.h"
+#include "fakesys/fakenet.h"
 #include "swim/swim_transport.h"
 
 ssize_t
diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h
index ba1749a7e..7a3a88c0b 100644
--- a/test/unit/swim_test_utils.h
+++ b/test/unit/swim_test_utils.h
@@ -38,7 +38,7 @@
 #include "swim/swim.h"
 #include "swim/swim_ev.h"
 #include "swim/swim_proto.h"
-#include "fakenet.h"
+#include "fakesys/fakenet.h"
 #include "swim_test_ev.h"
 
 struct swim_cluster;
-- 
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 ` Vladislav Shpilevoy [this message]
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 ` [Tarantool-patches] [PATCH 09/10] test: factor out swim from fakeev.h/.c files Vladislav Shpilevoy
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=1ce64b4dec76df9f69b5e75be529d240cff1b0e7.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 06/10] fakesys: introduce fake system library' \
    /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