mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Move test directory one up
This commit is contained in:
171
test/CMakeLists.txt
Normal file
171
test/CMakeLists.txt
Normal file
@@ -0,0 +1,171 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2014 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" #
|
||||
################################################################################
|
||||
|
||||
include(GTestHelper)
|
||||
|
||||
#############################
|
||||
# FairMQ Testsuites/helpers #
|
||||
#############################
|
||||
|
||||
add_testhelper(runTestDevice
|
||||
SOURCES
|
||||
helper/runTestDevice.cxx
|
||||
helper/devices/TestPairLeft.cxx
|
||||
helper/devices/TestPairRight.cxx
|
||||
helper/devices/TestPollIn.cxx
|
||||
helper/devices/TestPollOut.cxx
|
||||
helper/devices/TestPub.cxx
|
||||
helper/devices/TestPull.cxx
|
||||
helper/devices/TestPush.cxx
|
||||
helper/devices/TestRep.cxx
|
||||
helper/devices/TestReq.cxx
|
||||
helper/devices/TestSub.cxx
|
||||
helper/devices/TestTransferTimeout.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
)
|
||||
|
||||
|
||||
set(MQ_CONFIG "${CMAKE_BINARY_DIR}/bin/testsuite_FairMQ.IOPatterns_config.json")
|
||||
set(RUN_TEST_DEVICE "${CMAKE_BINARY_DIR}/bin/testhelper_runTestDevice")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protocols/config.json.in ${MQ_CONFIG})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protocols/runner.cxx.in ${CMAKE_CURRENT_BINARY_DIR}/protocols/runner.cxx)
|
||||
|
||||
add_testsuite(FairMQ.Protocols
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/protocols/runner.cxx
|
||||
protocols/_pair.cxx
|
||||
protocols/_poller.cxx
|
||||
protocols/_pub_sub.cxx
|
||||
protocols/_push_pull.cxx
|
||||
protocols/_req_rep.cxx
|
||||
protocols/_transfer_timeout.cxx
|
||||
protocols/_push_pull_multipart.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
DEPENDS testhelper_runTestDevice
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/protocols
|
||||
TIMEOUT 30
|
||||
RUN_SERIAL ON
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.Parts
|
||||
SOURCES
|
||||
parts/runner.cxx
|
||||
parts/_iterator_interface.cxx
|
||||
|
||||
LINKS FairMQ ZeroMQ
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/parts
|
||||
TIMEOUT 5
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.MessageResize
|
||||
SOURCES
|
||||
message_resize/runner.cxx
|
||||
message_resize/_message_resize.cxx
|
||||
|
||||
LINKS FairMQ ZeroMQ
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/message_resize
|
||||
TIMEOUT 5
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.Device
|
||||
SOURCES
|
||||
device/TestSender.h
|
||||
device/TestReceiver.h
|
||||
device/TestVersion.h
|
||||
device/runner.cxx
|
||||
device/_multiple_devices.cxx
|
||||
device/_device_version.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/device
|
||||
TIMEOUT 5
|
||||
RUN_SERIAL ON
|
||||
)
|
||||
|
||||
set(VERSION_MAJOR 1)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/helper/plugins/dummy.h.in ${CMAKE_CURRENT_BINARY_DIR}/helper/plugins/dummy.h)
|
||||
add_testlib(FairMQPlugin_test_dummy
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/helper/plugins/dummy.h
|
||||
helper/plugins/dummy.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/helper/plugins
|
||||
HIDDEN
|
||||
VERSION ${VERSION}
|
||||
)
|
||||
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 2)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/helper/plugins/dummy2.h.in ${CMAKE_CURRENT_BINARY_DIR}/helper/plugins/dummy2.h)
|
||||
add_testlib(FairMQPlugin_test_dummy2
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/helper/plugins/dummy2.h
|
||||
helper/plugins/dummy2.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/helper/plugins
|
||||
HIDDEN
|
||||
VERSION ${VERSION}
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.Plugins
|
||||
SOURCES
|
||||
plugins/runner.cxx
|
||||
plugins/_plugin.cxx
|
||||
plugins/_plugin_manager.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
DEPENDS FairMQPlugin_test_dummy FairMQPlugin_test_dummy2
|
||||
TIMEOUT 10
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.PluginsPrelinked
|
||||
SOURCES
|
||||
plugins/runner.cxx
|
||||
plugins/_plugin_manager_prelink.cxx
|
||||
|
||||
LINKS FairMQ FairMQPlugin_test_dummy FairMQPlugin_test_dummy2
|
||||
TIMEOUT 10
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.PluginServices
|
||||
SOURCES
|
||||
plugin_services/runner.cxx
|
||||
plugin_services/_config.cxx
|
||||
plugin_services/_control.cxx
|
||||
plugin_services/Fixture.h
|
||||
|
||||
LINKS FairMQ
|
||||
TIMEOUT 10
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.EventManager
|
||||
SOURCES
|
||||
event_manager/runner.cxx
|
||||
event_manager/_event_manager.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
TIMEOUT 10
|
||||
)
|
||||
|
||||
add_testsuite(FairMQ.StateMachine
|
||||
SOURCES
|
||||
state_machine/runner.cxx
|
||||
state_machine/_state_machine.cxx
|
||||
|
||||
LINKS FairMQ
|
||||
TIMEOUT 10
|
||||
)
|
62
test/device/TestReceiver.h
Normal file
62
test/device/TestReceiver.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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_TESTRECEIVER_H
|
||||
#define FAIR_MQ_TEST_TESTRECEIVER_H
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Receiver : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
Receiver(const std::string& channelName)
|
||||
: fChannelName(channelName)
|
||||
{}
|
||||
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg = FairMQMessagePtr{NewMessage()};
|
||||
if (Receive(msg, fChannelName) >= 0)
|
||||
{
|
||||
LOG(info) << "received empty message";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "fair::mq::test::Receiver::Run(): Receive(msg, fChannelName) < 0";
|
||||
}
|
||||
};
|
||||
|
||||
std::string fChannelName;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif // FAIR_MQ_TEST_TESTRECEIVER_H
|
62
test/device/TestSender.h
Normal file
62
test/device/TestSender.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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_TESTSENDER_H
|
||||
#define FAIR_MQ_TEST_TESTSENDER_H
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Sender : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
Sender(const std::string& channelName)
|
||||
: fChannelName(channelName)
|
||||
{}
|
||||
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg = FairMQMessagePtr{NewMessage()};
|
||||
if (Send(msg, fChannelName) >= 0)
|
||||
{
|
||||
LOG(info) << "sent empty message";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "fair::mq::test::Sender::Run(): Send(msg, fChannelName) < 0";
|
||||
}
|
||||
};
|
||||
|
||||
std::string fChannelName;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif // FAIR_MQ_TEST_TESTSENDER_H
|
30
test/device/TestVersion.h
Normal file
30
test/device/TestVersion.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class TestVersion : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
TestVersion(fair::mq::tools::Version version)
|
||||
: FairMQDevice(version)
|
||||
{}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
46
test/device/_device_version.cxx
Normal file
46
test/device/_device_version.cxx
Normal file
@@ -0,0 +1,46 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "TestVersion.h"
|
||||
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
|
||||
class DeviceVersion : public ::testing::Test {
|
||||
public:
|
||||
DeviceVersion()
|
||||
{}
|
||||
|
||||
fair::mq::tools::Version TestDeviceVersion()
|
||||
{
|
||||
fair::mq::test::TestVersion versionDevice({1, 2, 3});
|
||||
versionDevice.ChangeState("END");
|
||||
|
||||
return versionDevice.GetVersion();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DeviceVersion, getter)
|
||||
{
|
||||
struct fair::mq::tools::Version v{1, 2, 3};
|
||||
fair::mq::tools::Version version = TestDeviceVersion();
|
||||
|
||||
EXPECT_EQ(v, version);
|
||||
}
|
||||
|
||||
} // namespace
|
96
test/device/_multiple_devices.cxx
Normal file
96
test/device/_multiple_devices.cxx
Normal file
@@ -0,0 +1,96 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "TestSender.h"
|
||||
#include "TestReceiver.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <future> // std::async, std::future
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MultipleDevices : public ::testing::Test {
|
||||
public:
|
||||
MultipleDevices()
|
||||
{}
|
||||
|
||||
bool TestFirst()
|
||||
{
|
||||
fair::mq::test::Sender sender("data");
|
||||
|
||||
sender.SetTransport("zeromq");
|
||||
|
||||
FairMQChannel channel("push", "connect", "ipc://multiple-devices-test");
|
||||
channel.UpdateRateLogging(0);
|
||||
sender.fChannels["data"].push_back(channel);
|
||||
|
||||
sender.ChangeState("INIT_DEVICE");
|
||||
sender.WaitForEndOfState("INIT_DEVICE");
|
||||
sender.ChangeState("INIT_TASK");
|
||||
sender.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
sender.ChangeState("RUN");
|
||||
sender.WaitForEndOfState("RUN");
|
||||
|
||||
sender.ChangeState("RESET_TASK");
|
||||
sender.WaitForEndOfState("RESET_TASK");
|
||||
sender.ChangeState("RESET_DEVICE");
|
||||
sender.WaitForEndOfState("RESET_DEVICE");
|
||||
|
||||
sender.ChangeState("END");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestSecond()
|
||||
{
|
||||
fair::mq::test::Receiver receiver("data");
|
||||
|
||||
receiver.SetTransport("zeromq");
|
||||
|
||||
FairMQChannel channel("pull", "bind", "ipc://multiple-devices-test");
|
||||
channel.UpdateRateLogging(0);
|
||||
receiver.fChannels["data"].push_back(channel);
|
||||
|
||||
receiver.ChangeState("INIT_DEVICE");
|
||||
receiver.WaitForEndOfState("INIT_DEVICE");
|
||||
receiver.ChangeState("INIT_TASK");
|
||||
receiver.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
receiver.ChangeState("RUN");
|
||||
receiver.WaitForEndOfState("RUN");
|
||||
|
||||
receiver.ChangeState("RESET_TASK");
|
||||
receiver.WaitForEndOfState("RESET_TASK");
|
||||
receiver.ChangeState("RESET_DEVICE");
|
||||
receiver.WaitForEndOfState("RESET_DEVICE");
|
||||
|
||||
receiver.ChangeState("END");
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(MultipleDevices, TwoInSameProcess)
|
||||
{
|
||||
std::future<bool> fut1 = std::async(std::launch::async, &MultipleDevices::TestFirst, this);
|
||||
std::future<bool> fut2 = std::async(std::launch::async, &MultipleDevices::TestSecond, this);
|
||||
|
||||
bool first = fut1.get();
|
||||
bool second = fut2.get();
|
||||
|
||||
ASSERT_EQ(first, true);
|
||||
ASSERT_EQ(second, true);
|
||||
}
|
||||
|
||||
} // namespace
|
16
test/device/runner.cxx
Normal file
16
test/device/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
64
test/event_manager/_event_manager.cxx
Normal file
64
test/event_manager/_event_manager.cxx
Normal file
@@ -0,0 +1,64 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/EventManager.h>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
struct TestEvent : fair::mq::Event<const std::string&> {};
|
||||
|
||||
TEST(EventManager, Basics)
|
||||
{
|
||||
EventManager mgr{};
|
||||
int call_counter = 0;
|
||||
int call_counter2 = 0;
|
||||
int value = 0;
|
||||
string value2;
|
||||
|
||||
std::function<void(typename TestEvent::KeyType, int)> callback{
|
||||
[&](TestEvent::KeyType key, int newValue){
|
||||
++call_counter;
|
||||
if (key == "test") value = newValue;
|
||||
}
|
||||
};
|
||||
std::function<void(typename TestEvent::KeyType, string)> callback2{
|
||||
[&](TestEvent::KeyType key, string newValue){
|
||||
++call_counter2;
|
||||
if (key == "test") value2 = newValue;
|
||||
}
|
||||
};
|
||||
|
||||
mgr.Subscribe<TestEvent, int>("foo_subscriber", callback);
|
||||
// double subscription will automatically unsubscribe first
|
||||
mgr.Subscribe<TestEvent, int>("foo_subscriber", callback);
|
||||
mgr.Emit<TestEvent>(TestEvent::KeyType{"test"}, 42);
|
||||
ASSERT_EQ(call_counter, 1);
|
||||
ASSERT_EQ(value, 42);
|
||||
|
||||
mgr.Unsubscribe<TestEvent, int>("foo_subscriber");
|
||||
mgr.Emit<TestEvent>(TestEvent::KeyType{"test"}, 13);
|
||||
ASSERT_EQ(call_counter, 1);
|
||||
|
||||
mgr.Subscribe<TestEvent, int>("foo_subscriber", callback);
|
||||
mgr.Subscribe<TestEvent, string>("foo_subscriber", callback2);
|
||||
// two different callbacks:
|
||||
mgr.Emit<TestEvent>(TestEvent::KeyType{"test"}, 9000);
|
||||
mgr.Emit<TestEvent>(TestEvent::KeyType{"test"}, string{"over 9000"});
|
||||
ASSERT_EQ(call_counter, 2);
|
||||
ASSERT_EQ(value, 9000);
|
||||
ASSERT_EQ(call_counter2, 1);
|
||||
ASSERT_EQ(value2, "over 9000");
|
||||
}
|
||||
|
||||
} // namespace
|
16
test/event_manager/runner.cxx
Normal file
16
test/event_manager/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
64
test/helper/devices/TestPairLeft.cxx
Normal file
64
test/helper/devices/TestPairLeft.cxx
Normal file
@@ -0,0 +1,64 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class PairLeft : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter{0};
|
||||
|
||||
// Simple empty message ping pong
|
||||
auto msg1(NewMessageFor("data", 0));
|
||||
if (Send(msg1, "data") >= 0) counter++;
|
||||
auto msg2(NewMessageFor("data", 0));
|
||||
if (Receive(msg2, "data") >= 0) counter++;
|
||||
auto msg3(NewMessageFor("data", 0));
|
||||
if (Send(msg3, "data") >= 0) counter++;
|
||||
auto msg4(NewMessageFor("data", 0));
|
||||
if (Receive(msg4, "data") >= 0) counter++;
|
||||
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
|
||||
|
||||
// Simple message with short text data
|
||||
auto msg5(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||
if (Send(msg5, "data") >= 0) counter++;
|
||||
auto msg6(NewMessageFor("data", 0));
|
||||
auto ret = Receive(msg6, "data");
|
||||
if (ret > 0) {
|
||||
auto content = std::string{static_cast<char*>(msg6->GetData()), msg6->GetSize()};
|
||||
LOG(info) << ret << ", " << msg6->GetSize() << ", '" << content << "'";
|
||||
if (msg6->GetSize() == ret && content == "testdata1234") counter++;
|
||||
}
|
||||
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
|
||||
|
||||
assert(counter == 6);
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
66
test/helper/devices/TestPairRight.cxx
Normal file
66
test/helper/devices/TestPairRight.cxx
Normal file
@@ -0,0 +1,66 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <string>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class PairRight : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter{0};
|
||||
|
||||
// Simple empty message ping pong
|
||||
auto msg1(NewMessageFor("data", 0));
|
||||
if (Receive(msg1, "data") >= 0) counter++;
|
||||
auto msg2(NewMessageFor("data", 0));
|
||||
if (Send(msg2, "data") >= 0) counter++;
|
||||
auto msg3(NewMessageFor("data", 0));
|
||||
if (Receive(msg3, "data") >= 0) counter++;
|
||||
auto msg4(NewMessageFor("data", 0));
|
||||
if (Send(msg4, "data") >= 0) counter++;
|
||||
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
|
||||
|
||||
// Simple message with short text data
|
||||
auto msg5(NewMessageFor("data", 0));
|
||||
auto ret = Receive(msg5, "data");
|
||||
if (ret > 0) {
|
||||
auto content = std::string{static_cast<char*>(msg5->GetData()), msg5->GetSize()};
|
||||
LOG(info) << ret << ", " << msg5->GetSize() << ", '" << content << "'";
|
||||
if (msg5->GetSize() == ret && content == "testdata1234") counter++;
|
||||
}
|
||||
auto msg6(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||
if (Send(msg6, "data") >= 0) counter++;
|
||||
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
if (counter == 6) LOG(info) << "PAIR test successfull.";
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
133
test/helper/devices/TestPollIn.cxx
Normal file
133
test/helper/devices/TestPollIn.cxx
Normal file
@@ -0,0 +1,133 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PollIn : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
PollIn()
|
||||
: fPollType(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
fPollType = fConfig->GetValue<int>("poll-type");
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
vector<const FairMQChannel*> chans;
|
||||
|
||||
chans.push_back(&fChannels.at("data1").at(0));
|
||||
chans.push_back(&fChannels.at("data2").at(0));
|
||||
|
||||
FairMQPollerPtr poller = nullptr;
|
||||
|
||||
if (fPollType == 0)
|
||||
{
|
||||
poller = NewPoller(chans);
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
poller = NewPoller("data1", "data2");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "wrong poll type provided: " << fPollType;
|
||||
}
|
||||
|
||||
bool arrived1 = false;
|
||||
bool arrived2 = false;
|
||||
bool bothArrived = false;
|
||||
|
||||
FairMQMessagePtr msg1(NewMessage());
|
||||
FairMQMessagePtr msg2(NewMessage());
|
||||
|
||||
while (!bothArrived)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
if (poller->CheckInput("data1", 0))
|
||||
{
|
||||
LOG(debug) << "CheckInput(\"data1\", 0) triggered";
|
||||
if (Receive(msg1, "data1", 0) >= 0)
|
||||
{
|
||||
arrived1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckInput("data2", 0))
|
||||
{
|
||||
LOG(debug) << "CheckInput(\"data2\", 0) triggered";
|
||||
if (Receive(msg2, "data2", 0) >= 0)
|
||||
{
|
||||
arrived2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arrived1 && arrived2)
|
||||
{
|
||||
bothArrived = true;
|
||||
LOG(info) << "POLL test successfull";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
int fPollType;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
42
test/helper/devices/TestPollOut.cxx
Normal file
42
test/helper/devices/TestPollOut.cxx
Normal file
@@ -0,0 +1,42 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class PollOut : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg1 = FairMQMessagePtr{NewMessage()};
|
||||
auto msg2 = FairMQMessagePtr{NewMessage()};
|
||||
Send(msg1, "data1");
|
||||
Send(msg2, "data2");
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
77
test/helper/devices/TestPub.cxx
Normal file
77
test/helper/devices/TestPub.cxx
Normal file
@@ -0,0 +1,77 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Pub : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto ready1 = FairMQMessagePtr{NewMessage()};
|
||||
auto ready2 = FairMQMessagePtr{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 = FairMQMessagePtr{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 = FairMQMessagePtr{NewMessage()};
|
||||
auto ack2 = FairMQMessagePtr{NewMessage()};
|
||||
auto a1 = Receive(ack1, "control");
|
||||
auto a2 = Receive(ack2, "control");
|
||||
if (a1 >= 0 && a2 >= 0)
|
||||
{
|
||||
LOG(info) << "PUB-SUB test successfull";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed receiving ack signal: a1 = " << a1 << ", a2 = " << a2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed receiving ready signal: r1 = " << r1 << ", r2 = " << r2;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
47
test/helper/devices/TestPull.cxx
Normal file
47
test/helper/devices/TestPull.cxx
Normal file
@@ -0,0 +1,47 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Pull : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg = FairMQMessagePtr{NewMessage()};
|
||||
|
||||
if (Receive(msg, "data") >= 0)
|
||||
{
|
||||
LOG(info) << "PUSH-PULL test successfull";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
40
test/helper/devices/TestPush.cxx
Normal file
40
test/helper/devices/TestPush.cxx
Normal file
@@ -0,0 +1,40 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Push : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg = FairMQMessagePtr{NewMessage()};
|
||||
Send(msg, "data");
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
55
test/helper/devices/TestRep.cxx
Normal file
55
test/helper/devices/TestRep.cxx
Normal file
@@ -0,0 +1,55 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Rep : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto request1 = FairMQMessagePtr{NewMessage()};
|
||||
if (Receive(request1, "data") >= 0)
|
||||
{
|
||||
LOG(info) << "Received request 1";
|
||||
auto reply = FairMQMessagePtr{NewMessage()};
|
||||
Send(reply, "data");
|
||||
}
|
||||
auto request2 = FairMQMessagePtr{NewMessage()};
|
||||
if (Receive(request2, "data") >= 0)
|
||||
{
|
||||
LOG(info) << "Received request 2";
|
||||
auto reply = FairMQMessagePtr{NewMessage()};
|
||||
Send(reply, "data");
|
||||
}
|
||||
|
||||
LOG(info) << "REQ-REP test successfull";
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
47
test/helper/devices/TestReq.cxx
Normal file
47
test/helper/devices/TestReq.cxx
Normal file
@@ -0,0 +1,47 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Req : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto request = FairMQMessagePtr{NewMessage()};
|
||||
Send(request, "data");
|
||||
|
||||
auto reply = FairMQMessagePtr{NewMessage()};
|
||||
if (Receive(reply, "data") >= 0)
|
||||
{
|
||||
LOG(info) << "received reply";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
71
test/helper/devices/TestSub.cxx
Normal file
71
test/helper/devices/TestSub.cxx
Normal file
@@ -0,0 +1,71 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Sub : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto ready = FairMQMessagePtr{NewMessage()};
|
||||
auto r1 = Send(ready, "control");
|
||||
if (r1 >= 0)
|
||||
{
|
||||
LOG(info) << "Sent first control signal";
|
||||
auto msg = FairMQMessagePtr{NewMessage()};
|
||||
auto d1 = Receive(msg, "data");
|
||||
if (d1 >= 0)
|
||||
{
|
||||
LOG(info) << "Received data";
|
||||
auto ack = FairMQMessagePtr{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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
59
test/helper/devices/TestTransferTimeout.cxx
Normal file
59
test/helper/devices/TestTransferTimeout.cxx
Normal file
@@ -0,0 +1,59 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class TransferTimeout : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto sendCanceling = false;
|
||||
auto receiveCanceling = false;
|
||||
|
||||
auto msg1 = FairMQMessagePtr{NewMessage()};
|
||||
auto msg2 = FairMQMessagePtr{NewMessage()};
|
||||
|
||||
if (Send(msg1, "data-out", 0, 100) == -2)
|
||||
{
|
||||
LOG(info) << "send canceled";
|
||||
sendCanceling = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "send did not cancel";
|
||||
}
|
||||
|
||||
if (Receive(msg2, "data-in", 0, 100) == -2)
|
||||
{
|
||||
LOG(info) << "receive canceled";
|
||||
receiveCanceling = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "receive did not cancel";
|
||||
}
|
||||
|
||||
if (sendCanceling && receiveCanceling)
|
||||
{
|
||||
LOG(info) << "Transfer timeout test successfull";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
9
test/helper/plugins/dummy.cxx
Normal file
9
test/helper/plugins/dummy.cxx
Normal file
@@ -0,0 +1,9 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <dummy.h>
|
74
test/helper/plugins/dummy.h.in
Normal file
74
test/helper/plugins/dummy.h.in
Normal file
@@ -0,0 +1,74 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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_PLUGIN_DUMMY
|
||||
#define FAIR_MQ_TEST_PLUGIN_DUMMY
|
||||
|
||||
#include <fairmq/Plugin.h>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class DummyPlugin : public fair::mq::Plugin
|
||||
{
|
||||
public:
|
||||
|
||||
DummyPlugin(
|
||||
const std::string name,
|
||||
const Version version,
|
||||
const std::string maintainer,
|
||||
const std::string homepage,
|
||||
PluginServices* pluginServices)
|
||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||
{
|
||||
SubscribeToDeviceStateChange(
|
||||
[&](DeviceState newState){
|
||||
switch (newState)
|
||||
{
|
||||
case DeviceState::Exiting:
|
||||
UnsubscribeFromDeviceStateChange();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}; /* class DummyPlugin */
|
||||
|
||||
auto DummyPluginProgramOptions() -> Plugin::ProgOptions
|
||||
{
|
||||
auto plugin_options = boost::program_options::options_description{"Dummy Plugin"};
|
||||
plugin_options.add_options()
|
||||
("custom-dummy-option", boost::program_options::value<std::string>(), "Cool custom option.")
|
||||
("custom-dummy-option2", boost::program_options::value<std::string>(), "Another cool custom option.");
|
||||
return plugin_options;
|
||||
}
|
||||
|
||||
REGISTER_FAIRMQ_PLUGIN(
|
||||
DummyPlugin, // Class name
|
||||
test_dummy, // Plugin name (string, lower case chars only)
|
||||
(fair::mq::Plugin::Version{@VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@}), // Version
|
||||
"Mr. Dummy <dummy@test.net>", // Maintainer
|
||||
"https://git.test.net/dummy.git", // Homepage
|
||||
fair::mq::test::DummyPluginProgramOptions // Free function which declares custom program options for the plugin
|
||||
)
|
||||
|
||||
} /* namespace test */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_TEST_PLUGIN_DUMMY */
|
9
test/helper/plugins/dummy2.cxx
Normal file
9
test/helper/plugins/dummy2.cxx
Normal file
@@ -0,0 +1,9 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <dummy2.h>
|
44
test/helper/plugins/dummy2.h.in
Normal file
44
test/helper/plugins/dummy2.h.in
Normal file
@@ -0,0 +1,44 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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_PLUGIN_DUMMY2
|
||||
#define FAIR_MQ_TEST_PLUGIN_DUMMY2
|
||||
|
||||
#include <fairmq/Plugin.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class Dummy2Plugin : public fair::mq::Plugin
|
||||
{
|
||||
public:
|
||||
|
||||
Dummy2Plugin(const std::string name, const Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices)
|
||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||
{
|
||||
}
|
||||
}; /* class Dummy2Plugin */
|
||||
|
||||
REGISTER_FAIRMQ_PLUGIN(
|
||||
Dummy2Plugin,
|
||||
test_dummy2,
|
||||
(Plugin::Version{@VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@}),
|
||||
"Mr. Dummy <dummy@test.net>",
|
||||
"https://git.test.net/dummy.git",
|
||||
fair::mq::Plugin::NoProgramOptions
|
||||
)
|
||||
|
||||
} /* namespace test */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_TEST_PLUGIN_DUMMY */
|
88
test/helper/runTestDevice.cxx
Normal file
88
test/helper/runTestDevice.cxx
Normal file
@@ -0,0 +1,88 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "devices/TestPairLeft.cxx"
|
||||
#include "devices/TestPairRight.cxx"
|
||||
#include "devices/TestPollIn.cxx"
|
||||
#include "devices/TestPollOut.cxx"
|
||||
#include "devices/TestPub.cxx"
|
||||
#include "devices/TestPull.cxx"
|
||||
#include "devices/TestPush.cxx"
|
||||
#include "devices/TestRep.cxx"
|
||||
#include "devices/TestReq.cxx"
|
||||
#include "devices/TestSub.cxx"
|
||||
#include "devices/TestTransferTimeout.cxx"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <iostream>
|
||||
#include <runFairMQDevice.h>
|
||||
#include <string>
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
auto addCustomOptions(bpo::options_description& options) -> void
|
||||
{
|
||||
options.add_options()
|
||||
("poll-type", bpo::value<int>()->default_value(0), "Poll type switch(0 - vector of (sub-)channels, 1 - vector of channel names)");
|
||||
}
|
||||
|
||||
auto getDevice(const FairMQProgOptions& config) -> FairMQDevicePtr
|
||||
{
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
|
||||
auto id = config.GetValue<std::string>("id");
|
||||
if (0 == id.find("pull_"))
|
||||
{
|
||||
return new Pull;
|
||||
}
|
||||
else if (0 == id.find("push_"))
|
||||
{
|
||||
return new Push;
|
||||
}
|
||||
else if (0 == id.find("sub_"))
|
||||
{
|
||||
return new Sub;
|
||||
}
|
||||
else if (0 == id.find("pub_"))
|
||||
{
|
||||
return new Pub;
|
||||
}
|
||||
else if (0 == id.find("req_"))
|
||||
{
|
||||
return new Req;
|
||||
}
|
||||
else if (0 == id.find("rep_"))
|
||||
{
|
||||
return new Rep;
|
||||
}
|
||||
else if (0 == id.find("transfer_timeout_"))
|
||||
{
|
||||
return new TransferTimeout;
|
||||
}
|
||||
else if (0 == id.find("pollout_"))
|
||||
{
|
||||
return new PollOut;
|
||||
}
|
||||
else if (0 == id.find("pollin_"))
|
||||
{
|
||||
return new PollIn;
|
||||
}
|
||||
else if (0 == id.find("pairleft_"))
|
||||
{
|
||||
return new PairLeft;
|
||||
}
|
||||
else if (0 == id.find("pairright_"))
|
||||
{
|
||||
return new PairRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Don't know id '" << id << "'" << endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
73
test/message_resize/_message_resize.cxx
Normal file
73
test/message_resize/_message_resize.cxx
Normal file
@@ -0,0 +1,73 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQChannel.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
auto RunPushPullWithMsgResize(string transport, string address) -> void {
|
||||
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.SetValue<string>("session", to_string(session));
|
||||
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
|
||||
|
||||
FairMQChannel push{"Push", "push", factory};
|
||||
push.Bind(address);
|
||||
|
||||
FairMQChannel pull{"Pull", "pull", factory};
|
||||
pull.Connect(address);
|
||||
|
||||
FairMQMessagePtr outMsg(push.NewMessage(1000));
|
||||
ASSERT_EQ(outMsg->GetSize(), 1000);
|
||||
outMsg->SetUsedSize(500);
|
||||
ASSERT_EQ(outMsg->GetSize(), 500);
|
||||
outMsg->SetUsedSize(250);
|
||||
ASSERT_EQ(outMsg->GetSize(), 250);
|
||||
FairMQMessagePtr msgCopy(push.NewMessage());
|
||||
msgCopy->Copy(*outMsg);
|
||||
ASSERT_EQ(msgCopy->GetSize(), 250);
|
||||
|
||||
ASSERT_EQ(push.Send(outMsg), 250);
|
||||
|
||||
FairMQMessagePtr inMsg(pull.NewMessage());
|
||||
ASSERT_EQ(pull.Receive(inMsg), 250);
|
||||
ASSERT_EQ(inMsg->GetSize(), 250);
|
||||
}
|
||||
|
||||
TEST(MessageResize, ZeroMQ)
|
||||
{
|
||||
RunPushPullWithMsgResize("zeromq", "ipc://test_message_resize");
|
||||
}
|
||||
|
||||
TEST(MessageResize, shmem)
|
||||
{
|
||||
RunPushPullWithMsgResize("shmem", "ipc://test_message_resize");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(MessageResize, nanomsg)
|
||||
{
|
||||
RunPushPullWithMsgResize("nanomsg", "ipc://test_message_resize");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
16
test/message_resize/runner.cxx
Normal file
16
test/message_resize/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
73
test/parts/_iterator_interface.cxx
Normal file
73
test/parts/_iterator_interface.cxx
Normal file
@@ -0,0 +1,73 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <FairMQParts.h>
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class RandomAccessIterator : public ::testing::Test {
|
||||
protected:
|
||||
FairMQParts mParts;
|
||||
shared_ptr<FairMQTransportFactory> mFactory;
|
||||
|
||||
RandomAccessIterator()
|
||||
: mParts(FairMQParts{}),
|
||||
mFactory(FairMQTransportFactory::CreateTransportFactory("zeromq"))
|
||||
{
|
||||
mParts.AddPart(mFactory->NewSimpleMessage("1"));
|
||||
mParts.AddPart(mFactory->NewSimpleMessage("2"));
|
||||
mParts.AddPart(mFactory->NewSimpleMessage("3"));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(RandomAccessIterator, RangeForLoopConst)
|
||||
{
|
||||
stringstream out;
|
||||
for (const auto& part : mParts) {
|
||||
out << string{static_cast<char*>(part->GetData()), part->GetSize()};
|
||||
}
|
||||
|
||||
ASSERT_EQ(out.str(), "123");
|
||||
}
|
||||
|
||||
TEST_F(RandomAccessIterator, RangeForLoopMutation)
|
||||
{
|
||||
auto s = string{"4"};
|
||||
|
||||
for (auto&& part : mParts) {
|
||||
part = mFactory->NewSimpleMessage(s);
|
||||
}
|
||||
|
||||
stringstream out;
|
||||
for (const auto& part : mParts) {
|
||||
out << string{static_cast<char*>(part->GetData()), part->GetSize()};
|
||||
}
|
||||
|
||||
ASSERT_EQ(out.str(), "444");
|
||||
}
|
||||
|
||||
TEST_F(RandomAccessIterator, ForEachConst)
|
||||
{
|
||||
stringstream out;
|
||||
for_each(mParts.cbegin(), mParts.cend(), [&out](const FairMQMessagePtr& part) {
|
||||
out << string{static_cast<char*>(part->GetData()), part->GetSize()};
|
||||
});
|
||||
|
||||
ASSERT_EQ(out.str(), "123");
|
||||
}
|
||||
|
||||
} // namespace
|
16
test/parts/runner.cxx
Normal file
16
test/parts/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
60
test/plugin_services/Fixture.h
Normal file
60
test/plugin_services/Fixture.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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_FIXTURE
|
||||
#define FAIR_MQ_TEST_FIXTURE
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/PluginServices.h>
|
||||
#include <FairMQDevice.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
#include <memory>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
inline auto control(std::shared_ptr<FairMQDevice> device) -> void
|
||||
{
|
||||
for (const auto event : {
|
||||
FairMQDevice::INIT_DEVICE,
|
||||
FairMQDevice::RESET_DEVICE,
|
||||
FairMQDevice::END,
|
||||
}) {
|
||||
device->ChangeState(event);
|
||||
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
|
||||
}
|
||||
}
|
||||
|
||||
struct PluginServices : ::testing::Test {
|
||||
PluginServices()
|
||||
: mConfig()
|
||||
, mDevice{std::make_shared<FairMQDevice>()}
|
||||
, mServices{&mConfig, mDevice}
|
||||
{
|
||||
mDevice->SetTransport("zeromq");
|
||||
}
|
||||
|
||||
~PluginServices()
|
||||
{
|
||||
if(mDevice->GetCurrentState() == FairMQDevice::IDLE) control(mDevice);
|
||||
}
|
||||
|
||||
FairMQProgOptions mConfig;
|
||||
std::shared_ptr<FairMQDevice> mDevice;
|
||||
fair::mq::PluginServices mServices;
|
||||
};
|
||||
|
||||
} /* namespace test */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_TEST_FIXTURE */
|
91
test/plugin_services/_config.cxx
Normal file
91
test/plugin_services/_config.cxx
Normal file
@@ -0,0 +1,91 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Fixture.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using fair::mq::test::PluginServices;
|
||||
using DeviceState = fair::mq::PluginServices::DeviceState;
|
||||
using DeviceStateTransition = fair::mq::PluginServices::DeviceStateTransition;
|
||||
|
||||
TEST_F(PluginServices, ConfigSynchronous)
|
||||
{
|
||||
mServices.SubscribeToDeviceStateChange("test",[&](DeviceState newState){
|
||||
switch (newState) {
|
||||
case DeviceState::InitializingDevice:
|
||||
mServices.SetProperty<int>("blubb", 42);
|
||||
break;
|
||||
case DeviceState::DeviceReady:
|
||||
EXPECT_EQ(mServices.GetProperty<int>("blubb"), 42);
|
||||
EXPECT_EQ(mServices.GetPropertyAsString("blubb"), fair::mq::tools::ToString(42));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, ConfigInvalidStateError)
|
||||
{
|
||||
mServices.SubscribeToDeviceStateChange("test",[&](DeviceState newState){
|
||||
switch (newState) {
|
||||
case DeviceState::DeviceReady:
|
||||
ASSERT_THROW(mServices.SetProperty<int>("blubb", 42), fair::mq::PluginServices::InvalidStateError);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, KeyDiscovery)
|
||||
{
|
||||
mConfig.SetValue("foo", 0);
|
||||
|
||||
auto keys(mServices.GetPropertyKeys());
|
||||
|
||||
EXPECT_TRUE(find(keys.begin(), keys.end(), "foo") != keys.end());
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, ConfigCallbacks)
|
||||
{
|
||||
mServices.SubscribeToPropertyChange<string>("test", [](const string& key, string value) {
|
||||
if (key == "chans.data.0.address") { ASSERT_EQ(value, "tcp://localhost:4321"); }
|
||||
});
|
||||
|
||||
mServices.SubscribeToPropertyChange<int>("test", [](const string& key, int value) {
|
||||
if(key == "chans.data.0.rcvBufSize") {
|
||||
FAIL(); // should not be called because we unsubscribed
|
||||
}
|
||||
});
|
||||
|
||||
mServices.SubscribeToPropertyChange<double>("test", [](const string& key, double value) {
|
||||
if (key == "data-rate") { ASSERT_EQ(value, 0.9); }
|
||||
});
|
||||
|
||||
mServices.SubscribeToDeviceStateChange("test",[&](DeviceState newState){
|
||||
switch (newState) {
|
||||
case DeviceState::InitializingDevice:
|
||||
mServices.SetProperty<string>("chans.data.0.address", "tcp://localhost:4321");
|
||||
mServices.SetProperty<int>("chans.data.0.rcvBufSize", 100);
|
||||
mServices.SetProperty<double>("data-rate", 0.9);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
mServices.UnsubscribeFromPropertyChange<int>("test");
|
||||
}
|
||||
|
||||
} /* namespace */
|
129
test/plugin_services/_control.cxx
Normal file
129
test/plugin_services/_control.cxx
Normal file
@@ -0,0 +1,129 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Fixture.h"
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using fair::mq::test::PluginServices;
|
||||
using DeviceState = fair::mq::PluginServices::DeviceState;
|
||||
using DeviceStateTransition = fair::mq::PluginServices::DeviceStateTransition;
|
||||
|
||||
TEST_F(PluginServices, OnlySingleController)
|
||||
{
|
||||
ASSERT_NO_THROW(mServices.TakeDeviceControl("foo"));
|
||||
ASSERT_NO_THROW(mServices.TakeDeviceControl("foo")); // noop
|
||||
ASSERT_THROW( // no control for bar
|
||||
mServices.ChangeDeviceState("bar", DeviceStateTransition::InitDevice),
|
||||
fair::mq::PluginServices::DeviceControlError
|
||||
);
|
||||
ASSERT_THROW( // no control for bar
|
||||
mServices.ReleaseDeviceControl("bar"),
|
||||
fair::mq::PluginServices::DeviceControlError
|
||||
);
|
||||
|
||||
ASSERT_NO_THROW(mServices.ReleaseDeviceControl("foo"));
|
||||
ASSERT_FALSE(mServices.GetDeviceController());
|
||||
// take control implicitely
|
||||
ASSERT_NO_THROW(mServices.TakeDeviceControl("foo"));
|
||||
ASSERT_NO_THROW(mServices.ChangeDeviceState("foo", DeviceStateTransition::InitDevice));
|
||||
EXPECT_EQ(mServices.GetDeviceController(), string{"foo"});
|
||||
|
||||
// park device
|
||||
mDevice->WaitForEndOfState(FairMQDevice::DEVICE_READY);
|
||||
mServices.ChangeDeviceState("foo", DeviceStateTransition::ResetDevice);
|
||||
mDevice->WaitForEndOfState(FairMQDevice::RESET_DEVICE);
|
||||
mServices.ChangeDeviceState("foo", DeviceStateTransition::End);
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, Control)
|
||||
{
|
||||
ASSERT_EQ(mServices.GetCurrentDeviceState(), DeviceState::Idle);
|
||||
ASSERT_NO_THROW(mServices.TakeDeviceControl("foo"));
|
||||
ASSERT_NO_THROW(mServices.ChangeDeviceState("foo", DeviceStateTransition::InitDevice));
|
||||
|
||||
DeviceState nextState;
|
||||
condition_variable cv;
|
||||
mutex cv_m;
|
||||
mServices.SubscribeToDeviceStateChange("test", [&](DeviceState newState){
|
||||
ASSERT_NE(newState, DeviceState::ResettingDevice); // check UnsubscribeFromDeviceStateChange
|
||||
|
||||
lock_guard<mutex> lock{cv_m};
|
||||
nextState = newState;
|
||||
if (newState == DeviceState::DeviceReady)
|
||||
{
|
||||
cv.notify_one();
|
||||
mServices.UnsubscribeFromDeviceStateChange("test");
|
||||
}
|
||||
});
|
||||
|
||||
unique_lock<mutex> lock{cv_m};
|
||||
cv.wait(lock);
|
||||
|
||||
ASSERT_EQ(mServices.GetCurrentDeviceState(), DeviceState::DeviceReady);
|
||||
|
||||
mServices.ChangeDeviceState("foo", DeviceStateTransition::ResetDevice);
|
||||
mDevice->WaitForEndOfState(FairMQDevice::RESET_DEVICE);
|
||||
mServices.ChangeDeviceState("foo", DeviceStateTransition::End);
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, ControlStateConversions)
|
||||
{
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("OK"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("ERROR"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("IDLE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("INITIALIZING DEVICE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("DEVICE READY"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("INITIALIZING TASK"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("READY"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("RUNNING"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("PAUSED"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("RESETTING TASK"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("RESETTING DEVICE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceState("EXITING"));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Ok));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Error));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Idle));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::InitializingDevice));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::DeviceReady));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::InitializingTask));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Ready));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Running));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Paused));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::ResettingTask));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::ResettingDevice));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceState::Exiting));
|
||||
}
|
||||
|
||||
TEST_F(PluginServices, ControlStateTransitionConversions)
|
||||
{
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("INIT DEVICE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("INIT TASK"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("RUN"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("PAUSE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("STOP"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("RESET TASK"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("RESET DEVICE"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("END"));
|
||||
EXPECT_NO_THROW(mServices.ToDeviceStateTransition("ERROR FOUND"));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::InitDevice));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::InitTask));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::Run));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::Pause));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::Stop));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::ResetTask));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::ResetDevice));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::End));
|
||||
EXPECT_NO_THROW(mServices.ToStr(DeviceStateTransition::ErrorFound));
|
||||
}
|
||||
|
||||
} /* namespace */
|
16
test/plugin_services/runner.cxx
Normal file
16
test/plugin_services/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
79
test/plugins/_plugin.cxx
Normal file
79
test/plugins/_plugin.cxx
Normal file
@@ -0,0 +1,79 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/Plugin.h>
|
||||
#include <fairmq/PluginServices.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <FairMQDevice.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
auto control(shared_ptr<FairMQDevice> device) -> void
|
||||
{
|
||||
device->SetTransport("zeromq");
|
||||
for (const auto event : {
|
||||
FairMQDevice::INIT_DEVICE,
|
||||
FairMQDevice::RESET_DEVICE,
|
||||
FairMQDevice::END,
|
||||
}) {
|
||||
device->ChangeState(event);
|
||||
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Plugin, Operators)
|
||||
{
|
||||
FairMQProgOptions config{};
|
||||
auto device = make_shared<FairMQDevice>();
|
||||
PluginServices services{&config, device};
|
||||
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
|
||||
Plugin p2{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
|
||||
Plugin p3{"file", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/file.git", &services};
|
||||
EXPECT_EQ(p1, p2);
|
||||
EXPECT_NE(p1, p3);
|
||||
control(device);
|
||||
}
|
||||
|
||||
TEST(Plugin, OstreamOperators)
|
||||
{
|
||||
FairMQProgOptions config{};
|
||||
auto device = make_shared<FairMQDevice>();
|
||||
PluginServices services{&config, device};
|
||||
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
|
||||
stringstream ss;
|
||||
ss << p1;
|
||||
EXPECT_EQ(ss.str(), string{"'dds', version '1.0.0', maintainer 'Foo Bar <foo.bar@test.net>', homepage 'https://git.test.net/dds.git'"});
|
||||
control(device);
|
||||
}
|
||||
|
||||
TEST(PluginVersion, Operators)
|
||||
{
|
||||
struct fair::mq::tools::Version v1{1, 0, 0};
|
||||
struct fair::mq::tools::Version v2{1, 0, 0};
|
||||
struct fair::mq::tools::Version v3{1, 2, 0};
|
||||
EXPECT_EQ(v1, v2);
|
||||
EXPECT_NE(v1, v3);
|
||||
EXPECT_GT(v3, v2);
|
||||
EXPECT_LT(v1, v3);
|
||||
EXPECT_GE(v3, v2);
|
||||
EXPECT_GE(v2, v1);
|
||||
EXPECT_LE(v1, v2);
|
||||
EXPECT_LE(v2, v3);
|
||||
}
|
||||
|
||||
} /* namespace */
|
157
test/plugins/_plugin_manager.cxx
Normal file
157
test/plugins/_plugin_manager.cxx
Normal file
@@ -0,0 +1,157 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/PluginManager.h>
|
||||
#include <fairmq/PluginServices.h>
|
||||
#include <FairMQDevice.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace fair::mq;
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
auto control(shared_ptr<FairMQDevice> device) -> void
|
||||
{
|
||||
device->SetTransport("zeromq");
|
||||
for (const auto event : {
|
||||
FairMQDevice::INIT_DEVICE,
|
||||
FairMQDevice::RESET_DEVICE,
|
||||
FairMQDevice::END,
|
||||
}) {
|
||||
device->ChangeState(event);
|
||||
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PluginManager, LoadPluginDynamic)
|
||||
{
|
||||
FairMQProgOptions config{};
|
||||
auto mgr = PluginManager{};
|
||||
auto device = make_shared<FairMQDevice>();
|
||||
mgr.EmplacePluginServices(&config, device);
|
||||
|
||||
mgr.PrependSearchPath("./lib");
|
||||
|
||||
ASSERT_NO_THROW(mgr.LoadPlugin("test_dummy"));
|
||||
ASSERT_NO_THROW(mgr.LoadPlugin("test_dummy2"));
|
||||
|
||||
ASSERT_NO_THROW(mgr.InstantiatePlugins());
|
||||
|
||||
// check order
|
||||
const auto expected = vector<string>{"test_dummy", "test_dummy2"};
|
||||
auto actual = vector<string>{};
|
||||
mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); });
|
||||
ASSERT_TRUE(actual == expected);
|
||||
|
||||
// program options
|
||||
auto count = 0;
|
||||
mgr.ForEachPluginProgOptions([&count](const options_description& /*d*/){ ++count; });
|
||||
ASSERT_EQ(count, 1);
|
||||
|
||||
control(device);
|
||||
}
|
||||
|
||||
TEST(PluginManager, LoadPluginStatic)
|
||||
{
|
||||
auto mgr = PluginManager{};
|
||||
auto device = make_shared<FairMQDevice>();
|
||||
device->SetTransport("zeromq");
|
||||
|
||||
ASSERT_NO_THROW(mgr.LoadPlugin("s:control"));
|
||||
|
||||
FairMQProgOptions config{};
|
||||
config.SetValue<string>("control", "static");
|
||||
config.SetValue("catch-signals", 0);
|
||||
mgr.EmplacePluginServices(&config, device);
|
||||
|
||||
ASSERT_NO_THROW(mgr.InstantiatePlugins());
|
||||
|
||||
// check order
|
||||
const auto expected = vector<string>{"control"};
|
||||
auto actual = vector<string>{};
|
||||
mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); });
|
||||
ASSERT_TRUE(actual == expected);
|
||||
|
||||
// program options
|
||||
auto count = 0;
|
||||
mgr.ForEachPluginProgOptions([&count](const options_description& d){ ++count; });
|
||||
ASSERT_EQ(count, 1);
|
||||
|
||||
mgr.WaitForPluginsToReleaseDeviceControl();
|
||||
}
|
||||
|
||||
TEST(PluginManager, Factory)
|
||||
{
|
||||
const auto args = vector<string>{"-l", "debug", "--help", "-S", ">/lib", "</home/user/lib", "/usr/local/lib", "/usr/lib"};
|
||||
auto mgr = PluginManager::MakeFromCommandLineOptions(args);
|
||||
const auto path1 = path{"/home/user/lib"};
|
||||
const auto path2 = path{"/usr/local/lib"};
|
||||
const auto path3 = path{"/usr/lib"};
|
||||
const auto path4 = path{"/lib"};
|
||||
const auto expected = vector<path>{path1, path2, path3, path4};
|
||||
ASSERT_TRUE(static_cast<bool>(mgr));
|
||||
ASSERT_TRUE(mgr->SearchPaths() == expected);
|
||||
}
|
||||
|
||||
TEST(PluginManager, SearchPathValidation)
|
||||
{
|
||||
const auto path1 = path{"/tmp/test1"};
|
||||
const auto path2 = path{"/tmp/test2"};
|
||||
const auto path3 = path{"/tmp/test3"};
|
||||
auto mgr = PluginManager{};
|
||||
|
||||
mgr.SetSearchPaths({path1, path2});
|
||||
auto expected = vector<path>{path1, path2};
|
||||
ASSERT_EQ(mgr.SearchPaths(), expected);
|
||||
|
||||
mgr.AppendSearchPath(path3);
|
||||
expected = vector<path>{path1, path2, path3};
|
||||
ASSERT_EQ(mgr.SearchPaths(), expected);
|
||||
|
||||
mgr.PrependSearchPath(path3);
|
||||
expected = vector<path>{path3, path1, path2, path3};
|
||||
ASSERT_EQ(mgr.SearchPaths(), expected);
|
||||
}
|
||||
|
||||
TEST(PluginManager, SearchPaths)
|
||||
{
|
||||
const auto temp = temp_directory_path() / unique_path();
|
||||
create_directories(temp);
|
||||
const auto non_existing_dir = temp / "non-existing-dir";
|
||||
const auto existing_dir = temp / "existing-dir";
|
||||
create_directories(existing_dir);
|
||||
const auto existing_file = temp / "existing-file.so";
|
||||
std::fstream fs;
|
||||
fs.open(existing_file.string(), std::fstream::out);
|
||||
fs.close();
|
||||
const auto empty_path = path{""};
|
||||
|
||||
auto mgr = PluginManager{};
|
||||
ASSERT_NO_THROW(mgr.AppendSearchPath(non_existing_dir));
|
||||
ASSERT_NO_THROW(mgr.AppendSearchPath(existing_dir));
|
||||
ASSERT_THROW(mgr.AppendSearchPath(existing_file), PluginManager::BadSearchPath);
|
||||
ASSERT_NO_THROW(mgr.PrependSearchPath(non_existing_dir));
|
||||
ASSERT_NO_THROW(mgr.PrependSearchPath(existing_dir));
|
||||
ASSERT_THROW(mgr.PrependSearchPath(existing_file), PluginManager::BadSearchPath);
|
||||
ASSERT_NO_THROW(mgr.SetSearchPaths({non_existing_dir, existing_dir}));
|
||||
ASSERT_THROW(mgr.SetSearchPaths({non_existing_dir, existing_file}), PluginManager::BadSearchPath);
|
||||
ASSERT_THROW(mgr.SetSearchPaths({non_existing_dir, empty_path}), PluginManager::BadSearchPath);
|
||||
|
||||
remove_all(temp);
|
||||
}
|
||||
|
||||
} /* namespace */
|
26
test/plugins/_plugin_manager_prelink.cxx
Normal file
26
test/plugins/_plugin_manager_prelink.cxx
Normal file
@@ -0,0 +1,26 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/PluginManager.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace fair::mq;
|
||||
using namespace std;
|
||||
|
||||
TEST(PluginManager, LoadPluginPrelinkedDynamic)
|
||||
{
|
||||
auto mgr = PluginManager{};
|
||||
|
||||
ASSERT_NO_THROW(mgr.LoadPlugin("p:test_dummy"));
|
||||
ASSERT_NO_THROW(mgr.LoadPlugin("p:test_dummy2"));
|
||||
}
|
||||
|
||||
} /* namespace */
|
16
test/plugins/runner.cxx
Normal file
16
test/plugins/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
73
test/protocols/_pair.cxx
Normal file
73
test/protocols/_pair.cxx
Normal file
@@ -0,0 +1,73 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2018 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunPair(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto pairleft = execute_result{"", 100};
|
||||
thread pairleft_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pairleft_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
pairleft = execute(cmd.str(), "[PAIR L]");
|
||||
});
|
||||
|
||||
auto pairright = execute_result{"", 100};
|
||||
thread pairright_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pairright_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
pairright = execute(cmd.str(), "[PAIR R]");
|
||||
});
|
||||
|
||||
pairleft_thread.join();
|
||||
pairright_thread.join();
|
||||
cerr << pairleft.console_out << pairright.console_out;
|
||||
|
||||
exit(pairleft.exit_code + pairright.exit_code);
|
||||
}
|
||||
|
||||
TEST(Pair, MP_ZeroMQ__tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPair("zeromq"), ::testing::ExitedWithCode(0), "PAIR test successfull");
|
||||
}
|
||||
|
||||
TEST(Pair, MP_ShMem___tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPair("shmem"), ::testing::ExitedWithCode(0), "PAIR test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(Pair, MP_Nanomsg_tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPair("nanomsg"), ::testing::ExitedWithCode(0), "PAIR test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
#ifdef BUILD_OFI_TRANSPORT
|
||||
TEST(Pair, MP_Ofi_____tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPair("ofi"), ::testing::ExitedWithCode(0), "PAIR test successfull");
|
||||
}
|
||||
#endif /* BUILD_OFI_TRANSPORT */
|
||||
|
||||
} // namespace
|
87
test/protocols/_poller.cxx
Normal file
87
test/protocols/_poller.cxx
Normal file
@@ -0,0 +1,87 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunPoller(string transport, int pollType) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto pollout = execute_result{"", 0};
|
||||
thread poll_out_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice
|
||||
<< " --id pollout_"<< transport
|
||||
<< " --control static --color false"
|
||||
<< " --session " << session << " --mq-config \"" << mqConfig << "\"";
|
||||
pollout = execute(cmd.str(), "[POLLOUT]");
|
||||
});
|
||||
|
||||
auto pollin = execute_result{"", 0};
|
||||
thread poll_in_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice
|
||||
<< " --id pollin_" << transport
|
||||
<< " --control static --color false"
|
||||
<< " --session " << session << " --mq-config \"" << mqConfig << "\" --poll-type " << pollType;
|
||||
pollin = execute(cmd.str(), "[POLLIN]");
|
||||
});
|
||||
|
||||
poll_out_thread.join();
|
||||
poll_in_thread.join();
|
||||
cerr << pollout.console_out << pollin.console_out;
|
||||
|
||||
exit(pollout.exit_code + pollin.exit_code);
|
||||
}
|
||||
|
||||
TEST(Poller, ZeroMQ_subchannel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("zeromq", 0), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(Poller, Nanomsg_subchannel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("nanomsg", 0), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
TEST(Poller, ShMem_subchannel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("shmem", 0), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
|
||||
TEST(Poller, ZeroMQ_channel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("zeromq", 1), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(Poller, Nanomsg_channel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("nanomsg", 1), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
TEST(Poller, ShMem_channel)
|
||||
{
|
||||
EXPECT_EXIT(RunPoller("shmem", 1), ::testing::ExitedWithCode(0), "POLL test successfull");
|
||||
}
|
||||
|
||||
} // namespace
|
70
test/protocols/_pub_sub.cxx
Normal file
70
test/protocols/_pub_sub.cxx
Normal file
@@ -0,0 +1,70 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunPubSub(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto pub = execute_result{"", 0};
|
||||
thread pub_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pub_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
pub = execute(cmd.str(), "[PUB]");
|
||||
});
|
||||
|
||||
auto sub1 = execute_result{"", 0};
|
||||
thread sub1_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id sub_1" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
sub1 = execute(cmd.str(), "[SUB1]");
|
||||
});
|
||||
|
||||
auto sub2 = execute_result{"", 0};
|
||||
thread sub2_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id sub_2" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
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;
|
||||
|
||||
exit(pub.exit_code + sub1.exit_code + sub2.exit_code);
|
||||
}
|
||||
|
||||
TEST(PubSub, ZeroMQ)
|
||||
{
|
||||
EXPECT_EXIT(RunPubSub("zeromq"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PubSub, Nanomsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPubSub("nanomsg"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
66
test/protocols/_push_pull.cxx
Normal file
66
test/protocols/_push_pull.cxx
Normal file
@@ -0,0 +1,66 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunPushPull(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto push = execute_result{"", 100};
|
||||
thread push_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id push_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
push = execute(cmd.str(), "[PUSH]");
|
||||
});
|
||||
|
||||
auto pull = execute_result{"", 100};
|
||||
thread pull_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pull_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
pull = execute(cmd.str(), "[PULL]");
|
||||
});
|
||||
|
||||
push_thread.join();
|
||||
pull_thread.join();
|
||||
cerr << push.console_out << pull.console_out;
|
||||
|
||||
exit(push.exit_code + pull.exit_code);
|
||||
}
|
||||
|
||||
TEST(PushPull, MP_ZeroMQ__tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPushPull("zeromq"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
|
||||
}
|
||||
|
||||
TEST(PushPull, MP_ShMem___tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPushPull("shmem"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PushPull, MP_Nanomsg_tcp____SingleMsg)
|
||||
{
|
||||
EXPECT_EXIT(RunPushPull("nanomsg"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
174
test/protocols/_push_pull_multipart.cxx
Normal file
174
test/protocols/_push_pull_multipart.cxx
Normal file
@@ -0,0 +1,174 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <FairMQChannel.h>
|
||||
#include <FairMQParts.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
auto RunSingleThreadedMultipart(string transport, string address) -> void {
|
||||
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.SetValue<string>("session", std::to_string(session));
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
|
||||
auto push = FairMQChannel{"Push", "push", factory};
|
||||
ASSERT_TRUE(push.Bind(address));
|
||||
auto pull = FairMQChannel{"Pull", "pull", factory};
|
||||
pull.Connect(address);
|
||||
|
||||
// TODO validate that fTransportFactory is not nullptr
|
||||
// TODO validate that fSocket is not nullptr
|
||||
ASSERT_TRUE(push.ValidateChannel());
|
||||
ASSERT_TRUE(pull.ValidateChannel());
|
||||
|
||||
{
|
||||
auto sentMsg = FairMQParts{};
|
||||
sentMsg.AddPart(push.NewSimpleMessage("1"));
|
||||
sentMsg.AddPart(push.NewSimpleMessage("2"));
|
||||
sentMsg.AddPart(push.NewSimpleMessage("3"));
|
||||
|
||||
ASSERT_GE(push.Send(sentMsg), 0);
|
||||
}
|
||||
|
||||
auto receivedMsg = FairMQParts{};
|
||||
ASSERT_GE(pull.Receive(receivedMsg), 0);
|
||||
|
||||
stringstream out;
|
||||
for_each(receivedMsg.cbegin(), receivedMsg.cend(), [&out](const FairMQMessagePtr& part) {
|
||||
out << string{static_cast<char*>(part->GetData()), part->GetSize()};
|
||||
});
|
||||
ASSERT_EQ(out.str(), "123");
|
||||
}
|
||||
|
||||
auto RunMultiThreadedMultipart(string transport, string address) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.SetValue<string>("session", std::to_string(session));
|
||||
config.SetValue<int>("io-threads", 1);
|
||||
config.SetValue<size_t>("shm-segment-size", 20000000);
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
|
||||
auto push = FairMQChannel{"Push", "push", factory};
|
||||
ASSERT_TRUE(push.Bind(address));
|
||||
auto pull = FairMQChannel{"Pull", "pull", factory};
|
||||
pull.Connect(address);
|
||||
|
||||
auto pusher = thread{[&push](){
|
||||
ASSERT_TRUE(push.ValidateChannel());
|
||||
|
||||
auto sentMsg = FairMQParts{};
|
||||
sentMsg.AddPart(push.NewSimpleMessage("1"));
|
||||
sentMsg.AddPart(push.NewSimpleMessage("2"));
|
||||
sentMsg.AddPart(push.NewSimpleMessage("3"));
|
||||
|
||||
ASSERT_GE(push.Send(sentMsg), 0);
|
||||
}};
|
||||
|
||||
auto puller = thread{[&pull](){
|
||||
ASSERT_TRUE(pull.ValidateChannel());
|
||||
|
||||
auto receivedMsg = FairMQParts{};
|
||||
ASSERT_GE(pull.Receive(receivedMsg), 0);
|
||||
|
||||
stringstream out;
|
||||
for_each(receivedMsg.cbegin(), receivedMsg.cend(), [&out](const FairMQMessagePtr& part) {
|
||||
out << string{static_cast<char*>(part->GetData()), part->GetSize()};
|
||||
});
|
||||
ASSERT_EQ(out.str(), "123");
|
||||
}};
|
||||
|
||||
pusher.join();
|
||||
puller.join();
|
||||
}
|
||||
|
||||
TEST(PushPull, ST_ZeroMQ__inproc_Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("zeromq", "inproc://test");
|
||||
}
|
||||
|
||||
TEST(PushPull, ST_Shmem___inproc_Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("shmem", "inproc://test");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PushPull, ST_Nanomsg_inproc_Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("nanomsg", "inproc://test");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
TEST(PushPull, ST_ZeroMQ__ipc____Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("zeromq", "ipc://test_ST_ZeroMQ__ipc____Multipart");
|
||||
}
|
||||
|
||||
TEST(PushPull, ST_Shmen___ipc____Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("shmem", "ipc://test_ST_Shmen___ipc____Multipart");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PushPull, ST_Nanomsg_ipc____Multipart)
|
||||
{
|
||||
RunSingleThreadedMultipart("nanomsg", "ipc://test_ST_Nanomsg_ipc____Multipart");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
TEST(PushPull, MT_ZeroMQ__inproc_Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("zeromq", "inproc://test");
|
||||
}
|
||||
|
||||
TEST(PushPull, MT_Shmem___inproc_Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("shmem", "inproc://test");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PushPull, MT_Nanomsg_inproc_Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("nanomsg", "inproc://test");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
TEST(PushPull, MT_ZeroMQ__ipc____Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("zeromq", "ipc://test_MT_ZeroMQ__ipc____Multipart");
|
||||
}
|
||||
|
||||
TEST(PushPull, MT_Shmem___ipc____Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("shmem", "ipc://test_MT_Shmem___ipc____Multipart");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(PushPull, MT_Nanomsg_ipc____Multipart)
|
||||
{
|
||||
RunMultiThreadedMultipart("nanomsg", "ipc://test_MT_Nanomsg_ipc____Multipart");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
75
test/protocols/_req_rep.cxx
Normal file
75
test/protocols/_req_rep.cxx
Normal file
@@ -0,0 +1,75 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunReqRep(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto rep = execute_result{ "", 0 };
|
||||
thread rep_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id rep_" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
rep = execute(cmd.str(), "[REP]");
|
||||
});
|
||||
|
||||
auto req1 = execute_result{ "", 0 };
|
||||
thread req1_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id req_1" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
req1 = execute(cmd.str(), "[REQ1]");
|
||||
});
|
||||
|
||||
auto req2 = execute_result{ "", 0 };
|
||||
thread req2_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id req_2" << transport << " --control static "
|
||||
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
req2 = execute(cmd.str(), "[REQ2]");
|
||||
});
|
||||
|
||||
rep_thread.join();
|
||||
req1_thread.join();
|
||||
req2_thread.join();
|
||||
cerr << req1.console_out << req2.console_out << rep.console_out;
|
||||
|
||||
exit(req1.exit_code + req2.exit_code + rep.exit_code);
|
||||
}
|
||||
|
||||
TEST(ReqRep, ZeroMQ)
|
||||
{
|
||||
EXPECT_EXIT(RunReqRep("zeromq"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
|
||||
}
|
||||
|
||||
TEST(ReqRep, ShMem)
|
||||
{
|
||||
EXPECT_EXIT(RunReqRep("shmem"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(ReqRep, Nanomsg)
|
||||
{
|
||||
EXPECT_EXIT(RunReqRep("nanomsg"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
51
test/protocols/_transfer_timeout.cxx
Normal file
51
test/protocols/_transfer_timeout.cxx
Normal file
@@ -0,0 +1,51 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq::test;
|
||||
using namespace fair::mq::tools;
|
||||
|
||||
auto RunTransferTimeout(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id transfer_timeout_" << transport << " --control static --transport " << transport
|
||||
<< " --session " << session << " --color false --mq-config \"" << mqConfig << "\"";
|
||||
auto res = execute(cmd.str());
|
||||
|
||||
cerr << res.console_out;
|
||||
|
||||
exit(res.exit_code);
|
||||
}
|
||||
|
||||
TEST(TransferTimeout, ZeroMQ)
|
||||
{
|
||||
EXPECT_EXIT(RunTransferTimeout("zeromq"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
|
||||
}
|
||||
|
||||
TEST(TransferTimeout, ShMem)
|
||||
{
|
||||
EXPECT_EXIT(RunTransferTimeout("shmem"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
|
||||
}
|
||||
|
||||
#ifdef NANOMSG_FOUND
|
||||
TEST(TransferTimeout, Nanomsg)
|
||||
{
|
||||
EXPECT_EXIT(RunTransferTimeout("nanomsg"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
|
||||
}
|
||||
#endif /* NANOMSG_FOUND */
|
||||
|
||||
} // namespace
|
620
test/protocols/config.json.in
Normal file
620
test/protocols/config.json.in
Normal file
@@ -0,0 +1,620 @@
|
||||
{
|
||||
"fairMQOptions": {
|
||||
"devices": [
|
||||
{
|
||||
"id": "pairleft_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5557",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairright_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5557",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairleft_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5757",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairright_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5757",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairleft_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5857",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairright_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5857",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairleft_ofi",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5957",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "ofi",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pairright_ofi",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5957",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "ofi",
|
||||
"type": "pair"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "push_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5557",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pull_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5557",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "push_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5757",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pull_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5757",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "push_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5857",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pull_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5857",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pub_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5556",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5555",
|
||||
"method": "bind",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pub_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5756",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5755",
|
||||
"method": "bind",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sub_1zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5556",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "sub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5555",
|
||||
"method": "connect",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sub_2zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5556",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "sub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5555",
|
||||
"method": "connect",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sub_1nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5756",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "sub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5755",
|
||||
"method": "connect",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sub_2nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5756",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "sub"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5755",
|
||||
"method": "connect",
|
||||
"name": "control",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_1zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5558",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_1nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_2zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5558",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_2nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_1shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "req_2shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "connect",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "req"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "rep_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5558",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "rep"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "rep_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "rep"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "rep_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5758",
|
||||
"method": "bind",
|
||||
"name": "data",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "rep"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "transfer_timeout_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5559",
|
||||
"method": "bind",
|
||||
"name": "data-in",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5560",
|
||||
"method": "bind",
|
||||
"name": "data-out",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "transfer_timeout_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5959",
|
||||
"method": "bind",
|
||||
"name": "data-in",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5960",
|
||||
"method": "bind",
|
||||
"name": "data-out",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "transfer_timeout_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5759",
|
||||
"method": "bind",
|
||||
"name": "data-in",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:5560",
|
||||
"method": "bind",
|
||||
"name": "data-out",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollout_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6000",
|
||||
"method": "bind",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6001",
|
||||
"method": "bind",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollin_zeromq",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6000",
|
||||
"method": "connect",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6001",
|
||||
"method": "connect",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "zeromq",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollout_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6002",
|
||||
"method": "bind",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6003",
|
||||
"method": "bind",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollin_nanomsg",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6002",
|
||||
"method": "connect",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6003",
|
||||
"method": "connect",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "nanomsg",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollout_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6004",
|
||||
"method": "bind",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "push"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6005",
|
||||
"method": "bind",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "push"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pollin_shmem",
|
||||
"channels": [
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6004",
|
||||
"method": "connect",
|
||||
"name": "data1",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pull"
|
||||
},
|
||||
{
|
||||
"address": "tcp://127.0.0.1:6005",
|
||||
"method": "connect",
|
||||
"name": "data2",
|
||||
"rateLogging": 0,
|
||||
"transport": "shmem",
|
||||
"type": "pull"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
37
test/protocols/runner.cxx.in
Normal file
37
test/protocols/runner.cxx.in
Normal file
@@ -0,0 +1,37 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
string runTestDevice = "@RUN_TEST_DEVICE@";
|
||||
string mqConfig = "@MQ_CONFIG@";
|
||||
|
||||
} /* namespace test */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
28
test/protocols/runner.h
Normal file
28
test/protocols/runner.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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_RUNNER_H
|
||||
#define FAIR_MQ_TEST_RUNNER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
extern std::string runTestDevice; /// Path to test device executable.
|
||||
extern std::string mqConfig; /// Path to FairMQ device config file.
|
||||
|
||||
} /* namespace test */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_TEST_RUNNER_H */
|
136
test/state_machine/_state_machine.cxx
Normal file
136
test/state_machine/_state_machine.cxx
Normal file
@@ -0,0 +1,136 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/StateMachine.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
using S = StateMachine::State;
|
||||
using T = StateMachine::StateTransition;
|
||||
|
||||
TEST(StateMachine, RegularFSM)
|
||||
{
|
||||
StateMachine fsm;
|
||||
|
||||
ASSERT_FALSE(fsm.NextStatePending());
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::InitDevice));
|
||||
ASSERT_THROW(fsm.ChangeState(T::InitDevice), StateMachine::IllegalTransition);
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Automatic));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::InitTask));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Automatic));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Run));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Stop));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::ResetTask));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Automatic));
|
||||
|
||||
int cnt{0};
|
||||
fsm.SubscribeToStateQueued("test", [&](S newState, S lastState){
|
||||
++cnt;
|
||||
});
|
||||
|
||||
fsm.SubscribeToStateChange("test", [&](S newState, S lastState){
|
||||
if (newState == S::Idle && lastState == S::ResettingDevice)
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::End));
|
||||
});
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::ResetDevice));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Automatic));
|
||||
|
||||
fsm.UnsubscribeFromStateQueued("test");
|
||||
|
||||
ASSERT_TRUE(fsm.NextStatePending());
|
||||
|
||||
fsm.Run();
|
||||
|
||||
EXPECT_EQ(cnt, 2);
|
||||
}
|
||||
|
||||
TEST(StateMachine, ErrorFSM)
|
||||
{
|
||||
StateMachine fsm;
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::InitDevice));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::Automatic));
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::ErrorFound));
|
||||
|
||||
fsm.Run();
|
||||
}
|
||||
|
||||
TEST(StateMachine, Reset)
|
||||
{
|
||||
StateMachine fsm;
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::End));
|
||||
fsm.Run();
|
||||
|
||||
fsm.Reset();
|
||||
|
||||
ASSERT_NO_THROW(fsm.ChangeState(T::End));
|
||||
fsm.Run();
|
||||
}
|
||||
|
||||
TEST(StateMachine, StateConversions)
|
||||
{
|
||||
StateMachine fsm;
|
||||
EXPECT_NO_THROW(fsm.ToState("OK"));
|
||||
EXPECT_NO_THROW(fsm.ToState("ERROR"));
|
||||
EXPECT_NO_THROW(fsm.ToState("IDLE"));
|
||||
EXPECT_NO_THROW(fsm.ToState("INITIALIZING DEVICE"));
|
||||
EXPECT_NO_THROW(fsm.ToState("DEVICE READY"));
|
||||
EXPECT_NO_THROW(fsm.ToState("INITIALIZING TASK"));
|
||||
EXPECT_NO_THROW(fsm.ToState("READY"));
|
||||
EXPECT_NO_THROW(fsm.ToState("RUNNING"));
|
||||
EXPECT_NO_THROW(fsm.ToState("RESETTING TASK"));
|
||||
EXPECT_NO_THROW(fsm.ToState("RESETTING DEVICE"));
|
||||
EXPECT_NO_THROW(fsm.ToState("EXITING"));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Ok));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Error));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Idle));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::InitializingDevice));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::DeviceReady));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::InitializingTask));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Ready));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Running));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::ResettingTask));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::ResettingDevice));
|
||||
EXPECT_NO_THROW(fsm.ToStr(S::Exiting));
|
||||
}
|
||||
|
||||
TEST(StateMachine, StateTransitionConversions)
|
||||
{
|
||||
StateMachine fsm;
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("INIT DEVICE"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("INIT TASK"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("RUN"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("STOP"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("RESET TASK"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("RESET DEVICE"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("END"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("ERROR FOUND"));
|
||||
EXPECT_NO_THROW(fsm.ToStateTransition("AUTOMATIC"));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::InitDevice));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::InitTask));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::Run));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::Stop));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::ResetTask));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::ResetDevice));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::End));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::ErrorFound));
|
||||
EXPECT_NO_THROW(fsm.ToStr(T::Automatic));
|
||||
}
|
||||
|
||||
} // namespace
|
16
test/state_machine/runner.cxx
Normal file
16
test/state_machine/runner.cxx
Normal file
@@ -0,0 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
auto main(int argc, char** argv) -> int
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Reference in New Issue
Block a user