diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bed6666a..f1f0039e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,6 +49,7 @@ add_testhelper(runTestDevice helper/devices/TestRep.h helper/devices/TestReq.h helper/devices/TestSub.h + helper/devices/TestDevice.h helper/devices/TestTransferTimeout.h helper/devices/TestWaitFor.h helper/devices/TestExceptions.h diff --git a/test/helper/Devices.h b/test/helper/Devices.h new file mode 100644 index 00000000..142411b6 --- /dev/null +++ b/test/helper/Devices.h @@ -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 +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +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 const& devices, RunOptions const& options = RunOptions()) + -> std::vector +{ + auto const session = std::to_string(tools::UuidHash()); + std::vector results(devices.size()); + std::vector 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 */ diff --git a/test/helper/devices/TestDevice.h b/test/helper/devices/TestDevice.h new file mode 100644 index 00000000..71ee9c86 --- /dev/null +++ b/test/helper/devices/TestDevice.h @@ -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 + +#include + +#include +#include +#include + +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(msg.GetData()), msg.GetSize()}; + } +}; + +} // namespace fair::mq::test + +#endif /* FAIR_MQ_TEST_TESTDEVICE_H */ diff --git a/test/helper/devices/TestPairLeft.h b/test/helper/devices/TestPairLeft.h index 49202767..8d0b56dd 100644 --- a/test/helper/devices/TestPairLeft.h +++ b/test/helper/devices/TestPairLeft.h @@ -9,52 +9,35 @@ #ifndef FAIR_MQ_TEST_PAIRLEFT_H #define FAIR_MQ_TEST_PAIRLEFT_H -#include - -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class PairLeft : public Device +class PairLeft : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { - int counter{0}; - - // Simple empty message ping pong + // empty message ping pong 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)); - if (Receive(msg2, "data") >= 0) counter++; + Check(Receive(msg2, "data") >= 0, "receive empty message 2"); 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)); - if (Receive(msg4, "data") >= 0) counter++; - if (counter == 4) LOG(info) << "Simple empty message ping pong successfull"; + Check(Receive(msg4, "data") >= 0, "receive empty message 4"); - // Simple message with short text data + // message with short text data 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 ret = Receive(msg6, "data"); - if (ret > 0) { - auto content = std::string{static_cast(msg6->GetData()), msg6->GetSize()}; - LOG(info) << ret << ", " << msg6->GetSize() << ", '" << content << "'"; - if (msg6->GetSize() == static_cast(ret) && content == "testdata1234") counter++; - } - if (counter == 6) LOG(info) << "Simple message with short text data successfull"; + Check(Receive(msg6, "data") == 12, "receive text message"); + Check(AsString(*msg6) == "testdata1234", "text message content"); - assert(counter == 6); - if (counter == 6) LOG(info) << "PAIR test successfull."; - }; + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestPairRight.h b/test/helper/devices/TestPairRight.h index 31e5ea02..6181099e 100644 --- a/test/helper/devices/TestPairRight.h +++ b/test/helper/devices/TestPairRight.h @@ -9,49 +9,35 @@ #ifndef FAIR_MQ_TEST_PAIRRIGHT_H #define FAIR_MQ_TEST_PAIRRIGHT_H -#include -#include -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class PairRight : public Device +class PairRight : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { - int counter{0}; - - // Simple empty message ping pong + // empty message ping pong 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)); - if (Send(msg2, "data") >= 0) counter++; + Check(Send(msg2, "data") >= 0, "send empty message 2"); 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)); - if (Send(msg4, "data") >= 0) counter++; - if (counter == 4) LOG(info) << "Simple empty message ping pong successfull"; + Check(Send(msg4, "data") >= 0, "send empty message 4"); - // Simple message with short text data + // message with short text data auto msg5(NewMessageFor("data", 0)); - auto ret = Receive(msg5, "data"); - if (ret > 0) { - auto content = std::string{static_cast(msg5->GetData()), msg5->GetSize()}; - LOG(info) << ret << ", " << msg5->GetSize() << ", '" << content << "'"; - if (msg5->GetSize() == static_cast(ret) && content == "testdata1234") counter++; - } + Check(Receive(msg5, "data") == 12, "receive text message"); + Check(AsString(*msg5) == "testdata1234", "text message content"); auto msg6(NewSimpleMessageFor("data", 0, "testdata1234")); - if (Send(msg6, "data") >= 0) counter++; - if (counter == 6) LOG(info) << "Simple message with short text data successfull"; - }; + Check(Send(msg6, "data") == 12, "send text message"); + + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestPollIn.h b/test/helper/devices/TestPollIn.h index 6b8c6652..af2e2dcf 100644 --- a/test/helper/devices/TestPollIn.h +++ b/test/helper/devices/TestPollIn.h @@ -9,117 +9,59 @@ #ifndef FAIR_MQ_TEST_POLLIN_H #define FAIR_MQ_TEST_POLLIN_H -#include +#include "TestDevice.h" + #include -#include - -#include +#include namespace fair::mq::test { -using namespace std; -using namespace fair::mq; - -class PollIn : public Device +/// Polls two channels until a message arrived on each. +/// poll-type 0: poll a vector of sub-channels; 1: poll by channel names. +class PollIn : public TestDevice { - public: - PollIn() - : fPollType(0) - {} - protected: auto InitTask() -> void override { fPollType = fConfig->GetProperty("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 { - vector chans; - - chans.push_back(&GetChannel("data1", 0)); - chans.push_back(&GetChannel("data2", 0)); - - PollerPtr poller = nullptr; - - if (fPollType == 0) - { + PollerPtr poller; + if (fPollType == 0) { + std::vector chans{&GetChannel("data1", 0), &GetChannel("data2", 0)}; poller = NewPoller(chans); - } - else if (fPollType == 1) - { + } else { poller = NewPoller("data1", "data2"); } - else - { - LOG(error) << "wrong poll type provided: " << fPollType; - } + + auto checkInput = [&](int index, std::string const& name) { + return fPollType == 0 ? poller->CheckInput(index) : poller->CheckInput(name, 0); + }; bool arrived1 = false; bool arrived2 = false; - bool bothArrived = false; - - MessagePtr msg1(NewMessage()); - MessagePtr msg2(NewMessage()); - - while (!bothArrived) - { + while (!arrived1 || !arrived2) { poller->Poll(100); - - if (fPollType == 0) - { - if (poller->CheckInput(0)) - { - LOG(debug) << "CheckInput(0) triggered"; - if (Receive(msg1, "data1", 0) >= 0) - { - arrived1 = true; - } - } - - if (poller->CheckInput(1)) - { - LOG(debug) << "CheckInput(1) triggered"; - if (Receive(msg2, "data2", 0) >= 0) - { - arrived2 = true; - } - } + if (checkInput(0, "data1")) { + auto msg = NewMessage(); + arrived1 = arrived1 || Receive(msg, "data1", 0) >= 0; } - 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"; + if (checkInput(1, "data2")) { + auto msg = NewMessage(); + arrived2 = arrived2 || Receive(msg, "data2", 0) >= 0; } } - }; + + Succeed(); + } private: - int fPollType; + int fPollType = 0; }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestPollOut.h b/test/helper/devices/TestPollOut.h index a8eaef5a..4c806264 100644 --- a/test/helper/devices/TestPollOut.h +++ b/test/helper/devices/TestPollOut.h @@ -9,27 +9,23 @@ #ifndef FAIR_MQ_TEST_POLLOUT_H #define FAIR_MQ_TEST_POLLOUT_H -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class PollOut : public Device +class PollOut : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { auto msg1 = NewMessage(); + Check(Send(msg1, "data1") >= 0, "send on data1"); auto msg2 = NewMessage(); - Send(msg1, "data1"); - Send(msg2, "data2"); - }; + Check(Send(msg2, "data2") >= 0, "send on data2"); + + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestPub.h b/test/helper/devices/TestPub.h index 4ae3ba94..9cf83bfe 100644 --- a/test/helper/devices/TestPub.h +++ b/test/helper/devices/TestPub.h @@ -9,60 +9,32 @@ #ifndef FAIR_MQ_TEST_PUB_H #define FAIR_MQ_TEST_PUB_H -#include -#include -#include -#include +#include "TestDevice.h" 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: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { - auto ready1 = NewMessage(); - auto ready2 = NewMessage(); - auto r1 = Receive(ready1, "control"); - auto r2 = Receive(ready2, "control"); - if (r1 >= 0 && r2 >= 0) - { - LOG(info) << "Received both ready signals, proceeding to publish data"; - - auto msg = NewMessage(); - auto d1 = Send(msg, "data"); - if (d1 >= 0) - { - LOG(info) << "Sent data: d1 = " << d1; - } - else - { - LOG(error) << "Failed sending data: d1 = " << d1; - } - - auto ack1 = NewMessage(); - 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; - } + for (int i = 0; i < 2; ++i) { + auto ready = NewMessage(); + Check(Receive(ready, "control") >= 0, "receive ready signal"); } - else - { - LOG(error) << "Failed receiving ready signal: r1 = " << r1 << ", r2 = " << r2; + + auto msg = NewMessage(); + Check(Send(msg, "data") >= 0, "publish data"); + + for (int i = 0; i < 2; ++i) { + auto ack = NewMessage(); + Check(Receive(ack, "control") >= 0, "receive ack"); } + + Succeed(); } }; diff --git a/test/helper/devices/TestPull.h b/test/helper/devices/TestPull.h index c369c5a2..85b9731a 100644 --- a/test/helper/devices/TestPull.h +++ b/test/helper/devices/TestPull.h @@ -9,48 +9,24 @@ #ifndef FAIR_MQ_TEST_PULL_H #define FAIR_MQ_TEST_PULL_H -#include -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -using namespace std; - -class Pull : public Device +class Pull : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { - int counter = 0; - auto msg1 = NewMessageFor("data", 0); - - if (Receive(msg1, "data") >= 0) { - ++counter; - } - + Check(Receive(msg1, "data") == 0, "receive empty message"); 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"); - if (ret >= 0) { - auto content = std::string{static_cast(msg2->GetData()), msg2->GetSize()}; - LOG(info) << "Transferred " << static_cast(ret) << " bytes, msg size: " << msg2->GetSize() << ", content: " << content; - if (msg2->GetSize() == static_cast(ret) && content == "testdata1234") { - ++counter; - } - } - - if (counter == 2) { - LOG(info) << "PUSH-PULL test successfull"; - } - }; + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestPush.h b/test/helper/devices/TestPush.h index 3ee3f33c..e0b018d3 100644 --- a/test/helper/devices/TestPush.h +++ b/test/helper/devices/TestPush.h @@ -9,29 +9,23 @@ #ifndef FAIR_MQ_TEST_PUSH_H #define FAIR_MQ_TEST_PUSH_H -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class Push : public Device +class Push : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { - // empty message auto msg1 = NewMessageFor("data", 0); - Send(msg1, "data"); - // message with short text data + Check(Send(msg1, "data") == 0, "send empty message"); auto msg2(NewSimpleMessageFor("data", 0, "testdata1234")); - Send(msg2, "data"); - }; + Check(Send(msg2, "data") == 12, "send text message"); + + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestRep.h b/test/helper/devices/TestRep.h index 0615f349..a4fd247d 100644 --- a/test/helper/devices/TestRep.h +++ b/test/helper/devices/TestRep.h @@ -9,56 +9,27 @@ #ifndef FAIR_MQ_TEST_REP_H #define FAIR_MQ_TEST_REP_H -#include -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class Rep : public Device +/// Answers two requests (one from each Req device). +class Rep : public TestDevice { 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(msg->GetData()), msg->GetSize()}; - LOG(info) << "Transferred " << static_cast(ret) << " bytes, msg size: " << msg->GetSize() << ", content: " << content; - return msg->GetSize() == static_cast(ret) && content == "request"; - } - auto Run() -> void override { - int counter = 0; - auto req1 = NewMessage(); - auto ret1 = Receive(req1, "data"); - if (ret1 >= 0) { - LOG(info) << "Received request 1"; - if (check(ret1, req1)) { - ++counter; - } + for (int i = 0; i < 2; ++i) { + auto request = NewMessage(); + Check(Receive(request, "data") == 7, "receive request"); + Check(AsString(*request) == "request", "request content"); auto reply = NewSimpleMessageFor("data", 0, "reply"); - Send(reply, "data"); - } - 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"); + Check(Send(reply, "data") == 5, "send reply"); } - if (counter == 2) { - LOG(info) << "REQ-REP test successfull"; - } - }; + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestReq.h b/test/helper/devices/TestReq.h index 2c55d7f4..362d0fd1 100644 --- a/test/helper/devices/TestReq.h +++ b/test/helper/devices/TestReq.h @@ -9,36 +9,25 @@ #ifndef FAIR_MQ_TEST_REQ_H #define FAIR_MQ_TEST_REQ_H -#include -#include -#include +#include "TestDevice.h" namespace fair::mq::test { -class Req : public Device +class Req : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - auto Run() -> void override { auto request = NewSimpleMessageFor("data", 0, "request"); - Send(request, "data"); + Check(Send(request, "data") == 7, "send request"); auto reply = NewMessage(); - if (Receive(reply, "data") >= 0) { - LOG(info) << "received reply"; - auto content = std::string{static_cast(reply->GetData()), reply->GetSize()}; - LOG(info) << "Transferred reply of size: " << reply->GetSize() << ", content: " << content; - if (content != "reply") { - ChangeStateOrThrow(Transition::ErrorFound); - } - } - }; + Check(Receive(reply, "data") == 5, "receive reply"); + Check(AsString(*reply) == "reply", "reply content"); + + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/helper/devices/TestSub.h b/test/helper/devices/TestSub.h index 4d248b3f..4b3845f6 100644 --- a/test/helper/devices/TestSub.h +++ b/test/helper/devices/TestSub.h @@ -9,54 +9,34 @@ #ifndef FAIR_MQ_TEST_SUB_H #define FAIR_MQ_TEST_SUB_H -#include -#include +#include "TestDevice.h" + #include #include namespace fair::mq::test { -class Sub : public Device +class Sub : public TestDevice { protected: - auto InitTask() -> void override - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - 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 r1 = Send(ready, "control"); - if (r1 >= 0) - { - LOG(info) << "Sent first control signal"; - auto msg = NewMessage(); - auto d1 = Receive(msg, "data"); - if (d1 >= 0) - { - LOG(info) << "Received data"; - auto ack = NewMessage(); - auto a1 = Send(ack, "control"); - if (a1 >= 0) - { - 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; - } + Check(Send(ready, "control") >= 0, "send ready signal"); + + auto msg = NewMessage(); + Check(Receive(msg, "data") >= 0, "receive data"); + + auto ack = NewMessage(); + Check(Send(ack, "control") >= 0, "send ack"); + + Succeed(); } }; diff --git a/test/helper/devices/TestTransferTimeout.h b/test/helper/devices/TestTransferTimeout.h index fbadb44f..0e64b898 100644 --- a/test/helper/devices/TestTransferTimeout.h +++ b/test/helper/devices/TestTransferTimeout.h @@ -9,150 +9,44 @@ #ifndef FAIR_MQ_TEST_TRANSFERTIMEOUT_H #define FAIR_MQ_TEST_TRANSFERTIMEOUT_H -#include +#include "TestDevice.h" -#include +#include namespace fair::mq::test { -using namespace fair::mq; - -class TransferTimeout : public Device +/// 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 TestDevice { protected: auto Run() -> void override { - bool sendMsgCancelingAfter200ms = false; - bool receiveMsgCancelingAfter200ms = false; + auto const timeout = static_cast(TransferCode::timeout); - bool sendMsgCancelingAfter0ms = false; - bool receiveMsgCancelingAfter0ms = false; + for (int ms : {200, 0}) { + auto const suffix = " (" + std::to_string(ms) + " ms)"; - bool send1PartCancelingAfter200ms = false; - bool receive1PartCancelingAfter200ms = false; + auto msgOut(NewMessage()); + 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; - bool receive1PartCancelingAfter0ms = false; - - bool send2PartsCancelingAfter200ms = false; - bool receive2PartsCancelingAfter200ms = false; - - bool send2PartsCancelingAfter0ms = false; - bool receive2PartsCancelingAfter0ms = false; - - MessagePtr msg1(NewMessage()); - MessagePtr msg2(NewMessage()); - - if (Send(msg1, "data-out", 0, 200) == static_cast(TransferCode::timeout)) { - LOG(info) << "send msg canceled (200ms)"; - sendMsgCancelingAfter200ms = true; - } else { - LOG(error) << "send msg did not cancel (200ms)"; + for (int numParts : {1, 2}) { + auto const what = std::to_string(numParts) + " part(s) times out" + suffix; + Parts partsOut; + for (int i = 0; i < numParts; ++i) { + partsOut.AddPart(NewMessage(10)); + } + Parts partsIn; + Check(Send(partsOut, "data-out", 0, ms) == timeout, "send " + what); + Check(Receive(partsIn, "data-in", 0, ms) == timeout, "receive " + what); + } } - if (Receive(msg2, "data-in", 0, 200) == static_cast(TransferCode::timeout)) { - 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(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(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(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(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(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(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(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(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(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(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"; - } - }; + Succeed(); + } }; } // namespace fair::mq::test diff --git a/test/poller/_poller.cxx b/test/poller/_poller.cxx index f9e449bf..9a79ee1c 100644 --- a/test/poller/_poller.cxx +++ b/test/poller/_poller.cxx @@ -6,92 +6,55 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" +#include +#include -#include -#include -#include #include -#include // std::remove -#include // std::stringstream -#include + +#include namespace { using namespace std; 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()}; - string data1IpcFile("/tmp/fmq_" + to_string(session) + "_data1_" + transport); - string data2IpcFile("/tmp/fmq_" + to_string(session) + "_data2_" + transport); - string data1Address("ipc://" + data1IpcFile); - string data2Address("ipc://" + data2IpcFile); + IpcAddress const data1("poller_data1"); + IpcAddress const data2("poller_data2"); - auto pollout = execute_result{"", 0}; - thread poll_out_thread([&]() { - stringstream cmd; - cmd << runTestDevice - << " --id pollout_"<< transport - << " --control static" - << " --transport " << 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 const results = RunDevices({ + {"pollout_" + transport, "name=data1,type=push,method=bind,address=" + data1.str() + + " name=data2,type=push,method=bind,address=" + data2.str()}, + {"pollin_" + transport, "name=data1,type=pull,method=connect,address=" + data1.str() + + " name=data2,type=pull,method=connect,address=" + data2.str(), + "--poll-type " + to_string(pollType)}, + }, RunOptions(transport)); - auto pollin = execute_result{"", 0}; - thread poll_in_thread([&]() { - 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); + for (auto const& result : results) { + EXPECT_TRUE(Succeeded(result, transport)); + } } TEST(Subchannel, zeromq) { - EXPECT_EXIT(RunPoller("zeromq", 0), ::testing::ExitedWithCode(0), "POLL test successfull"); + RunPoller("zeromq", 0); } TEST(Subchannel, shmem) { - EXPECT_EXIT(RunPoller("shmem", 0), ::testing::ExitedWithCode(0), "POLL test successfull"); + RunPoller("shmem", 0); } TEST(Channel, zeromq) { - EXPECT_EXIT(RunPoller("zeromq", 1), ::testing::ExitedWithCode(0), "POLL test successfull"); + RunPoller("zeromq", 1); } TEST(Channel, shmem) { - EXPECT_EXIT(RunPoller("shmem", 1), ::testing::ExitedWithCode(0), "POLL test successfull"); + RunPoller("shmem", 1); } } // namespace diff --git a/test/protocols/_pair.cxx b/test/protocols/_pair.cxx index 019392d1..df3cd2ee 100644 --- a/test/protocols/_pair.cxx +++ b/test/protocols/_pair.cxx @@ -6,82 +6,46 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" -#include -#include -#include +#include +#include + #include -#include // std::remove -#include // std::stringstream -#include + +#include namespace { using namespace std; 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()}; - string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport); - string address("ipc://" + ipcFile); + IpcAddress const address("pair"); - auto pairleft = execute_result{"", 100}; - thread pairleft_thread([&]() { - stringstream cmd; - cmd << runTestDevice - << " --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 const results = RunDevices({ + {"pairleft_" + transport, "name=data,type=pair,method=bind,address=" + address.str()}, + {"pairright_" + transport, "name=data,type=pair,method=connect,address=" + address.str()}, + }, RunOptions(transport, extraArgs)); - auto pairright = execute_result{"", 100}; - thread pairright_thread([&]() { - 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); + for (auto const& result : results) { + EXPECT_TRUE(Succeeded(result, transport)); + } } TEST(Pair, SingleMsg_MultiThreaded_ipc_zeromq) { - EXPECT_EXIT(RunPair("zeromq", ""), ::testing::ExitedWithCode(0), "PAIR test successfull"); + RunPair("zeromq", ""); } 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) { - EXPECT_EXIT(RunPair("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PAIR test successfull"); + RunPair("shmem", "--shm-metadata-msg-size 2048"); } } // namespace diff --git a/test/protocols/_pub_sub.cxx b/test/protocols/_pub_sub.cxx index 5548dbf5..c10b34a1 100644 --- a/test/protocols/_pub_sub.cxx +++ b/test/protocols/_pub_sub.cxx @@ -6,89 +6,41 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" - -#include -#include -#include +#include +#include #include -#include // std::remove -#include // std::stringstream -#include +#include namespace { using namespace std; 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()}; - string dataIpcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport); - string ctrlIpcFile("/tmp/fmq_" + to_string(session) + "_ctrl_" + transport); - string dataAddress("ipc://" + dataIpcFile); - string ctrlAddress("ipc://" + ctrlIpcFile); + IpcAddress const data("pub_sub_data"); + IpcAddress const control("pub_sub_control"); - auto pub = execute_result{"", 0}; - thread pub_thread([&]() { - stringstream cmd; - cmd << runTestDevice - << " --id pub_" << transport - << " --control static" - << " --transport " << transport - << " --session " << session - << " --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 const subChannels = "name=data,type=sub,method=connect,address=" + data.str() + + " name=control,type=push,method=connect,address=" + control.str(); + auto const results = RunDevices({ + {"pub_" + transport, "name=data,type=pub,method=bind,address=" + data.str() + + " name=control,type=pull,method=bind,address=" + control.str()}, + {"sub_1_" + transport, subChannels}, + {"sub_2_" + transport, subChannels}, + }, RunOptions(transport)); - auto sub1 = execute_result{"", 0}; - thread sub1_thread([&]() { - 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); + for (auto const& result : results) { + EXPECT_TRUE(Succeeded(result, transport)); + } } TEST(PubSub, zeromq) { - EXPECT_EXIT(RunPubSub("zeromq"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull"); + RunPubSub("zeromq"); } } // namespace diff --git a/test/protocols/_push_pull.cxx b/test/protocols/_push_pull.cxx index 6feafb3b..88f2b5cf 100644 --- a/test/protocols/_push_pull.cxx +++ b/test/protocols/_push_pull.cxx @@ -6,82 +6,46 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" -#include -#include -#include +#include +#include + #include -#include // std::remove -#include // std::stringstream -#include + +#include namespace { using namespace std; 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()); - string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport); - string address("ipc://" + ipcFile); + IpcAddress const address("push_pull"); - auto push = execute_result{"", 100}; - thread push_thread([&]() { - stringstream cmd; - cmd << runTestDevice - << " --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 const results = RunDevices({ + {"push_" + transport, "name=data,type=push,method=bind,address=" + address.str()}, + {"pull_" + transport, "name=data,type=pull,method=connect,address=" + address.str()}, + }, RunOptions(transport, extraArgs)); - auto pull = execute_result{"", 100}; - thread pull_thread([&]() { - 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); + for (auto const& result : results) { + EXPECT_TRUE(Succeeded(result, transport)); + } } 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) { - EXPECT_EXIT(RunPushPull("shmem", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull"); + RunPushPull("shmem", ""); } 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 diff --git a/test/protocols/_req_rep.cxx b/test/protocols/_req_rep.cxx index f30dc9d9..63216ecd 100644 --- a/test/protocols/_req_rep.cxx +++ b/test/protocols/_req_rep.cxx @@ -6,99 +6,47 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" -#include -#include -#include +#include +#include + #include -#include // std::remove -#include // std::stringstream -#include + +#include namespace { using namespace std; 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()}; - string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport); - string address("ipc://" + ipcFile); + IpcAddress const address("req_rep"); - auto rep = execute_result{"", 0}; - thread rep_thread([&]() { - stringstream cmd; - cmd << runTestDevice - << " --id rep_" << transport - << " --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 const results = RunDevices({ + {"rep_" + transport, "name=data,type=rep,method=bind,address=" + address.str()}, + {"req_1_" + transport, "name=data,type=req,method=connect,address=" + address.str()}, + {"req_2_" + transport, "name=data,type=req,method=connect,address=" + address.str()}, + }, RunOptions(transport, extraArgs)); - auto req1 = execute_result{"", 0}; - thread req1_thread([&]() { - 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); + for (auto const& result : results) { + EXPECT_TRUE(Succeeded(result, transport)); + } } TEST(ReqRep, zeromq) { - EXPECT_EXIT(RunReqRep("zeromq", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull"); + RunReqRep("zeromq", ""); } TEST(ReqRep, shmem) { - EXPECT_EXIT(RunReqRep("shmem", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull"); + RunReqRep("shmem", ""); } 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 diff --git a/test/transport/_transfer_timeout.cxx b/test/transport/_transfer_timeout.cxx index df28318a..1bdfab60 100644 --- a/test/transport/_transfer_timeout.cxx +++ b/test/transport/_transfer_timeout.cxx @@ -6,23 +6,19 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ -#include "runner.h" - #include #include #include -#include #include #include -#include - +#include #include + #include #include -#include // std::remove -#include // std::stringstream +#include #include namespace @@ -39,34 +35,18 @@ void delayedInterruptor(TransportFactory& transport) transport.Interrupt(); } -auto RunTransferTimeout(string transport) -> void +auto RunTransferTimeout(string const& transport) -> void { - size_t session{UuidHash()}; - string dataInIpcFile("/tmp/fmq_" + to_string(session) + "_datain_" + transport); - string dataOutIpcFile("/tmp/fmq_" + to_string(session) + "_dataout_" + transport); - string dataInAddress("ipc://" + dataInIpcFile); - string dataOutAddress("ipc://" + dataOutIpcFile); + IpcAddress const dataIn("transfer_timeout_in"); + IpcAddress const dataOut("transfer_timeout_out"); - stringstream cmd; - cmd << runTestDevice - << " --id transfer_timeout_" << transport - << " --control static" - << " --shm-segment-size 100000000" - << " --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()); + auto const results = RunDevices({ + {"transfer_timeout_" + transport, + "name=data-in,type=pull,method=bind,address=" + dataIn.str() + + " name=data-out,type=push,method=bind,address=" + dataOut.str()}, + }, RunOptions(transport, "--severity debug")); - cerr << res.console_out; - - std::remove(dataInIpcFile.c_str()); - std::remove(dataOutIpcFile.c_str()); - - exit(res.exit_code); + EXPECT_TRUE(Succeeded(results.at(0), transport)); } void InterruptTransfer(const string& transport, const string& name) @@ -93,12 +73,12 @@ void InterruptTransfer(const string& transport, const string& name) TEST(TransferTimeout, zeromq) { - EXPECT_EXIT(RunTransferTimeout("zeromq"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull"); + RunTransferTimeout("zeromq"); } TEST(TransferTimeout, shmem) { - EXPECT_EXIT(RunTransferTimeout("shmem"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull"); + RunTransferTimeout("shmem"); } TEST(InterruptTransfer, zeromq)