mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
test: parameterize the device state tests by state and control
- Add test::StateParam (state, control mode, stdin input) and WithControls() for INSTANTIATE_TEST_SUITE_P() - Turn the 60 TEST() copies in the Exceptions, ErrorState, Signals and WaitFor files into one TEST_P() each - The test names change, e.g. Exceptions.interactive_InRun is now Exceptions.Throw/interactive_Run, Signal_SIGINT.* is Signals.RaiseSIGINT/* and ErrorState.OrphanMessages is OrphanMessages.shmem Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <helper/Devices.h>
|
||||
#include <helper/StateParam.h>
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
@@ -61,108 +62,23 @@ class BadDevice : public Device
|
||||
Parts parts;
|
||||
};
|
||||
|
||||
void RunErrorStateIn(string const& state, string const& control, string const& input = "")
|
||||
using ErrorState = StateTest;
|
||||
|
||||
TEST_P(ErrorState, ChangeState)
|
||||
{
|
||||
auto const& state = GetParam().state;
|
||||
RunOptions options;
|
||||
options.control = control;
|
||||
options.input = input;
|
||||
options.control = GetParam().control;
|
||||
options.input = GetParam().Input();
|
||||
auto const results = RunDevices({{"error_state_" + state + "_"}}, options);
|
||||
|
||||
EXPECT_TRUE(ExitedWith(results.at(0), 1, "going to change to Error state from " + state + "()"));
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InInit)
|
||||
{
|
||||
RunErrorStateIn("Init", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InBind)
|
||||
{
|
||||
RunErrorStateIn("Bind", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InConnect)
|
||||
{
|
||||
RunErrorStateIn("Connect", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InInitTask)
|
||||
{
|
||||
RunErrorStateIn("InitTask", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InPreRun)
|
||||
{
|
||||
RunErrorStateIn("PreRun", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InRun)
|
||||
{
|
||||
RunErrorStateIn("Run", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InPostRun)
|
||||
{
|
||||
RunErrorStateIn("PostRun", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InResetTask)
|
||||
{
|
||||
RunErrorStateIn("ResetTask", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, static_InReset)
|
||||
{
|
||||
RunErrorStateIn("Reset", "static");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InInit)
|
||||
{
|
||||
RunErrorStateIn("Init", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InBind)
|
||||
{
|
||||
RunErrorStateIn("Bind", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InConnect)
|
||||
{
|
||||
RunErrorStateIn("Connect", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InInitTask)
|
||||
{
|
||||
RunErrorStateIn("InitTask", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InPreRun)
|
||||
{
|
||||
RunErrorStateIn("PreRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InRun)
|
||||
{
|
||||
RunErrorStateIn("Run", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InPostRun)
|
||||
{
|
||||
RunErrorStateIn("PostRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InResetTask)
|
||||
{
|
||||
RunErrorStateIn("ResetTask", "interactive", "q");
|
||||
}
|
||||
|
||||
TEST(ErrorState, interactive_InReset)
|
||||
{
|
||||
RunErrorStateIn("Reset", "interactive", "q");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(, ErrorState, WithControls(HookStates()), StateParamName());
|
||||
|
||||
#ifdef FAIRMQ_DEBUG_MODE
|
||||
TEST(ErrorState, OrphanMessages)
|
||||
TEST(OrphanMessages, shmem)
|
||||
{
|
||||
BadDevice badDevice;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <helper/Devices.h>
|
||||
#include <helper/StateParam.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -18,104 +19,19 @@ namespace
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
|
||||
void RunExceptionIn(string const& state, string const& control, string const& input = "")
|
||||
using Exceptions = StateTest;
|
||||
|
||||
TEST_P(Exceptions, Throw)
|
||||
{
|
||||
auto const& state = GetParam().state;
|
||||
RunOptions options;
|
||||
options.control = control;
|
||||
options.input = input;
|
||||
options.control = GetParam().control;
|
||||
options.input = GetParam().Input();
|
||||
auto const results = RunDevices({{"exceptions_" + state + "_"}}, options);
|
||||
|
||||
EXPECT_TRUE(ExitedWith(results.at(0), 1, "exception in " + state + "()"));
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InInit)
|
||||
{
|
||||
RunExceptionIn("Init", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InBind)
|
||||
{
|
||||
RunExceptionIn("Bind", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InConnect)
|
||||
{
|
||||
RunExceptionIn("Connect", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InInitTask)
|
||||
{
|
||||
RunExceptionIn("InitTask", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InPreRun)
|
||||
{
|
||||
RunExceptionIn("PreRun", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InRun)
|
||||
{
|
||||
RunExceptionIn("Run", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InPostRun)
|
||||
{
|
||||
RunExceptionIn("PostRun", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InResetTask)
|
||||
{
|
||||
RunExceptionIn("ResetTask", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, static_InReset)
|
||||
{
|
||||
RunExceptionIn("Reset", "static");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InInit)
|
||||
{
|
||||
RunExceptionIn("Init", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InBind)
|
||||
{
|
||||
RunExceptionIn("Bind", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InConnect)
|
||||
{
|
||||
RunExceptionIn("Connect", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InInitTask)
|
||||
{
|
||||
RunExceptionIn("InitTask", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InPreRun)
|
||||
{
|
||||
RunExceptionIn("PreRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InRun)
|
||||
{
|
||||
RunExceptionIn("Run", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InPostRun)
|
||||
{
|
||||
RunExceptionIn("PostRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InResetTask)
|
||||
{
|
||||
RunExceptionIn("ResetTask", "interactive", "q");
|
||||
}
|
||||
|
||||
TEST(Exceptions, interactive_InReset)
|
||||
{
|
||||
RunExceptionIn("Reset", "interactive", "q");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(, Exceptions, WithControls(HookStates()), StateParamName());
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <helper/Devices.h>
|
||||
#include <helper/StateParam.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -18,104 +19,19 @@ namespace
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
|
||||
void RunSignalIn(string const& state, string const& control, string const& input = "")
|
||||
using Signals = StateTest;
|
||||
|
||||
TEST_P(Signals, RaiseSIGINT)
|
||||
{
|
||||
auto const& state = GetParam().state;
|
||||
RunOptions options;
|
||||
options.control = control;
|
||||
options.input = input;
|
||||
options.control = GetParam().control;
|
||||
options.input = GetParam().Input();
|
||||
auto const results = RunDevices({{"signals_" + state + "_"}}, options);
|
||||
|
||||
EXPECT_TRUE(ExitedWith(results.at(0), 0, "raising SIGINT from " + state + "()"));
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InInit)
|
||||
{
|
||||
RunSignalIn("Init", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InBind)
|
||||
{
|
||||
RunSignalIn("Bind", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InConnect)
|
||||
{
|
||||
RunSignalIn("Connect", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InInitTask)
|
||||
{
|
||||
RunSignalIn("InitTask", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InPreRun)
|
||||
{
|
||||
RunSignalIn("PreRun", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InRun)
|
||||
{
|
||||
RunSignalIn("Run", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InPostRun)
|
||||
{
|
||||
RunSignalIn("PostRun", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InResetTask)
|
||||
{
|
||||
RunSignalIn("ResetTask", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, static_InReset)
|
||||
{
|
||||
RunSignalIn("Reset", "static");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InInit)
|
||||
{
|
||||
RunSignalIn("Init", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InBind)
|
||||
{
|
||||
RunSignalIn("Bind", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InConnect)
|
||||
{
|
||||
RunSignalIn("Connect", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InInitTask)
|
||||
{
|
||||
RunSignalIn("InitTask", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InPreRun)
|
||||
{
|
||||
RunSignalIn("PreRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InRun)
|
||||
{
|
||||
RunSignalIn("Run", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InPostRun)
|
||||
{
|
||||
RunSignalIn("PostRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InResetTask)
|
||||
{
|
||||
RunSignalIn("ResetTask", "interactive", "q");
|
||||
}
|
||||
|
||||
TEST(Signal_SIGINT, interactive_InReset)
|
||||
{
|
||||
RunSignalIn("Reset", "interactive", "q");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(, Signals, WithControls(HookStates()), StateParamName());
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <helper/Devices.h>
|
||||
#include <helper/StateParam.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -19,45 +20,20 @@ namespace
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
|
||||
void RunWaitFor(string const& state, string const& control)
|
||||
using WaitFor = StateTest;
|
||||
|
||||
TEST_P(WaitFor, Interrupt)
|
||||
{
|
||||
RunOptions options;
|
||||
options.control = control;
|
||||
options.control = GetParam().control;
|
||||
options.signal = SIGINT;
|
||||
options.extraArgs = "--severity debug";
|
||||
auto const results = RunDevices({{"waitfor_" + state + "_"}}, options);
|
||||
auto const results = RunDevices({{"waitfor_" + GetParam().state + "_"}}, options);
|
||||
|
||||
EXPECT_TRUE(ExitedWith(results.at(0), 0, "Sleeping Done. Interrupted."));
|
||||
}
|
||||
|
||||
TEST(WaitFor, static_InPreRun)
|
||||
{
|
||||
RunWaitFor("PreRun", "static");
|
||||
}
|
||||
|
||||
TEST(WaitFor, static_InRun)
|
||||
{
|
||||
RunWaitFor("Run", "static");
|
||||
}
|
||||
|
||||
TEST(WaitFor, static_InPostRun)
|
||||
{
|
||||
RunWaitFor("PostRun", "static");
|
||||
}
|
||||
|
||||
TEST(WaitFor, interactive_InPreRun)
|
||||
{
|
||||
RunWaitFor("PreRun", "interactive");
|
||||
}
|
||||
|
||||
TEST(WaitFor, interactive_InRun)
|
||||
{
|
||||
RunWaitFor("Run", "interactive");
|
||||
}
|
||||
|
||||
TEST(WaitFor, interactive_InPostRun)
|
||||
{
|
||||
RunWaitFor("PostRun", "interactive");
|
||||
}
|
||||
// The device waits (and SIGINT interrupts the wait) only in these states.
|
||||
INSTANTIATE_TEST_SUITE_P(, WaitFor, WithControls({"PreRun", "Run", "PostRun"}), StateParamName());
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user