mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
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:
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
72
test/helper/devices/TestStateAction.h
Normal file
72
test/helper/devices/TestStateAction.h
Normal 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 */
|
||||
@@ -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 */
|
||||
@@ -17,11 +17,8 @@
|
||||
#include "devices/TestRep.h"
|
||||
#include "devices/TestReq.h"
|
||||
#include "devices/TestSub.h"
|
||||
#include "devices/TestStateAction.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>
|
||||
|
||||
@@ -70,14 +67,8 @@ auto getDevice(fair::mq::ProgOptions& config) -> std::unique_ptr<fair::mq::Devic
|
||||
return std::make_unique<PairLeft>();
|
||||
} else if (0 == id.find("pairright_")) {
|
||||
return std::make_unique<PairRight>();
|
||||
} else if (0 == id.find("waitfor_")) {
|
||||
return std::make_unique<TestWaitFor>();
|
||||
} 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 if (0 == id.find("exceptions_") || 0 == id.find("error_state_") || 0 == id.find("signals_") || 0 == id.find("waitfor_")) {
|
||||
return std::make_unique<StateAction>();
|
||||
} else {
|
||||
cerr << "Don't know id '" << id << "'" << endl;
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user