From 1765b485efbfc5a72a65d8a4a543d66eeea312be Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 6 May 2020 10:12:17 +0200 Subject: [PATCH] Add test stub for LiveRecvModule --- core-buffer/test/main.cpp | 1 + core-buffer/test/test_LiveRecvModule.cpp | 47 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core-buffer/test/test_LiveRecvModule.cpp diff --git a/core-buffer/test/main.cpp b/core-buffer/test/main.cpp index 0f858d7..24f5952 100644 --- a/core-buffer/test/main.cpp +++ b/core-buffer/test/main.cpp @@ -6,6 +6,7 @@ #include "test_BufferH5Writer.cpp" #include "test_SFWriter.cpp" #include "test_FastQueue.cpp" +#include "test_LiveRecvModule.cpp" using namespace std; diff --git a/core-buffer/test/test_LiveRecvModule.cpp b/core-buffer/test/test_LiveRecvModule.cpp new file mode 100644 index 0000000..a7921bc --- /dev/null +++ b/core-buffer/test/test_LiveRecvModule.cpp @@ -0,0 +1,47 @@ +#include +#include "LiveRecvModule.hpp" +#include "gtest/gtest.h" +#include "buffer_config.hpp" + +using namespace std; +using namespace core_buffer; + + +TEST(LiveRecvModule, basic_interaction) { + auto ctx = zmq_ctx_new(); + string ipc_prefix = "ipc:///tmp/sf-live-"; + + size_t n_modules = 32; + size_t n_slots = 5; + FastQueue queue(MODULE_N_BYTES * n_modules, n_slots); + + void *sockets[n_modules]; + for (size_t i = 0; i < n_modules; i++) { + sockets[i] = zmq_socket(ctx, ZMQ_PUB); + + int linger = 0; + if (zmq_setsockopt(sockets[i], ZMQ_LINGER, &linger, + sizeof(linger)) != 0) { + throw runtime_error(strerror(errno)); + } + + stringstream ipc_addr; + ipc_addr << ipc_prefix << i; + const auto ipc = ipc_addr.str(); + + if (zmq_bind(sockets[i], ipc.c_str()) != 0) { + throw runtime_error(strerror(errno)); + } + } + + LiveRecvModule recv_module(queue, n_modules, ctx, ipc_prefix); + + // Nothing should be committed, queue, should be empty. + ASSERT_EQ(queue.read(), -1); + + + for (size_t i = 0; i < n_modules; i++) { + zmq_close(sockets[i]); + } + zmq_ctx_destroy(ctx); +} \ No newline at end of file