Move test directory one up

This commit is contained in:
Dennis Klein
2018-04-12 17:46:18 +02:00
parent 33fffb1644
commit 2327fd2115
51 changed files with 21 additions and 85 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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>

View 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 */

View 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>

View 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 */

View 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;
}
}