Improve test and add basic interaction

This commit is contained in:
2020-05-06 10:57:57 +02:00
parent 032fe93bce
commit f86f71fe95
+32 -2
View File
@@ -6,11 +6,22 @@
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<ModuleFrameBuffer> queue(MODULE_N_BYTES * n_modules, n_slots);
LiveRecvModule recv_module(queue, n_modules, ctx, ipc_prefix);
this_thread::sleep_for(chrono::milliseconds(100));
zmq_ctx_destroy(ctx);
}
TEST(LiveRecvModule, transfer_test) {
auto ctx = zmq_ctx_new();
string ipc_prefix = "ipc:///tmp/sf-live-";
size_t n_modules = 32;
size_t n_slots = 5;
FastQueue<ModuleFrameBuffer> queue(MODULE_N_BYTES * n_modules, n_slots);
@@ -39,10 +50,29 @@ TEST(LiveRecvModule, basic_interaction) {
// Nothing should be committed, queue, should be empty.
ASSERT_EQ(queue.read(), -1);
ModuleFrame metadata;
auto data = make_unique<char[]>(MODULE_N_BYTES);
for (size_t i = 0; i < n_modules; i++) {
metadata.pulse_id = 1;
metadata.frame_index = 2;
metadata.daq_rec = 3;
metadata.n_received_packets = 4;
metadata.module_id = i;
zmq_send(sockets[i], &metadata, sizeof(ModuleFrame), ZMQ_SNDMORE);
zmq_send(sockets[i], data.get(), MODULE_N_BYTES, 0);
}
this_thread::sleep_for(chrono::milliseconds(100));
auto slot_id = queue.read();
// We should have the first Detector frame in the buffer.
//ASSERT_NE(slot_id, -1);
this_thread::sleep_for(chrono::milliseconds(10000));
for (size_t i = 0; i < n_modules; i++) {
zmq_close(sockets[i]);
}
zmq_ctx_destroy(ctx);
cout << "We are finished" << endl;
}