mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
Add more tests for custom main()
This commit is contained in:
parent
2498837b8e
commit
7d5e76dece
|
@ -1,16 +1,10 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
/**
|
|
||||||
* Sampler.cpp
|
|
||||||
*
|
|
||||||
* @since 2014-10-10
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <thread> // this_thread::sleep_for
|
#include <thread> // this_thread::sleep_for
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
/**
|
|
||||||
* FairMQBenchmarkSampler.cpp
|
|
||||||
*
|
|
||||||
* @since 2013-04-23
|
|
||||||
* @author D. Klein, A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "FairMQBenchmarkSampler.h"
|
#include "FairMQBenchmarkSampler.h"
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
/**
|
|
||||||
* FairMQBenchmarkSampler.h
|
|
||||||
*
|
|
||||||
* @since 2013-04-23
|
|
||||||
* @author D. Klein, A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FAIRMQBENCHMARKSAMPLER_H_
|
#ifndef FAIRMQBENCHMARKSAMPLER_H_
|
||||||
#define FAIRMQBENCHMARKSAMPLER_H_
|
#define FAIRMQBENCHMARKSAMPLER_H_
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
# Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||||
# #
|
# #
|
||||||
# This software is distributed under the terms of the #
|
# This software is distributed under the terms of the #
|
||||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||||
|
@ -83,10 +83,10 @@ add_testsuite(FairMQ.Device
|
||||||
SOURCES
|
SOURCES
|
||||||
device/TestSender.h
|
device/TestSender.h
|
||||||
device/TestReceiver.h
|
device/TestReceiver.h
|
||||||
device/TestVersion.h
|
|
||||||
device/runner.cxx
|
device/runner.cxx
|
||||||
device/_multiple_devices.cxx
|
device/_multiple_devices.cxx
|
||||||
device/_device_version.cxx
|
device/_device_version.cxx
|
||||||
|
device/_device_config.cxx
|
||||||
|
|
||||||
LINKS FairMQ
|
LINKS FairMQ
|
||||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/device
|
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/device
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* 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
|
|
122
test/device/_device_config.cxx
Normal file
122
test/device/_device_config.cxx
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/********************************************************************************
|
||||||
|
* 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 <FairMQDevice.h>
|
||||||
|
#include <options/FairMQProgOptions.h>
|
||||||
|
|
||||||
|
#include <fairmq/Tools.h>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <sstream> // std::stringstream
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void control(FairMQDevice& device)
|
||||||
|
{
|
||||||
|
device.ChangeState("INIT_DEVICE");
|
||||||
|
device.WaitForEndOfState("INIT_DEVICE");
|
||||||
|
device.ChangeState("INIT_TASK");
|
||||||
|
device.WaitForEndOfState("INIT_TASK");
|
||||||
|
|
||||||
|
device.ChangeState("RUN");
|
||||||
|
device.WaitForEndOfState("RUN");
|
||||||
|
|
||||||
|
device.ChangeState("RESET_TASK");
|
||||||
|
device.WaitForEndOfState("RESET_TASK");
|
||||||
|
device.ChangeState("RESET_DEVICE");
|
||||||
|
device.WaitForEndOfState("RESET_DEVICE");
|
||||||
|
|
||||||
|
device.ChangeState("END");
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeviceConfig : public ::testing::Test
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceConfig()
|
||||||
|
{}
|
||||||
|
|
||||||
|
string TestDeviceSetConfig(const string& transport)
|
||||||
|
{
|
||||||
|
FairMQProgOptions config;
|
||||||
|
|
||||||
|
vector<string> emptyArgs = {"dummy", "--id", "test", "--color", "false"};
|
||||||
|
|
||||||
|
if (config.ParseAll(emptyArgs, true))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.SetValue<string>("transport", transport);
|
||||||
|
|
||||||
|
FairMQDevice device;
|
||||||
|
device.SetConfig(config);
|
||||||
|
|
||||||
|
FairMQChannel channel;
|
||||||
|
channel.UpdateType("pub");
|
||||||
|
channel.UpdateMethod("connect");
|
||||||
|
channel.UpdateAddress("tcp://localhost:5558");
|
||||||
|
device.AddChannel("data", channel);
|
||||||
|
|
||||||
|
thread t(control, ref(device));
|
||||||
|
|
||||||
|
device.RunStateMachine();
|
||||||
|
|
||||||
|
if (t.joinable())
|
||||||
|
{
|
||||||
|
t.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
return device.GetTransportName();
|
||||||
|
}
|
||||||
|
|
||||||
|
string TestDeviceSetTransport(const string& transport)
|
||||||
|
{
|
||||||
|
FairMQDevice device;
|
||||||
|
device.SetTransport(transport);
|
||||||
|
|
||||||
|
FairMQChannel channel;
|
||||||
|
channel.UpdateType("pub");
|
||||||
|
channel.UpdateMethod("connect");
|
||||||
|
channel.UpdateAddress("tcp://localhost:5558");
|
||||||
|
device.AddChannel("data", channel);
|
||||||
|
|
||||||
|
std::thread t(control, std::ref(device));
|
||||||
|
|
||||||
|
device.RunStateMachine();
|
||||||
|
|
||||||
|
if (t.joinable())
|
||||||
|
{
|
||||||
|
t.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
return device.GetTransportName();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(DeviceConfig, SetConfig)
|
||||||
|
{
|
||||||
|
string transport = "nanomsg";
|
||||||
|
string returnedTransport = TestDeviceSetConfig(transport);
|
||||||
|
|
||||||
|
EXPECT_EQ(transport, returnedTransport);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DeviceConfig, SetTransport)
|
||||||
|
{
|
||||||
|
string transport = "nanomsg";
|
||||||
|
string returnedTransport = TestDeviceSetTransport(transport);
|
||||||
|
|
||||||
|
EXPECT_EQ(transport, returnedTransport);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
|
@ -1,12 +1,12 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#include "TestVersion.h"
|
#include <FairMQDevice.h>
|
||||||
|
|
||||||
#include <fairmq/Tools.h>
|
#include <fairmq/Tools.h>
|
||||||
|
|
||||||
|
@ -19,16 +19,24 @@ namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fair::mq::test;
|
|
||||||
|
|
||||||
class DeviceVersion : public ::testing::Test {
|
class TestVersion : public FairMQDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestVersion(fair::mq::tools::Version version)
|
||||||
|
: FairMQDevice(version)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeviceVersion : public ::testing::Test
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DeviceVersion()
|
DeviceVersion()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
fair::mq::tools::Version TestDeviceVersion()
|
fair::mq::tools::Version TestDeviceVersion()
|
||||||
{
|
{
|
||||||
fair::mq::test::TestVersion versionDevice({1, 2, 3});
|
TestVersion versionDevice({1, 2, 3});
|
||||||
versionDevice.ChangeState("END");
|
versionDevice.ChangeState("END");
|
||||||
|
|
||||||
return versionDevice.GetVersion();
|
return versionDevice.GetVersion();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -51,7 +51,7 @@ class MultipleDevices : public ::testing::Test {
|
||||||
|
|
||||||
FairMQChannel channel("push", "connect", "ipc://multiple-devices-test");
|
FairMQChannel channel("push", "connect", "ipc://multiple-devices-test");
|
||||||
channel.UpdateRateLogging(0);
|
channel.UpdateRateLogging(0);
|
||||||
sender.fChannels["data"].push_back(channel);
|
sender.AddChannel("data", channel);
|
||||||
|
|
||||||
thread t(control, std::ref(sender));
|
thread t(control, std::ref(sender));
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class MultipleDevices : public ::testing::Test {
|
||||||
|
|
||||||
FairMQChannel channel("pull", "bind", "ipc://multiple-devices-test");
|
FairMQChannel channel("pull", "bind", "ipc://multiple-devices-test");
|
||||||
channel.UpdateRateLogging(0);
|
channel.UpdateRateLogging(0);
|
||||||
receiver.fChannels["data"].push_back(channel);
|
receiver.AddChannel("data", channel);
|
||||||
|
|
||||||
thread t(control, std::ref(receiver));
|
thread t(control, std::ref(receiver));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user