Modifications in preparation to MAX IV experiment

This commit is contained in:
2024-01-27 21:23:56 +01:00
parent 2446643489
commit f5f86d9ab6
250 changed files with 9363 additions and 3022 deletions
+45 -13
View File
@@ -2,7 +2,7 @@
#include <catch2/catch.hpp>
#include "../writer/ZMQImagePuller.h"
#include "../frame_serialize/ZMQStream2Pusher.h"
#include "../frame_serialize/ZMQStream2PusherGroup.h"
void test_puller(ZMQImagePuller *puller,
const DiffractionExperiment& x,
@@ -71,16 +71,17 @@ TEST_CASE("ZMQImageCommTest_1Writer","[ZeroMQ]") {
std::vector<uint16_t> image1(x.GetPixelsNum()*nframes);
for (auto &i: image1) i = dist(g1);
std::string zmq_addr = "inproc://#1";
std::string zmq_addr = "ipc://*";
// Puller needs to be declared first, but both objects need to exist till communication finished
// TODO: ImageSender should not allow if there are still completions to be done
ZMQImagePuller puller(context);
ZMQStream2Pusher pusher(context, {zmq_addr});
ZMQStream2PusherGroup pusher(context, {zmq_addr});
std::vector<size_t> diff_size(1), diff_content(1), diff_split(1), nimages(1);
puller.Connect(zmq_addr);
auto pusher_addr = pusher.GetAddress();
puller.Connect(pusher_addr[0]);
std::thread sender_thread = std::thread([&] {
StartMessage message {
@@ -142,16 +143,18 @@ TEST_CASE("ZMQImageCommTest_2Writers","[ZeroMQ]") {
int64_t npullers = 2;
for (int i = 0; i < npullers; i++)
zmq_addr.push_back("inproc://#" + std::to_string(i));
zmq_addr.push_back("ipc://*");
ZMQStream2Pusher pusher(context, zmq_addr);
ZMQStream2PusherGroup pusher(context, zmq_addr);
// Puller needs to be declared first, but both objects need to exist till communication finished
// TODO: ImageSender should not allow if there are still completions to be done
std::vector<std::unique_ptr<ZMQImagePuller> > puller;
auto pusher_addr = pusher.GetAddress();
REQUIRE(pusher_addr.size() == 2);
for (int i = 0; i < npullers; i++) {
puller.push_back(std::make_unique<ZMQImagePuller>(context));
puller[i]->Connect(zmq_addr[i]);
puller[i]->Connect(pusher_addr[i]);
}
std::vector<size_t> diff_size(npullers), diff_content(npullers), diff_split(npullers), nimages(npullers);
@@ -226,21 +229,20 @@ TEST_CASE("ZMQImageCommTest_4Writers","[ZeroMQ]") {
int64_t npullers = 4;
for (int i = 0; i < npullers; i++)
zmq_addr.push_back("inproc://#" + std::to_string(i));
ZMQStream2Pusher pusher(context, zmq_addr);
zmq_addr.push_back("ipc://*");
ZMQStream2PusherGroup pusher(context, zmq_addr);
auto pusher_addr = pusher.GetAddress();
REQUIRE(pusher_addr.size() == npullers);
// Puller needs to be declared first, but both objects need to exist till communication finished
// TODO: ImageSender should not allow if there are still completions to be done
std::vector<std::unique_ptr<ZMQImagePuller> > puller;
for (int i = 0; i < npullers; i++) {
puller.push_back(std::make_unique<ZMQImagePuller>(context));
puller[i]->Connect(zmq_addr[i]);
puller[i]->Connect(pusher_addr[i]);
}
std::vector<size_t> diff_size(npullers), diff_content(npullers), diff_split(npullers), nimages(npullers);
std::thread sender_thread = std::thread([&] {
@@ -310,4 +312,34 @@ TEST_CASE("ZMQImagePuller_abort","[ZeroMQ]") {
puller.Abort();
puller_thread.join();
REQUIRE(nimages[0] == 0);
}
TEST_CASE("ZMQImageCommTest_NoWriter","[ZeroMQ]") {
ZMQStream2PusherGroup pusher({"ipc://*"});
StartMessage msg;
msg.data_file_count = 1;
REQUIRE_THROWS(pusher.StartDataCollection(msg));
std::vector<uint8_t> test(512*1024, 11);
CompressedImage image {
.data = test.data(),
.size = 1024 * 512,
.xpixel = 1024,
.ypixel = 512,
.pixel_depth_bytes = 1,
.pixel_is_signed = false,
.pixel_is_float = false,
.algorithm = CompressionAlgorithm::NO_COMPRESSION,
.channel = "default"
};
DataMessage data_message;
data_message.number = 1;
data_message.image = image;
REQUIRE(!pusher.SendImage(data_message));
EndMessage end_message;
REQUIRE(!pusher.EndDataCollection(end_message));
}