From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5FA2F45C30C for ; Tue, 1 Dec 2020 02:56:29 +0300 (MSK) From: Vladislav Shpilevoy Date: Tue, 1 Dec 2020 00:56:15 +0100 Message-Id: <1ce64b4dec76df9f69b5e75be529d240cff1b0e7.1606780408.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 06/10] fakesys: introduce fake system library List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@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 #include -#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)