test: run multi-process tests with one harness

- Add test::RunDevices(): starts the devices with the same session,
  transport, shm options and channel config, with a deadline per run
- Add the TestDevice base: Check() fails the device, Succeed() prints
  a marker with the transport name that the harness verifies
- Make the protocol, poller and transfer-timeout devices check their
  own results and drop the InitTask() sleeps
- Replace EXPECT_EXIT() and the copied launch code in the protocol,
  poller and transfer-timeout tests
- A device that uses the wrong transport now fails the test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-03 14:27:11 +00:00
committed by Dennis Klein
parent f50b1f0e39
commit be400e4752
20 changed files with 446 additions and 800 deletions

View File

@@ -49,6 +49,7 @@ add_testhelper(runTestDevice
helper/devices/TestRep.h helper/devices/TestRep.h
helper/devices/TestReq.h helper/devices/TestReq.h
helper/devices/TestSub.h helper/devices/TestSub.h
helper/devices/TestDevice.h
helper/devices/TestTransferTimeout.h helper/devices/TestTransferTimeout.h
helper/devices/TestWaitFor.h helper/devices/TestWaitFor.h
helper/devices/TestExceptions.h helper/devices/TestExceptions.h

139
test/helper/Devices.h Normal file
View File

@@ -0,0 +1,139 @@
/********************************************************************************
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_TEST_DEVICES_H
#define FAIR_MQ_TEST_DEVICES_H
#include "devices/TestDevice.h"
#include "../runner.h"
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <fairmq/tools/Unique.h>
#include <gtest/gtest.h>
#include <chrono>
#include <cstddef>
#include <sstream>
#include <string>
#include <thread>
#include <utility>
#include <vector>
namespace fair::mq::test
{
/// One runTestDevice process.
struct DeviceSpec
{
DeviceSpec(std::string id_, std::string channelConfig_ = {}, std::string extraArgs_ = {})
: id(std::move(id_))
, channelConfig(std::move(channelConfig_))
, extraArgs(std::move(extraArgs_))
{}
std::string id; ///< selects the device class, see runTestDevice.cxx
std::string channelConfig; ///< value of --channel-config (empty: none)
std::string extraArgs; ///< more command line arguments for this device
};
/// Settings for all devices of one RunDevices() call.
struct RunOptions
{
explicit RunOptions(std::string transport_ = "zeromq", std::string extraArgs_ = {})
: transport(std::move(transport_))
, extraArgs(std::move(extraArgs_))
{}
std::string transport;
std::string extraArgs; ///< more command line arguments for each device
std::string control = "static";
std::string input; ///< sent to stdin of each device after 1 s
int signal = -1; ///< sent to each device after 2 s (-1: none)
std::chrono::milliseconds timeout = std::chrono::seconds(15);
};
struct DeviceResult
{
std::string id;
std::string output;
int exitCode = -1;
};
/// Run the devices at the same time, in one session, and wait for all of
/// them. A device that runs longer than options.timeout is killed.
inline auto RunDevices(std::vector<DeviceSpec> const& devices, RunOptions const& options = RunOptions())
-> std::vector<DeviceResult>
{
auto const session = std::to_string(tools::UuidHash());
std::vector<DeviceResult> results(devices.size());
std::vector<std::thread> threads;
threads.reserve(devices.size());
for (std::size_t i = 0; i < devices.size(); ++i) {
threads.emplace_back([&, i] {
auto const& device = devices[i];
std::stringstream cmd;
cmd << runTestDevice
<< " --id " << device.id
<< " --transport " << options.transport
<< " --control " << options.control
<< " --session " << session
<< " --shm-segment-size 100000000"
<< " --shm-monitor true"
<< " --color false";
if (!options.extraArgs.empty()) {
cmd << " " << options.extraArgs;
}
if (!device.extraArgs.empty()) {
cmd << " " << device.extraArgs;
}
if (!device.channelConfig.empty()) {
cmd << " --channel-config " << device.channelConfig;
}
auto const res = tools::execute(cmd.str(),
tools::ToString("[", device.id, "] "),
options.input,
options.signal,
options.timeout);
results[i] = DeviceResult{device.id, res.console_out, res.exit_code};
});
}
for (auto& t : threads) {
t.join();
}
return results;
}
/// Check that the device exited with exitCode and that its output contains text.
inline auto ExitedWith(DeviceResult const& result, int exitCode, std::string const& text = "")
-> ::testing::AssertionResult
{
if (result.exitCode != exitCode) {
return ::testing::AssertionFailure() << "device '" << result.id << "' exited with "
<< result.exitCode << ", expected " << exitCode
<< ", output:\n" << result.output;
}
if (!text.empty() && result.output.find(text) == std::string::npos) {
return ::testing::AssertionFailure() << "output of device '" << result.id << "' has no '"
<< text << "', output:\n" << result.output;
}
return ::testing::AssertionSuccess();
}
/// Check that the device exited with 0 and reported success on the transport.
inline auto Succeeded(DeviceResult const& result, std::string const& transport)
-> ::testing::AssertionResult
{
return ExitedWith(result, 0, std::string(kSuccessMarker).append(transport));
}
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_DEVICES_H */

View File

@@ -0,0 +1,52 @@
/********************************************************************************
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_TEST_TESTDEVICE_H
#define FAIR_MQ_TEST_TESTDEVICE_H
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <stdexcept>
#include <string>
#include <string_view>
namespace fair::mq::test
{
/// Printed by a test device that has done all its checks. The test harness
/// expects it followed by the name of the transport that the device used.
constexpr std::string_view kSuccessMarker = "test device succeeded, transport: ";
/// Base class of the devices in runTestDevice.
class TestDevice : public Device
{
protected:
/// Report success; call it as the last step of the test.
void Succeed() const { LOG(info) << kSuccessMarker << GetTransportName(); }
/// Throw if the condition is false. The device then goes to the Error
/// state and exits with a non-zero exit code.
static void Check(bool condition, std::string_view what)
{
if (!condition) {
throw std::runtime_error(std::string("check failed: ").append(what));
}
}
/// The content of a message as a string.
static auto AsString(Message const& msg) -> std::string
{
return {static_cast<char const*>(msg.GetData()), msg.GetSize()};
}
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_TESTDEVICE_H */

View File

@@ -9,52 +9,35 @@
#ifndef FAIR_MQ_TEST_PAIRLEFT_H #ifndef FAIR_MQ_TEST_PAIRLEFT_H
#define FAIR_MQ_TEST_PAIRLEFT_H #define FAIR_MQ_TEST_PAIRLEFT_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <cstddef>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class PairLeft : public Device class PairLeft : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
int counter{0}; // empty message ping pong
// Simple empty message ping pong
auto msg1(NewMessageFor("data", 0)); auto msg1(NewMessageFor("data", 0));
if (Send(msg1, "data") >= 0) counter++; Check(Send(msg1, "data") >= 0, "send empty message 1");
auto msg2(NewMessageFor("data", 0)); auto msg2(NewMessageFor("data", 0));
if (Receive(msg2, "data") >= 0) counter++; Check(Receive(msg2, "data") >= 0, "receive empty message 2");
auto msg3(NewMessageFor("data", 0)); auto msg3(NewMessageFor("data", 0));
if (Send(msg3, "data") >= 0) counter++; Check(Send(msg3, "data") >= 0, "send empty message 3");
auto msg4(NewMessageFor("data", 0)); auto msg4(NewMessageFor("data", 0));
if (Receive(msg4, "data") >= 0) counter++; Check(Receive(msg4, "data") >= 0, "receive empty message 4");
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
// Simple message with short text data // message with short text data
auto msg5(NewSimpleMessageFor("data", 0, "testdata1234")); auto msg5(NewSimpleMessageFor("data", 0, "testdata1234"));
if (Send(msg5, "data") >= 0) counter++; Check(Send(msg5, "data") == 12, "send text message");
auto msg6(NewMessageFor("data", 0)); auto msg6(NewMessageFor("data", 0));
auto ret = Receive(msg6, "data"); Check(Receive(msg6, "data") == 12, "receive text message");
if (ret > 0) { Check(AsString(*msg6) == "testdata1234", "text message content");
auto content = std::string{static_cast<char*>(msg6->GetData()), msg6->GetSize()};
LOG(info) << ret << ", " << msg6->GetSize() << ", '" << content << "'";
if (msg6->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") counter++;
}
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
assert(counter == 6); Succeed();
if (counter == 6) LOG(info) << "PAIR test successfull."; }
};
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,49 +9,35 @@
#ifndef FAIR_MQ_TEST_PAIRRIGHT_H #ifndef FAIR_MQ_TEST_PAIRRIGHT_H
#define FAIR_MQ_TEST_PAIRRIGHT_H #define FAIR_MQ_TEST_PAIRRIGHT_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <cstddef>
#include <string>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class PairRight : public Device class PairRight : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
int counter{0}; // empty message ping pong
// Simple empty message ping pong
auto msg1(NewMessageFor("data", 0)); auto msg1(NewMessageFor("data", 0));
if (Receive(msg1, "data") >= 0) counter++; Check(Receive(msg1, "data") >= 0, "receive empty message 1");
auto msg2(NewMessageFor("data", 0)); auto msg2(NewMessageFor("data", 0));
if (Send(msg2, "data") >= 0) counter++; Check(Send(msg2, "data") >= 0, "send empty message 2");
auto msg3(NewMessageFor("data", 0)); auto msg3(NewMessageFor("data", 0));
if (Receive(msg3, "data") >= 0) counter++; Check(Receive(msg3, "data") >= 0, "receive empty message 3");
auto msg4(NewMessageFor("data", 0)); auto msg4(NewMessageFor("data", 0));
if (Send(msg4, "data") >= 0) counter++; Check(Send(msg4, "data") >= 0, "send empty message 4");
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
// Simple message with short text data // message with short text data
auto msg5(NewMessageFor("data", 0)); auto msg5(NewMessageFor("data", 0));
auto ret = Receive(msg5, "data"); Check(Receive(msg5, "data") == 12, "receive text message");
if (ret > 0) { Check(AsString(*msg5) == "testdata1234", "text message content");
auto content = std::string{static_cast<char*>(msg5->GetData()), msg5->GetSize()};
LOG(info) << ret << ", " << msg5->GetSize() << ", '" << content << "'";
if (msg5->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") counter++;
}
auto msg6(NewSimpleMessageFor("data", 0, "testdata1234")); auto msg6(NewSimpleMessageFor("data", 0, "testdata1234"));
if (Send(msg6, "data") >= 0) counter++; Check(Send(msg6, "data") == 12, "send text message");
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
}; Succeed();
}
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,117 +9,59 @@
#ifndef FAIR_MQ_TEST_POLLIN_H #ifndef FAIR_MQ_TEST_POLLIN_H
#define FAIR_MQ_TEST_POLLIN_H #define FAIR_MQ_TEST_POLLIN_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairmq/ProgOptions.h> #include <fairmq/ProgOptions.h>
#include <fairlogger/Logger.h> #include <vector>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
using namespace std; /// Polls two channels until a message arrived on each.
using namespace fair::mq; /// poll-type 0: poll a vector of sub-channels; 1: poll by channel names.
class PollIn : public TestDevice
class PollIn : public Device
{ {
public:
PollIn()
: fPollType(0)
{}
protected: protected:
auto InitTask() -> void override auto InitTask() -> void override
{ {
fPollType = fConfig->GetProperty<int>("poll-type"); fPollType = fConfig->GetProperty<int>("poll-type");
std::this_thread::sleep_for(std::chrono::milliseconds(200)); Check(fPollType == 0 || fPollType == 1, "poll-type is 0 or 1");
} }
auto Run() -> void override auto Run() -> void override
{ {
vector<Channel*> chans; PollerPtr poller;
if (fPollType == 0) {
chans.push_back(&GetChannel("data1", 0)); std::vector<Channel*> chans{&GetChannel("data1", 0), &GetChannel("data2", 0)};
chans.push_back(&GetChannel("data2", 0));
PollerPtr poller = nullptr;
if (fPollType == 0)
{
poller = NewPoller(chans); poller = NewPoller(chans);
} } else {
else if (fPollType == 1)
{
poller = NewPoller("data1", "data2"); poller = NewPoller("data1", "data2");
} }
else
{ auto checkInput = [&](int index, std::string const& name) {
LOG(error) << "wrong poll type provided: " << fPollType; return fPollType == 0 ? poller->CheckInput(index) : poller->CheckInput(name, 0);
} };
bool arrived1 = false; bool arrived1 = false;
bool arrived2 = false; bool arrived2 = false;
bool bothArrived = false; while (!arrived1 || !arrived2) {
MessagePtr msg1(NewMessage());
MessagePtr msg2(NewMessage());
while (!bothArrived)
{
poller->Poll(100); poller->Poll(100);
if (checkInput(0, "data1")) {
if (fPollType == 0) auto msg = NewMessage();
{ arrived1 = arrived1 || Receive(msg, "data1", 0) >= 0;
if (poller->CheckInput(0)) }
{ if (checkInput(1, "data2")) {
LOG(debug) << "CheckInput(0) triggered"; auto msg = NewMessage();
if (Receive(msg1, "data1", 0) >= 0) arrived2 = arrived2 || Receive(msg, "data2", 0) >= 0;
{
arrived1 = true;
} }
} }
if (poller->CheckInput(1)) Succeed();
{
LOG(debug) << "CheckInput(1) triggered";
if (Receive(msg2, "data2", 0) >= 0)
{
arrived2 = true;
} }
}
}
else if (fPollType == 1)
{
if (poller->CheckInput("data1", 0))
{
LOG(debug) << "CheckInput(\"data1\", 0) triggered";
if (Receive(msg1, "data1", 0) >= 0)
{
arrived1 = true;
}
}
if (poller->CheckInput("data2", 0))
{
LOG(debug) << "CheckInput(\"data2\", 0) triggered";
if (Receive(msg2, "data2", 0) >= 0)
{
arrived2 = true;
}
}
}
if (arrived1 && arrived2)
{
bothArrived = true;
LOG(info) << "POLL test successfull";
}
}
};
private: private:
int fPollType; int fPollType = 0;
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,27 +9,23 @@
#ifndef FAIR_MQ_TEST_POLLOUT_H #ifndef FAIR_MQ_TEST_POLLOUT_H
#define FAIR_MQ_TEST_POLLOUT_H #define FAIR_MQ_TEST_POLLOUT_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class PollOut : public Device class PollOut : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
auto msg1 = NewMessage(); auto msg1 = NewMessage();
Check(Send(msg1, "data1") >= 0, "send on data1");
auto msg2 = NewMessage(); auto msg2 = NewMessage();
Send(msg1, "data1"); Check(Send(msg2, "data2") >= 0, "send on data2");
Send(msg2, "data2");
}; Succeed();
}
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,60 +9,32 @@
#ifndef FAIR_MQ_TEST_PUB_H #ifndef FAIR_MQ_TEST_PUB_H
#define FAIR_MQ_TEST_PUB_H #define FAIR_MQ_TEST_PUB_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h>
#include <chrono>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class Pub : public Device /// Publishes one message after both Sub devices report that they are ready,
/// then waits for an ack from each.
class Pub : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
auto ready1 = NewMessage(); for (int i = 0; i < 2; ++i) {
auto ready2 = NewMessage(); auto ready = NewMessage();
auto r1 = Receive(ready1, "control"); Check(Receive(ready, "control") >= 0, "receive ready signal");
auto r2 = Receive(ready2, "control"); }
if (r1 >= 0 && r2 >= 0)
{
LOG(info) << "Received both ready signals, proceeding to publish data";
auto msg = NewMessage(); auto msg = NewMessage();
auto d1 = Send(msg, "data"); Check(Send(msg, "data") >= 0, "publish data");
if (d1 >= 0)
{ for (int i = 0; i < 2; ++i) {
LOG(info) << "Sent data: d1 = " << d1; auto ack = NewMessage();
} Check(Receive(ack, "control") >= 0, "receive ack");
else
{
LOG(error) << "Failed sending data: d1 = " << d1;
} }
auto ack1 = NewMessage(); Succeed();
auto ack2 = NewMessage();
auto a1 = Receive(ack1, "control");
auto a2 = Receive(ack2, "control");
if (a1 >= 0 && a2 >= 0)
{
LOG(info) << "PUB-SUB test successfull";
}
else
{
LOG(error) << "Failed receiving ack signal: a1 = " << a1 << ", a2 = " << a2;
}
}
else
{
LOG(error) << "Failed receiving ready signal: r1 = " << r1 << ", r2 = " << r2;
}
} }
}; };

