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