[Tarantool-patches] [PATCH 06/10] fakesys: introduce fake system library

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Dec 1 02:56:15 MSK 2020


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)



More information about the Tarantool-patches mailing list