refactor(test): merge the state action test devices

- Replace TestExceptions, TestErrorState, TestSignals and TestWaitFor
  with one StateAction device; the id selects the action and the state
- Run the device tests through test::RunDevices() instead of
  EXPECT_EXIT() and check the exit code and the expected log line

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

View File

@@ -50,9 +50,8 @@ add_testhelper(runTestDevice
helper/devices/TestReq.h helper/devices/TestReq.h
helper/devices/TestSub.h helper/devices/TestSub.h
helper/devices/TestDevice.h helper/devices/TestDevice.h
helper/devices/TestStateAction.h
helper/devices/TestTransferTimeout.h helper/devices/TestTransferTimeout.h
helper/devices/TestWaitFor.h
helper/devices/TestExceptions.h
LINKS FairMQ LINKS FairMQ
${definitions} ${definitions}

View File

@@ -6,16 +6,14 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <fairmq/Device.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Unique.h>
#include <fairmq/Device.h>
#include <string> #include <string>
#include <thread> #include <thread>
#include <iostream>
namespace namespace
{ {
@@ -23,7 +21,6 @@ namespace
using namespace std; using namespace std;
using namespace fair::mq; using namespace fair::mq;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
class BadDevice : public Device class BadDevice : public Device
{ {
@@ -64,99 +61,104 @@ class BadDevice : public Device
Parts parts; Parts parts;
}; };
void RunErrorStateIn(const string& state, const string& control, const string& input = "") void RunErrorStateIn(string const& state, string const& control, string const& input = "")
{ {
size_t session{tools::UuidHash()}; RunOptions options;
options.control = control;
options.input = input;
auto const results = RunDevices({{"error_state_" + state + "_"}}, options);
execute_result result{"", 100}; EXPECT_TRUE(ExitedWith(results.at(0), 1, "going to change to Error state from " + state + "()"));
thread device_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id error_state_" << state << "_"
<< " --control " << control
<< " --session " << session
<< " --color false";
result = execute(cmd.str(), "[ErrorFound IN " + state + "]", input);
});
device_thread.join();
ASSERT_NE(string::npos, result.console_out.find("going to change to Error state from " + state + "()"));
exit(result.exit_code);
} }
TEST(ErrorState, static_InInit) TEST(ErrorState, static_InInit)
{ {
EXPECT_EXIT(RunErrorStateIn("Init", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Init", "static");
} }
TEST(ErrorState, static_InBind) TEST(ErrorState, static_InBind)
{ {
EXPECT_EXIT(RunErrorStateIn("Bind", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Bind", "static");
} }
TEST(ErrorState, static_InConnect) TEST(ErrorState, static_InConnect)
{ {
EXPECT_EXIT(RunErrorStateIn("Connect", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Connect", "static");
} }
TEST(ErrorState, static_InInitTask) TEST(ErrorState, static_InInitTask)
{ {
EXPECT_EXIT(RunErrorStateIn("InitTask", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("InitTask", "static");
} }
TEST(ErrorState, static_InPreRun) TEST(ErrorState, static_InPreRun)
{ {
EXPECT_EXIT(RunErrorStateIn("PreRun", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("PreRun", "static");
} }
TEST(ErrorState, static_InRun) TEST(ErrorState, static_InRun)
{ {
EXPECT_EXIT(RunErrorStateIn("Run", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Run", "static");
} }
TEST(ErrorState, static_InPostRun) TEST(ErrorState, static_InPostRun)
{ {
EXPECT_EXIT(RunErrorStateIn("PostRun", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("PostRun", "static");
} }
TEST(ErrorState, static_InResetTask) TEST(ErrorState, static_InResetTask)
{ {
EXPECT_EXIT(RunErrorStateIn("ResetTask", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("ResetTask", "static");
} }
TEST(ErrorState, static_InReset) TEST(ErrorState, static_InReset)
{ {
EXPECT_EXIT(RunErrorStateIn("Reset", "static"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Reset", "static");
} }
TEST(ErrorState, interactive_InInit) TEST(ErrorState, interactive_InInit)
{ {
EXPECT_EXIT(RunErrorStateIn("Init", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Init", "interactive");
} }
TEST(ErrorState, interactive_InBind) TEST(ErrorState, interactive_InBind)
{ {
EXPECT_EXIT(RunErrorStateIn("Bind", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Bind", "interactive");
} }
TEST(ErrorState, interactive_InConnect) TEST(ErrorState, interactive_InConnect)
{ {
EXPECT_EXIT(RunErrorStateIn("Connect", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Connect", "interactive");
} }
TEST(ErrorState, interactive_InInitTask) TEST(ErrorState, interactive_InInitTask)
{ {
EXPECT_EXIT(RunErrorStateIn("InitTask", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("InitTask", "interactive");
} }
TEST(ErrorState, interactive_InPreRun) TEST(ErrorState, interactive_InPreRun)
{ {
EXPECT_EXIT(RunErrorStateIn("PreRun", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("PreRun", "interactive");
} }
TEST(ErrorState, interactive_InRun) TEST(ErrorState, interactive_InRun)
{ {
EXPECT_EXIT(RunErrorStateIn("Run", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Run", "interactive");
} }
TEST(ErrorState, interactive_InPostRun) TEST(ErrorState, interactive_InPostRun)
{ {
EXPECT_EXIT(RunErrorStateIn("PostRun", "interactive"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("PostRun", "interactive");
} }
TEST(ErrorState, interactive_InResetTask) TEST(ErrorState, interactive_InResetTask)
{ {
EXPECT_EXIT(RunErrorStateIn("ResetTask", "interactive", "q"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("ResetTask", "interactive", "q");
} }
TEST(ErrorState, interactive_InReset) TEST(ErrorState, interactive_InReset)
{ {
EXPECT_EXIT(RunErrorStateIn("Reset", "interactive", "q"), ::testing::ExitedWithCode(1), ""); RunErrorStateIn("Reset", "interactive", "q");
} }
#ifdef FAIRMQ_DEBUG_MODE #ifdef FAIRMQ_DEBUG_MODE

View File

@@ -6,116 +6,116 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Unique.h>
#include <string> #include <string>
#include <thread>
#include <iostream>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
void RunExceptionIn(const string& state, const string& control, const string& input = "") void RunExceptionIn(string const& state, string const& control, string const& input = "")
{ {
size_t session{fair::mq::tools::UuidHash()}; RunOptions options;
options.control = control;
options.input = input;
auto const results = RunDevices({{"exceptions_" + state + "_"}}, options);
execute_result result{"", 100}; EXPECT_TRUE(ExitedWith(results.at(0), 1, "exception in " + state + "()"));
thread device_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id exceptions_" << state << "_"
<< " --control " << control
<< " --session " << session
<< " --color false";
result = execute(cmd.str(), "[EXCEPTION IN " + state + "]", input);
});
device_thread.join();
ASSERT_NE(string::npos, result.console_out.find("exception in " + state + "()"));
exit(result.exit_code);
} }
TEST(Exceptions, static_InInit) TEST(Exceptions, static_InInit)
{ {
EXPECT_EXIT(RunExceptionIn("Init", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Init", "static");
} }
TEST(Exceptions, static_InBind) TEST(Exceptions, static_InBind)
{ {
EXPECT_EXIT(RunExceptionIn("Bind", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Bind", "static");
} }
TEST(Exceptions, static_InConnect) TEST(Exceptions, static_InConnect)
{ {
EXPECT_EXIT(RunExceptionIn("Connect", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Connect", "static");
} }
TEST(Exceptions, static_InInitTask) TEST(Exceptions, static_InInitTask)
{ {
EXPECT_EXIT(RunExceptionIn("InitTask", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("InitTask", "static");
} }
TEST(Exceptions, static_InPreRun) TEST(Exceptions, static_InPreRun)
{ {
EXPECT_EXIT(RunExceptionIn("PreRun", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("PreRun", "static");
} }
TEST(Exceptions, static_InRun) TEST(Exceptions, static_InRun)
{ {
EXPECT_EXIT(RunExceptionIn("Run", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Run", "static");
} }
TEST(Exceptions, static_InPostRun) TEST(Exceptions, static_InPostRun)
{ {
EXPECT_EXIT(RunExceptionIn("PostRun", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("PostRun", "static");
} }
TEST(Exceptions, static_InResetTask) TEST(Exceptions, static_InResetTask)
{ {
EXPECT_EXIT(RunExceptionIn("ResetTask", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("ResetTask", "static");
} }
TEST(Exceptions, static_InReset) TEST(Exceptions, static_InReset)
{ {
EXPECT_EXIT(RunExceptionIn("Reset", "static"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Reset", "static");
} }
TEST(Exceptions, interactive_InInit) TEST(Exceptions, interactive_InInit)
{ {
EXPECT_EXIT(RunExceptionIn("Init", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Init", "interactive");
} }
TEST(Exceptions, interactive_InBind) TEST(Exceptions, interactive_InBind)
{ {
EXPECT_EXIT(RunExceptionIn("Bind", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Bind", "interactive");
} }
TEST(Exceptions, interactive_InConnect) TEST(Exceptions, interactive_InConnect)
{ {
EXPECT_EXIT(RunExceptionIn("Connect", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Connect", "interactive");
} }
TEST(Exceptions, interactive_InInitTask) TEST(Exceptions, interactive_InInitTask)
{ {
EXPECT_EXIT(RunExceptionIn("InitTask", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("InitTask", "interactive");
} }
TEST(Exceptions, interactive_InPreRun) TEST(Exceptions, interactive_InPreRun)
{ {
EXPECT_EXIT(RunExceptionIn("PreRun", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("PreRun", "interactive");
} }
TEST(Exceptions, interactive_InRun) TEST(Exceptions, interactive_InRun)
{ {
EXPECT_EXIT(RunExceptionIn("Run", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Run", "interactive");
} }
TEST(Exceptions, interactive_InPostRun) TEST(Exceptions, interactive_InPostRun)
{ {
EXPECT_EXIT(RunExceptionIn("PostRun", "interactive"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("PostRun", "interactive");
} }
TEST(Exceptions, interactive_InResetTask) TEST(Exceptions, interactive_InResetTask)
{ {
EXPECT_EXIT(RunExceptionIn("ResetTask", "interactive", "q"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("ResetTask", "interactive", "q");
} }
TEST(Exceptions, interactive_InReset) TEST(Exceptions, interactive_InReset)
{ {
EXPECT_EXIT(RunExceptionIn("Reset", "interactive", "q"), ::testing::ExitedWithCode(1), ""); RunExceptionIn("Reset", "interactive", "q");
} }
} // namespace } // namespace

View File

@@ -6,116 +6,116 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <string> #include <string>
#include <thread>
#include <iostream>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
void RunSignalIn(const string& state, const string& control, const string& input = "") void RunSignalIn(string const& state, string const& control, string const& input = "")
{ {
size_t session{fair::mq::tools::UuidHash()}; RunOptions options;
options.control = control;
options.input = input;
auto const results = RunDevices({{"signals_" + state + "_"}}, options);
execute_result result{"", 100}; EXPECT_TRUE(ExitedWith(results.at(0), 0, "raising SIGINT from " + state + "()"));
thread device_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id signals_" << state << "_"
<< " --control " << control
<< " --session " << session
<< " --color false";
result = execute(cmd.str(), "[SIGINT IN " + state + "]", input);
});
device_thread.join();
ASSERT_NE(string::npos, result.console_out.find("raising SIGINT from " + state + "()"));
exit(result.exit_code);
} }
TEST(Signal_SIGINT, static_InInit) TEST(Signal_SIGINT, static_InInit)
{ {
EXPECT_EXIT(RunSignalIn("Init", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Init", "static");
} }
TEST(Signal_SIGINT, static_InBind) TEST(Signal_SIGINT, static_InBind)
{ {
EXPECT_EXIT(RunSignalIn("Bind", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Bind", "static");
} }
TEST(Signal_SIGINT, static_InConnect) TEST(Signal_SIGINT, static_InConnect)
{ {
EXPECT_EXIT(RunSignalIn("Connect", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Connect", "static");
} }
TEST(Signal_SIGINT, static_InInitTask) TEST(Signal_SIGINT, static_InInitTask)
{ {
EXPECT_EXIT(RunSignalIn("InitTask", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("InitTask", "static");
} }
TEST(Signal_SIGINT, static_InPreRun) TEST(Signal_SIGINT, static_InPreRun)
{ {
EXPECT_EXIT(RunSignalIn("PreRun", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("PreRun", "static");
} }
TEST(Signal_SIGINT, static_InRun) TEST(Signal_SIGINT, static_InRun)
{ {
EXPECT_EXIT(RunSignalIn("Run", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Run", "static");
} }
TEST(Signal_SIGINT, static_InPostRun) TEST(Signal_SIGINT, static_InPostRun)
{ {
EXPECT_EXIT(RunSignalIn("PostRun", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("PostRun", "static");
} }
TEST(Signal_SIGINT, static_InResetTask) TEST(Signal_SIGINT, static_InResetTask)
{ {
EXPECT_EXIT(RunSignalIn("ResetTask", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("ResetTask", "static");
} }
TEST(Signal_SIGINT, static_InReset) TEST(Signal_SIGINT, static_InReset)
{ {
EXPECT_EXIT(RunSignalIn("Reset", "static"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Reset", "static");
} }
TEST(Signal_SIGINT, interactive_InInit) TEST(Signal_SIGINT, interactive_InInit)
{ {
EXPECT_EXIT(RunSignalIn("Init", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Init", "interactive");
} }
TEST(Signal_SIGINT, interactive_InBind) TEST(Signal_SIGINT, interactive_InBind)
{ {
EXPECT_EXIT(RunSignalIn("Bind", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Bind", "interactive");
} }
TEST(Signal_SIGINT, interactive_InConnect) TEST(Signal_SIGINT, interactive_InConnect)
{ {
EXPECT_EXIT(RunSignalIn("Connect", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Connect", "interactive");
} }
TEST(Signal_SIGINT, interactive_InInitTask) TEST(Signal_SIGINT, interactive_InInitTask)
{ {
EXPECT_EXIT(RunSignalIn("InitTask", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("InitTask", "interactive");
} }
TEST(Signal_SIGINT, interactive_InPreRun) TEST(Signal_SIGINT, interactive_InPreRun)
{ {
EXPECT_EXIT(RunSignalIn("PreRun", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("PreRun", "interactive");
} }
TEST(Signal_SIGINT, interactive_InRun) TEST(Signal_SIGINT, interactive_InRun)
{ {
EXPECT_EXIT(RunSignalIn("Run", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Run", "interactive");
} }
TEST(Signal_SIGINT, interactive_InPostRun) TEST(Signal_SIGINT, interactive_InPostRun)
{ {
EXPECT_EXIT(RunSignalIn("PostRun", "interactive"), ::testing::ExitedWithCode(0), ""); RunSignalIn("PostRun", "interactive");
} }
TEST(Signal_SIGINT, interactive_InResetTask) TEST(Signal_SIGINT, interactive_InResetTask)
{ {
EXPECT_EXIT(RunSignalIn("ResetTask", "interactive", "q"), ::testing::ExitedWithCode(0), ""); RunSignalIn("ResetTask", "interactive", "q");
} }
TEST(Signal_SIGINT, interactive_InReset) TEST(Signal_SIGINT, interactive_InReset)
{ {
EXPECT_EXIT(RunSignalIn("Reset", "interactive", "q"), ::testing::ExitedWithCode(0), ""); RunSignalIn("Reset", "interactive", "q");
} }
} // namespace } // namespace

View File

@@ -6,68 +6,58 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include <helper/Devices.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <fairmq/tools/Unique.h> #include <csignal>
#include <fairmq/tools/Process.h>
#include <string> #include <string>
#include <thread>
#include <sstream>
namespace namespace
{ {
using namespace std; using namespace std;
using namespace fair::mq::test; using namespace fair::mq::test;
using namespace fair::mq::tools;
void RunWaitFor(const string& state, const string& control) void RunWaitFor(string const& state, string const& control)
{ {
execute_result result; RunOptions options;
thread device_thread([&] { options.control = control;
stringstream cmd; options.signal = SIGINT;
cmd << runTestDevice options.extraArgs = "--severity debug";
<< " --id waitfor_" << state auto const results = RunDevices({{"waitfor_" + state + "_"}}, options);
<< " --control " << control
<< " --session " << UuidHash()
<< " --severity debug"
<< " --color false";
result = execute(cmd.str(), "[WaitFor]", "", SIGINT);
});
device_thread.join(); EXPECT_TRUE(ExitedWith(results.at(0), 0, "Sleeping Done. Interrupted."));
ASSERT_NE(string::npos, result.console_out.find("Sleeping Done. Interrupted."));
exit(result.exit_code);
} }
TEST(WaitFor, static_InPreRun) TEST(WaitFor, static_InPreRun)
{ {
EXPECT_EXIT(RunWaitFor("PreRun", "static"), ::testing::ExitedWithCode(0), ""); RunWaitFor("PreRun", "static");
} }
TEST(WaitFor, static_InRun) TEST(WaitFor, static_InRun)
{ {
EXPECT_EXIT(RunWaitFor("Run", "static"), ::testing::ExitedWithCode(0), ""); RunWaitFor("Run", "static");
} }
TEST(WaitFor, static_InPostRun) TEST(WaitFor, static_InPostRun)
{ {
EXPECT_EXIT(RunWaitFor("PostRun", "static"), ::testing::ExitedWithCode(0), ""); RunWaitFor("PostRun", "static");
} }
TEST(WaitFor, interactive_InPreRun) TEST(WaitFor, interactive_InPreRun)
{ {
EXPECT_EXIT(RunWaitFor("PreRun", "interactive"), ::testing::ExitedWithCode(0), ""); RunWaitFor("PreRun", "interactive");
} }
TEST(WaitFor, interactive_InRun) TEST(WaitFor, interactive_InRun)
{ {
EXPECT_EXIT(RunWaitFor("Run", "interactive"), ::testing::ExitedWithCode(0), ""); RunWaitFor("Run", "interactive");
} }
TEST(WaitFor, interactive_InPostRun) TEST(WaitFor, interactive_InPostRun)
{ {
EXPECT_EXIT(RunWaitFor("PostRun", "interactive"), ::testing::ExitedWithCode(0), ""); RunWaitFor("PostRun", "interactive");
} }
} // namespace } // namespace

View File

@@ -1,46 +0,0 @@
/********************************************************************************
* Copyright (C) 2018-2023 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_ERROR_STATE_H
#define FAIR_MQ_TEST_ERROR_STATE_H
#include <fairmq/Device.h>
#include <fairmq/Tools.h>
#include <fairlogger/Logger.h>
#include <string_view>
namespace fair::mq::test
{
class ErrorState : public Device
{
auto ErrorIfRequestedById(std::string_view state)
{
if (std::string::npos != GetId().find(tools::ToString("_", state, "_"))) {
LOG(info) << "going to change to Error state from " << state << "()";
ChangeStateOrThrow(fair::mq::Transition::ErrorFound);
}
}
public:
void Init() override { ErrorIfRequestedById("Init"); }
void Bind() override { ErrorIfRequestedById("Bind"); }
void Connect() override { ErrorIfRequestedById("Connect"); }
void InitTask() override { ErrorIfRequestedById("InitTask"); }
void PreRun() override { ErrorIfRequestedById("PreRun"); }
void Run() override { ErrorIfRequestedById("Run"); }
void PostRun() override { ErrorIfRequestedById("PostRun"); }
void ResetTask() override { ErrorIfRequestedById("ResetTask"); }
void Reset() override { ErrorIfRequestedById("Reset"); }
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_ERROR_STATE_H */

View File

@@ -1,99 +0,0 @@
/********************************************************************************
* Copyright (C) 2018-2022 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_EXCEPTIONS_H
#define FAIR_MQ_TEST_EXCEPTIONS_H
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <iostream>
#include <stdexcept>
namespace fair::mq::test
{
class Exceptions : public Device
{
public:
auto Init() -> void override
{
std::string state("Init");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto Bind() -> void override
{
std::string state("Bind");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto Connect() -> void override
{
std::string state("Connect");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto InitTask() -> void override
{
std::string state("InitTask");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto PreRun() -> void override
{
std::string state("PreRun");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto Run() -> void override
{
std::string state("Run");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto PostRun() -> void override
{
std::string state("PostRun");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto ResetTask() -> void override
{
std::string state("ResetTask");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
auto Reset() -> void override
{
std::string state("Reset");
if (std::string::npos != GetId().find("_" + state + "_")) {
throw std::runtime_error("exception in " + state + "()");
}
}
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_EXCEPTIONS_H */

View File

@@ -1,106 +0,0 @@
/********************************************************************************
* Copyright (C) 2018-2022 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_SIGNALS_H
#define FAIR_MQ_TEST_SIGNALS_H
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <iostream>
#include <csignal>
namespace fair::mq::test
{
class Signals : public Device
{
public:
void Init() override
{
std::string state("Init");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void Bind() override
{
std::string state("Bind");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void Connect() override
{
std::string state("Connect");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void InitTask() override
{
std::string state("InitTask");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void PreRun() override
{
std::string state("PreRun");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void Run() override
{
std::string state("Run");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void PostRun() override
{
std::string state("PostRun");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void ResetTask() override
{
std::string state("ResetTask");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
void Reset() override
{
std::string state("Reset");
if (std::string::npos != GetId().find("_" + state + "_")) {
LOG(info) << "raising SIGINT from " << state << "()";
raise(SIGINT);
}
}
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_SIGNALS_H */

View File

@@ -0,0 +1,72 @@
/********************************************************************************
* 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_STATEACTION_H
#define FAIR_MQ_TEST_STATEACTION_H
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <chrono>
#include <csignal>
#include <stdexcept>
#include <string>
#include <string_view>
namespace fair::mq::test
{
/// Does one action in one state handler. The device id selects both:
/// "<action>_<State>_", e.g. "exceptions_InitTask_". Actions:
/// - exceptions: throw an exception
/// - error_state: change to the Error state
/// - signals: raise SIGINT
/// - waitfor: wait 60 s in WaitFor(); the test interrupts the wait
class StateAction : public Device
{
public:
void Init() override { ActIfRequested("Init"); }
void Bind() override { ActIfRequested("Bind"); }
void Connect() override { ActIfRequested("Connect"); }
void InitTask() override { ActIfRequested("InitTask"); }
void PreRun() override { ActIfRequested("PreRun"); }
void Run() override { ActIfRequested("Run"); }
void PostRun() override { ActIfRequested("PostRun"); }
void ResetTask() override { ActIfRequested("ResetTask"); }
void Reset() override { ActIfRequested("Reset"); }
private:
void ActIfRequested(std::string_view state)
{
auto const id = GetId();
if (std::string::npos == id.find(std::string("_").append(state).append("_"))) {
return;
}
if (id.rfind("exceptions_", 0) == 0) {
throw std::runtime_error(std::string("exception in ").append(state).append("()"));
} else if (id.rfind("error_state_", 0) == 0) {
LOG(info) << "going to change to Error state from " << state << "()";
ChangeStateOrThrow(Transition::ErrorFound);
} else if (id.rfind("signals_", 0) == 0) {
LOG(info) << "raising SIGINT from " << state << "()";
std::raise(SIGINT);
} else if (id.rfind("waitfor_", 0) == 0) {
LOG(info) << "Going to sleep via WaitFor() in " << state << "...";
bool const done = WaitFor(std::chrono::seconds(60));
LOG(info) << (done ? "Sleeping Done. Not interrupted." : "Sleeping Done. Interrupted.");
} else {
throw std::runtime_error("unknown action in device id '" + id + "'");
}
}
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_STATEACTION_H */

View File

@@ -1,56 +0,0 @@
/********************************************************************************
* Copyright (C) 2015-2022 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_WAITFOR_H
#define FAIR_MQ_TEST_WAITFOR_H
#include <fairmq/Device.h>
#include <fairlogger/Logger.h>
#include <iostream>
namespace fair::mq::test
{
class TestWaitFor : public Device
{
public:
void PreRun() override
{
std::string state("PreRun");
if (std::string::npos != GetId().find("_" + state)) {
LOG(info) << "Going to sleep via WaitFor() in " << state << "...";
bool result = WaitFor(std::chrono::seconds(60));
LOG(info) << (result == true ? "Sleeping Done. Not interrupted." : "Sleeping Done. Interrupted.");
}
}
void Run() override
{
std::string state("Run");
if (std::string::npos != GetId().find("_" + state)) {
LOG(info) << "Going to sleep via WaitFor() in " << state << "...";
bool result = WaitFor(std::chrono::seconds(60));
LOG(info) << (result == true ? "Sleeping Done. Not interrupted." : "Sleeping Done. Interrupted.");
}
}
void PostRun() override
{
std::string state("PostRun");
if (std::string::npos != GetId().find("_" + state)) {
LOG(info) << "Going to sleep via WaitFor() in " << state << "...";
bool result = WaitFor(std::chrono::seconds(60));
LOG(info) << (result == true ? "Sleeping Done. Not interrupted." : "Sleeping Done. Interrupted.");
}
}
};
} // namespace fair::mq::test
#endif /* FAIR_MQ_TEST_WAITFOR_H */

View File

@@ -17,11 +17,8 @@
#include "devices/TestRep.h" #include "devices/TestRep.h"
#include "devices/TestReq.h" #include "devices/TestReq.h"
#include "devices/TestSub.h" #include "devices/TestSub.h"
#include "devices/TestStateAction.h"
#include "devices/TestTransferTimeout.h" #include "devices/TestTransferTimeout.h"
#include "devices/TestWaitFor.h"
#include "devices/TestExceptions.h"
#include "devices/TestErrorState.h"
#include "devices/TestSignals.h"
#include <fairmq/runDevice.h> #include <fairmq/runDevice.h>
@@ -70,14 +67,8 @@ auto getDevice(fair::mq::ProgOptions& config) -> std::unique_ptr<fair::mq::Devic
return std::make_unique<PairLeft>(); return std::make_unique<PairLeft>();
} else if (0 == id.find("pairright_")) { } else if (0 == id.find("pairright_")) {
return std::make_unique<PairRight>(); return std::make_unique<PairRight>();
} else if (0 == id.find("waitfor_")) { } else if (0 == id.find("exceptions_") || 0 == id.find("error_state_") || 0 == id.find("signals_") || 0 == id.find("waitfor_")) {
return std::make_unique<TestWaitFor>(); return std::make_unique<StateAction>();
} else if (0 == id.find("exceptions_")) {
return std::make_unique<Exceptions>();
} else if (0 == id.find("error_state_")) {
return std::make_unique<ErrorState>();
} else if (0 == id.find("signals_")) {
return std::make_unique<Signals>();
} else { } else {
cerr << "Don't know id '" << id << "'" << endl; cerr << "Don't know id '" << id << "'" << endl;
return nullptr; return nullptr;