View File

@@ -9,48 +9,24 @@
#ifndef FAIR_MQ_TEST_PULL_H #ifndef FAIR_MQ_TEST_PULL_H
#define FAIR_MQ_TEST_PULL_H #define FAIR_MQ_TEST_PULL_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
using namespace std; class Pull : public TestDevice
class Pull : public Device
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
int counter = 0;
auto msg1 = NewMessageFor("data", 0); auto msg1 = NewMessageFor("data", 0);
Check(Receive(msg1, "data") == 0, "receive empty message");
if (Receive(msg1, "data") >= 0) {
++counter;
}
auto msg2 = NewMessageFor("data", 0); auto msg2 = NewMessageFor("data", 0);
Check(Receive(msg2, "data") == 12, "receive text message");
Check(AsString(*msg2) == "testdata1234", "text message content");
auto ret = Receive(msg2, "data"); Succeed();
if (ret >= 0) {
auto content = std::string{static_cast<char*>(msg2->GetData()), msg2->GetSize()};
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg2->GetSize() << ", content: " << content;
if (msg2->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") {
++counter;
} }
}
if (counter == 2) {
LOG(info) << "PUSH-PULL test successfull";
}
};
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,29 +9,23 @@
#ifndef FAIR_MQ_TEST_PUSH_H #ifndef FAIR_MQ_TEST_PUSH_H
#define FAIR_MQ_TEST_PUSH_H #define FAIR_MQ_TEST_PUSH_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class Push : public Device class Push : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
// empty message
auto msg1 = NewMessageFor("data", 0); auto msg1 = NewMessageFor("data", 0);
Send(msg1, "data"); Check(Send(msg1, "data") == 0, "send empty message");
// message with short text data
auto msg2(NewSimpleMessageFor("data", 0, "testdata1234")); auto msg2(NewSimpleMessageFor("data", 0, "testdata1234"));
Send(msg2, "data"); Check(Send(msg2, "data") == 12, "send text message");
};
Succeed();
}
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,56 +9,27 @@
#ifndef FAIR_MQ_TEST_REP_H #ifndef FAIR_MQ_TEST_REP_H
#define FAIR_MQ_TEST_REP_H #define FAIR_MQ_TEST_REP_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class Rep : public Device /// Answers two requests (one from each Req device).
class Rep : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
bool check(signed long ret, const fair::mq::MessagePtr& msg)
{
auto content = std::string{static_cast<char*>(msg->GetData()), msg->GetSize()};
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg->GetSize() << ", content: " << content;
return msg->GetSize() == static_cast<std::size_t>(ret) && content == "request";
}
auto Run() -> void override auto Run() -> void override
{ {
int counter = 0; for (int i = 0; i < 2; ++i) {
auto req1 = NewMessage(); auto request = NewMessage();
auto ret1 = Receive(req1, "data"); Check(Receive(request, "data") == 7, "receive request");
if (ret1 >= 0) { Check(AsString(*request) == "request", "request content");
LOG(info) << "Received request 1";
if (check(ret1, req1)) {
++counter;
}
auto reply = NewSimpleMessageFor("data", 0, "reply"); auto reply = NewSimpleMessageFor("data", 0, "reply");
Send(reply, "data"); Check(Send(reply, "data") == 5, "send reply");
}
auto req2 = NewMessage();
auto ret2 = Receive(req2, "data");
if (ret2 >= 0) {
LOG(info) << "Received request 2";
if (check(ret2, req2)) {
++counter;
}
auto reply = NewSimpleMessageFor("data", 0, "reply");
Send(reply, "data");
} }
if (counter == 2) { Succeed();
LOG(info) << "REQ-REP test successfull";
} }
};
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,36 +9,25 @@
#ifndef FAIR_MQ_TEST_REQ_H #ifndef FAIR_MQ_TEST_REQ_H
#define FAIR_MQ_TEST_REQ_H #define FAIR_MQ_TEST_REQ_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h>
#include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class Req : public Device class Req : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
auto request = NewSimpleMessageFor("data", 0, "request"); auto request = NewSimpleMessageFor("data", 0, "request");
Send(request, "data"); Check(Send(request, "data") == 7, "send request");
auto reply = NewMessage(); auto reply = NewMessage();
if (Receive(reply, "data") >= 0) { Check(Receive(reply, "data") == 5, "receive reply");
LOG(info) << "received reply"; Check(AsString(*reply) == "reply", "reply content");
auto content = std::string{static_cast<char*>(reply->GetData()), reply->GetSize()};
LOG(info) << "Transferred reply of size: " << reply->GetSize() << ", content: " << content; Succeed();
if (content != "reply") {
ChangeStateOrThrow(Transition::ErrorFound);
} }
}
};
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -9,54 +9,34 @@
#ifndef FAIR_MQ_TEST_SUB_H #ifndef FAIR_MQ_TEST_SUB_H
#define FAIR_MQ_TEST_SUB_H #define FAIR_MQ_TEST_SUB_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
namespace fair::mq::test namespace fair::mq::test
{ {
class Sub : public Device class Sub : public TestDevice
{ {
protected: protected:
auto InitTask() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
auto Run() -> void override auto Run() -> void override
{ {
// A pub socket drops messages for a subscriber until the subscription
// has reached it. The connect is done, but the subscription can still
// be in flight: give it time before the ready signal.
std::this_thread::sleep_for(std::chrono::milliseconds(200));
auto ready = NewMessage(); auto ready = NewMessage();
auto r1 = Send(ready, "control"); Check(Send(ready, "control") >= 0, "send ready signal");
if (r1 >= 0)
{
LOG(info) << "Sent first control signal";
auto msg = NewMessage(); auto msg = NewMessage();
auto d1 = Receive(msg, "data"); Check(Receive(msg, "data") >= 0, "receive data");
if (d1 >= 0)
{
LOG(info) << "Received data";
auto ack = NewMessage(); auto ack = NewMessage();
auto a1 = Send(ack, "control"); Check(Send(ack, "control") >= 0, "send ack");
if (a1 >= 0)
{ Succeed();
LOG(info) << "Sent second control signal";
}
else
{
LOG(error) << "Failed sending ack signal: a1 = " << a1;
}
}
else
{
LOG(error) << "Failed receiving data: d1 = " << d1;
}
}
else
{
LOG(error) << "Failed sending ready signal: r1 = " << r1;
}
} }
}; };

View File

@@ -9,150 +9,44 @@
#ifndef FAIR_MQ_TEST_TRANSFERTIMEOUT_H #ifndef FAIR_MQ_TEST_TRANSFERTIMEOUT_H
#define FAIR_MQ_TEST_TRANSFERTIMEOUT_H #define FAIR_MQ_TEST_TRANSFERTIMEOUT_H
#include <fairmq/Device.h> #include "TestDevice.h"
#include <fairlogger/Logger.h> #include <string>
namespace fair::mq::test namespace fair::mq::test
{ {
using namespace fair::mq; /// Sends and receives on channels without a peer. Each transfer must end
/// with TransferCode::timeout, for a timeout of 200 ms and of 0 ms.
class TransferTimeout : public Device class TransferTimeout : public TestDevice
{ {
protected: protected:
auto Run() -> void override auto Run() -> void override
{ {
bool sendMsgCancelingAfter200ms = false; auto const timeout = static_cast<int64_t>(TransferCode::timeout);
bool receiveMsgCancelingAfter200ms = false;
bool sendMsgCancelingAfter0ms = false; for (int ms : {200, 0}) {
bool receiveMsgCancelingAfter0ms = false; auto const suffix = " (" + std::to_string(ms) + " ms)";
bool send1PartCancelingAfter200ms = false; auto msgOut(NewMessage());
bool receive1PartCancelingAfter200ms = false; auto msgIn(NewMessage());
Check(Send(msgOut, "data-out", 0, ms) == timeout, "send msg times out" + suffix);
Check(Receive(msgIn, "data-in", 0, ms) == timeout, "receive msg times out" + suffix);
bool send1PartCancelingAfter0ms = false; for (int numParts : {1, 2}) {
bool receive1PartCancelingAfter0ms = false; auto const what = std::to_string(numParts) + " part(s) times out" + suffix;
Parts partsOut;
bool send2PartsCancelingAfter200ms = false; for (int i = 0; i < numParts; ++i) {
bool receive2PartsCancelingAfter200ms = false; partsOut.AddPart(NewMessage(10));
}
bool send2PartsCancelingAfter0ms = false; Parts partsIn;
bool receive2PartsCancelingAfter0ms = false; Check(Send(partsOut, "data-out", 0, ms) == timeout, "send " + what);
Check(Receive(partsIn, "data-in", 0, ms) == timeout, "receive " + what);
MessagePtr msg1(NewMessage()); }
MessagePtr msg2(NewMessage());
if (Send(msg1, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send msg canceled (200ms)";
sendMsgCancelingAfter200ms = true;
} else {
LOG(error) << "send msg did not cancel (200ms)";
} }
if (Receive(msg2, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) { Succeed();
LOG(info) << "receive msg canceled (200ms)";
receiveMsgCancelingAfter200ms = true;
} else {
LOG(error) << "receive msg did not cancel (200ms)";
} }
if (Send(msg1, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send msg canceled (0ms)";
sendMsgCancelingAfter0ms = true;
} else {
LOG(error) << "send msg did not cancel (0ms)";
}
if (Receive(msg2, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "receive msg canceled (0ms)";
receiveMsgCancelingAfter0ms = true;
} else {
LOG(error) << "receive msg did not cancel (0ms)";
}
Parts parts1;
parts1.AddPart(NewMessage(10));
Parts parts2;
if (Send(parts1, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send 1 part canceled (200ms)";
send1PartCancelingAfter200ms = true;
} else {
LOG(error) << "send 1 part did not cancel (200ms)";
}
if (Receive(parts2, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "receive 1 part canceled (200ms)";
receive1PartCancelingAfter200ms = true;
} else {
LOG(error) << "receive 1 part did not cancel (200ms)";
}
if (Send(parts1, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send 1 part canceled (0ms)";
send1PartCancelingAfter0ms = true;
} else {
LOG(error) << "send 1 part did not cancel (0ms)";
}
if (Receive(parts2, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "receive 1 part canceled (0ms)";
receive1PartCancelingAfter0ms = true;
} else {
LOG(error) << "receive 1 part did not cancel (0ms)";
}
Parts parts3;
parts3.AddPart(NewMessage(10));
parts3.AddPart(NewMessage(10));
Parts parts4;
if (Send(parts3, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send 2 parts canceled (200ms)";
send2PartsCancelingAfter200ms = true;
} else {
LOG(error) << "send 2 parts did not cancel (200ms)";
}
if (Receive(parts4, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "receive 2 parts canceled (200ms)";
receive2PartsCancelingAfter200ms = true;
} else {
LOG(error) << "receive 2 parts did not cancel (200ms)";
}
if (Send(parts3, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "send 2 parts canceled (0ms)";
send2PartsCancelingAfter0ms = true;
} else {
LOG(error) << "send 2 parts did not cancel (0ms)";
}
if (Receive(parts4, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
LOG(info) << "receive 2 parts canceled (0ms)";
receive2PartsCancelingAfter0ms = true;
} else {
LOG(error) << "receive 2 parts did not cancel (0ms)";
}
if (sendMsgCancelingAfter200ms &&
receiveMsgCancelingAfter200ms &&
sendMsgCancelingAfter0ms &&
receiveMsgCancelingAfter0ms &&
send1PartCancelingAfter200ms &&
receive1PartCancelingAfter200ms &&
send1PartCancelingAfter0ms &&
receive1PartCancelingAfter0ms &&
send2PartsCancelingAfter200ms &&
receive2PartsCancelingAfter200ms &&
send2PartsCancelingAfter0ms &&
receive2PartsCancelingAfter0ms)
{
LOG(info) << "Transfer timeout test successfull";
}
};
}; };
} // namespace fair::mq::test } // namespace fair::mq::test

View File

@@ -6,92 +6,55 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <helper/Transport.h>
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream #include <string>
#include <thread>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPoller(string transport, int pollType) -> void auto RunPoller(string const& transport, int pollType) -> void
{ {
size_t session{UuidHash()}; IpcAddress const data1("poller_data1");
string data1IpcFile("/tmp/fmq_" + to_string(session) + "_data1_" + transport); IpcAddress const data2("poller_data2");
string data2IpcFile("/tmp/fmq_" + to_string(session) + "_data2_" + transport);
string data1Address("ipc://" + data1IpcFile);
string data2Address("ipc://" + data2IpcFile);
auto pollout = execute_result{"", 0}; auto const results = RunDevices({
thread poll_out_thread([&]() { {"pollout_" + transport, "name=data1,type=push,method=bind,address=" + data1.str()
stringstream cmd; + " name=data2,type=push,method=bind,address=" + data2.str()},
cmd << runTestDevice {"pollin_" + transport, "name=data1,type=pull,method=connect,address=" + data1.str()
<< " --id pollout_"<< transport + " name=data2,type=pull,method=connect,address=" + data2.str(),
<< " --control static" "--poll-type " + to_string(pollType)},
<< " --transport " << transport }, RunOptions(transport));
<< " --color false"
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --channel-config name=data1,type=push,method=bind,address=" << data1Address
<< " name=data2,type=push,method=bind,address=" << data2Address;
pollout = execute(cmd.str(), "[POLLOUT]");
});
auto pollin = execute_result{"", 0}; for (auto const& result : results) {
thread poll_in_thread([&]() { EXPECT_TRUE(Succeeded(result, transport));
stringstream cmd; }
cmd << runTestDevice
<< " --id pollin_" << transport
<< " --control static"
<< " --transport " << transport
<< " --color false"
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --poll-type " << pollType
<< " --channel-config name=data1,type=pull,method=connect,address=" << data1Address
<< " name=data2,type=pull,method=connect,address=" << data2Address;
pollin = execute(cmd.str(), "[POLLIN]");
});
poll_out_thread.join();
poll_in_thread.join();
cerr << pollout.console_out << pollin.console_out;
std::remove(data1IpcFile.c_str());
std::remove(data2IpcFile.c_str());
exit(pollout.exit_code + pollin.exit_code);
} }
TEST(Subchannel, zeromq) TEST(Subchannel, zeromq)
{ {
EXPECT_EXIT(RunPoller("zeromq", 0), ::testing::ExitedWithCode(0), "POLL test successfull"); RunPoller("zeromq", 0);
} }
TEST(Subchannel, shmem) TEST(Subchannel, shmem)
{ {
EXPECT_EXIT(RunPoller("shmem", 0), ::testing::ExitedWithCode(0), "POLL test successfull"); RunPoller("shmem", 0);
} }
TEST(Channel, zeromq) TEST(Channel, zeromq)
{ {
EXPECT_EXIT(RunPoller("zeromq", 1), ::testing::ExitedWithCode(0), "POLL test successfull"); RunPoller("zeromq", 1);
} }
TEST(Channel, shmem) TEST(Channel, shmem)
{ {
EXPECT_EXIT(RunPoller("shmem", 1), ::testing::ExitedWithCode(0), "POLL test successfull"); RunPoller("shmem", 1);
} }
} // namespace } // namespace

View File

@@ -6,82 +6,46 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <fairmq/tools/Unique.h> #include <helper/Transport.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream #include <string>
#include <thread>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPair(const string& transport, const string& extraDeviceCmdArgs) -> void auto RunPair(string const& transport, string const& extraArgs) -> void
{ {
size_t session{fair::mq::tools::UuidHash()}; IpcAddress const address("pair");
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
auto pairleft = execute_result{"", 100}; auto const results = RunDevices({
thread pairleft_thread([&]() { {"pairleft_" + transport, "name=data,type=pair,method=bind,address=" + address.str()},
stringstream cmd; {"pairright_" + transport, "name=data,type=pair,method=connect,address=" + address.str()},
cmd << runTestDevice }, RunOptions(transport, extraArgs));
<< " --id pairleft_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pair,method=bind,address=" << address;
pairleft = execute(cmd.str(), "[PAIR L]");
});
auto pairright = execute_result{"", 100}; for (auto const& result : results) {
thread pairright_thread([&]() { EXPECT_TRUE(Succeeded(result, transport));
stringstream cmd; }
cmd << runTestDevice
<< " --id pairright_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pair,method=connect,address=" << address;
pairright = execute(cmd.str(), "[PAIR R]");
});
pairleft_thread.join();
pairright_thread.join();
cerr << pairleft.console_out << pairright.console_out;
std::remove(ipcFile.c_str());
exit(pairleft.exit_code + pairright.exit_code);
} }
TEST(Pair, SingleMsg_MultiThreaded_ipc_zeromq) TEST(Pair, SingleMsg_MultiThreaded_ipc_zeromq)
{ {
EXPECT_EXIT(RunPair("zeromq", ""), ::testing::ExitedWithCode(0), "PAIR test successfull"); RunPair("zeromq", "");
} }
TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem) TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem)
{ {
EXPECT_EXIT(RunPair("shmem", ""), ::testing::ExitedWithCode(0), "PAIR test successfull"); RunPair("shmem", "");
} }
TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata) TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata)
{ {
EXPECT_EXIT(RunPair("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PAIR test successfull"); RunPair("shmem", "--shm-metadata-msg-size 2048");
} }
} // namespace } // namespace

View File

@@ -6,89 +6,41 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <helper/Transport.h>
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdio> // std::remove #include <string>
#include <sstream> // std::stringstream
#include <thread>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPubSub(string transport) -> void auto RunPubSub(string const& transport) -> void
{ {
size_t session{fair::mq::tools::UuidHash()}; IpcAddress const data("pub_sub_data");
string dataIpcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport); IpcAddress const control("pub_sub_control");
string ctrlIpcFile("/tmp/fmq_" + to_string(session) + "_ctrl_" + transport);
string dataAddress("ipc://" + dataIpcFile);
string ctrlAddress("ipc://" + ctrlIpcFile);
auto pub = execute_result{"", 0}; auto const subChannels = "name=data,type=sub,method=connect,address=" + data.str()
thread pub_thread([&]() { + " name=control,type=push,method=connect,address=" + control.str();
stringstream cmd; auto const results = RunDevices({
cmd << runTestDevice {"pub_" + transport, "name=data,type=pub,method=bind,address=" + data.str()
<< " --id pub_" << transport + " name=control,type=pull,method=bind,address=" + control.str()},
<< " --control static" {"sub_1_" + transport, subChannels},
<< " --transport " << transport {"sub_2_" + transport, subChannels},
<< " --session " << session }, RunOptions(transport));
<< " --color false"
<< " --channel-config name=data,type=pub,method=bind,address=" << dataAddress
<< " name=control,type=pull,method=bind,address=" << ctrlAddress;
pub = execute(cmd.str(), "[PUB]");
});
auto sub1 = execute_result{"", 0}; for (auto const& result : results) {
thread sub1_thread([&]() { EXPECT_TRUE(Succeeded(result, transport));
stringstream cmd; }
cmd << runTestDevice
<< " --id sub_1_" << transport
<< " --control static"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data,type=sub,method=connect,address=" << dataAddress
<< " name=control,type=push,method=connect,address=" << ctrlAddress;
sub1 = execute(cmd.str(), "[SUB1]");
});
auto sub2 = execute_result{"", 0};
thread sub2_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id sub_2_" << transport
<< " --control static"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data,type=sub,method=connect,address=" << dataAddress
<< " name=control,type=push,method=connect,address=" << ctrlAddress;
sub2 = execute(cmd.str(), "[SUB2]");
});
pub_thread.join();
sub1_thread.join();
sub2_thread.join();
cerr << pub.console_out << sub1.console_out << sub2.console_out << endl;
std::remove(dataIpcFile.c_str());
std::remove(ctrlIpcFile.c_str());
exit(pub.exit_code + sub1.exit_code + sub2.exit_code);
} }
TEST(PubSub, zeromq) TEST(PubSub, zeromq)
{ {
EXPECT_EXIT(RunPubSub("zeromq"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull"); RunPubSub("zeromq");
} }
} // namespace } // namespace

View File

@@ -6,82 +6,46 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <fairmq/tools/Unique.h> #include <helper/Transport.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream #include <string>
#include <thread>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPushPull(string transport, const string& extraDeviceCmdArgs) -> void auto RunPushPull(string const& transport, string const& extraArgs) -> void
{ {
size_t session(fair::mq::tools::UuidHash()); IpcAddress const address("push_pull");
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
auto push = execute_result{"", 100}; auto const results = RunDevices({
thread push_thread([&]() { {"push_" + transport, "name=data,type=push,method=bind,address=" + address.str()},
stringstream cmd; {"pull_" + transport, "name=data,type=pull,method=connect,address=" + address.str()},
cmd << runTestDevice }, RunOptions(transport, extraArgs));
<< " --id push_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=push,method=bind,address=" << address;
push = execute(cmd.str(), "[PUSH]");
});
auto pull = execute_result{"", 100}; for (auto const& result : results) {
thread pull_thread([&]() { EXPECT_TRUE(Succeeded(result, transport));
stringstream cmd; }
cmd << runTestDevice
<< " --id pull_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pull,method=connect,address=" << address;
pull = execute(cmd.str(), "[PULL]");
});
push_thread.join();
pull_thread.join();
cerr << push.console_out << pull.console_out;
std::remove(ipcFile.c_str());
exit(push.exit_code + pull.exit_code);
} }
TEST(PushPull, SingleMsg_MultiThreaded_ipc_zeromq) TEST(PushPull, SingleMsg_MultiThreaded_ipc_zeromq)
{ {
EXPECT_EXIT(RunPushPull("zeromq", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull"); RunPushPull("zeromq", "");
} }
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem) TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem)
{ {
EXPECT_EXIT(RunPushPull("shmem", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull"); RunPushPull("shmem", "");
} }
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata) TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata)
{ {
EXPECT_EXIT(RunPushPull("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull"); RunPushPull("shmem", "--shm-metadata-msg-size 2048");
} }
} // namespace } // namespace

View File

@@ -6,99 +6,47 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <fairmq/tools/Unique.h> #include <helper/Transport.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream #include <string>
#include <thread>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunReqRep(string transport, const string& extraDeviceCmdArgs) -> void auto RunReqRep(string const& transport, string const& extraArgs) -> void
{ {
size_t session{fair::mq::tools::UuidHash()}; IpcAddress const address("req_rep");
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
auto rep = execute_result{"", 0}; auto const results = RunDevices({
thread rep_thread([&]() { {"rep_" + transport, "name=data,type=rep,method=bind,address=" + address.str()},
stringstream cmd; {"req_1_" + transport, "name=data,type=req,method=connect,address=" + address.str()},
cmd << runTestDevice {"req_2_" + transport, "name=data,type=req,method=connect,address=" + address.str()},
<< " --id rep_" << transport }, RunOptions(transport, extraArgs));
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=rep,method=bind,address=" << address;
rep = execute(cmd.str(), "[REP]");
});
auto req1 = execute_result{"", 0}; for (auto const& result : results) {
thread req1_thread([&]() { EXPECT_TRUE(Succeeded(result, transport));
stringstream cmd; }
cmd << runTestDevice
<< " --id req_1_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=req,method=connect,address=" << address;
req1 = execute(cmd.str(), "[REQ1]");
});
auto req2 = execute_result{"", 0};
thread req2_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id req_2_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=req,method=connect,address=" << address;
req2 = execute(cmd.str(), "[REQ2]");
});
rep_thread.join();
req1_thread.join();
req2_thread.join();
cerr << req1.console_out << req2.console_out << rep.console_out;
std::remove(ipcFile.c_str());
exit(req1.exit_code + req2.exit_code + rep.exit_code);
} }
TEST(ReqRep, zeromq) TEST(ReqRep, zeromq)
{ {
EXPECT_EXIT(RunReqRep("zeromq", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull"); RunReqRep("zeromq", "");
} }
TEST(ReqRep, shmem) TEST(ReqRep, shmem)
{ {
EXPECT_EXIT(RunReqRep("shmem", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull"); RunReqRep("shmem", "");
} }
TEST(ReqRep, shmem_expanded_metadata) TEST(ReqRep, shmem_expanded_metadata)
{ {
EXPECT_EXIT(RunReqRep("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "REQ-REP test successfull"); RunReqRep("shmem", "--shm-metadata-msg-size 2048");
} }
} // namespace } // namespace

View File

@@ -6,23 +6,19 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h"
#include <fairmq/Channel.h> #include <fairmq/Channel.h>
#include <fairmq/TransportFactory.h> #include <fairmq/TransportFactory.h>
#include <fairmq/ProgOptions.h> #include <fairmq/ProgOptions.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
#include <fairmq/tools/Unique.h> #include <fairmq/tools/Unique.h>
#include <fairlogger/Logger.h> #include <helper/Devices.h>
#include <helper/Transport.h> #include <helper/Transport.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <chrono> #include <chrono>
#include <cstdio> // std::remove #include <string>
#include <sstream> // std::stringstream
#include <thread> #include <thread>
namespace namespace
@@ -39,34 +35,18 @@ void delayedInterruptor(TransportFactory& transport)
transport.Interrupt(); transport.Interrupt();
} }
auto RunTransferTimeout(string transport) -> void auto RunTransferTimeout(string const& transport) -> void
{ {
size_t session{UuidHash()}; IpcAddress const dataIn("transfer_timeout_in");
string dataInIpcFile("/tmp/fmq_" + to_string(session) + "_datain_" + transport); IpcAddress const dataOut("transfer_timeout_out");
string dataOutIpcFile("/tmp/fmq_" + to_string(session) + "_dataout_" + transport);
string dataInAddress("ipc://" + dataInIpcFile);
string dataOutAddress("ipc://" + dataOutIpcFile);
stringstream cmd; auto const results = RunDevices({
cmd << runTestDevice {"transfer_timeout_" + transport,
<< " --id transfer_timeout_" << transport "name=data-in,type=pull,method=bind,address=" + dataIn.str()
<< " --control static" + " name=data-out,type=push,method=bind,address=" + dataOut.str()},
<< " --shm-segment-size 100000000" }, RunOptions(transport, "--severity debug"));
<< " --severity debug"
<< " --shm-monitor true"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data-in,type=pull,method=bind,address=" << dataInAddress
<< " name=data-out,type=push,method=bind,address=" << dataOutAddress;
auto res = execute(cmd.str());
cerr << res.console_out; EXPECT_TRUE(Succeeded(results.at(0), transport));
std::remove(dataInIpcFile.c_str());
std::remove(dataOutIpcFile.c_str());
exit(res.exit_code);
} }
void InterruptTransfer(const string& transport, const string& name) void InterruptTransfer(const string& transport, const string& name)
@@ -93,12 +73,12 @@ void InterruptTransfer(const string& transport, const string& name)
TEST(TransferTimeout, zeromq) TEST(TransferTimeout, zeromq)
{ {
EXPECT_EXIT(RunTransferTimeout("zeromq"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull"); RunTransferTimeout("zeromq");
} }
TEST(TransferTimeout, shmem) TEST(TransferTimeout, shmem)
{ {
EXPECT_EXIT(RunTransferTimeout("shmem"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull"); RunTransferTimeout("shmem");
} }
TEST(InterruptTransfer, zeromq) TEST(InterruptTransfer, zeromq)