refactor tests

* move to gtest
* add shmem tests
* cleanup cmake file (organize tests in suites)
This commit is contained in:
Dennis Klein
2017-03-28 14:19:08 +02:00
committed by Mohammad Al-Turany
parent 55a9d69908
commit 7e34f7042f
38 changed files with 1185 additions and 1298 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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestPub.cxx
*/
#include <FairMQDevice.h>
#include <FairMQLogger.h>
namespace fair
{
namespace mq
{
namespace test
{
class Pub : public FairMQDevice
{
protected:
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(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,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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestPull.cxx
*/
#include <FairMQDevice.h>
#include <FairMQLogger.h>
namespace fair
{
namespace mq
{
namespace test
{
using namespace std;
class Pull : public FairMQDevice
{
protected:
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,33 @@
/********************************************************************************
* 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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestPush.cxx
*/
#include <FairMQDevice.h>
namespace fair
{
namespace mq
{
namespace test
{
class Push : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto msg = FairMQMessagePtr{NewMessage()};
Send(msg, "data");
};
};
} // namespace test
} // namespace mq
} // namespace fair

View File

@@ -0,0 +1,48 @@
/********************************************************************************
* 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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestRep.cxx
*/
#include <FairMQDevice.h>
#include <FairMQLogger.h>
namespace fair
{
namespace mq
{
namespace test
{
class Rep : public FairMQDevice
{
protected:
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,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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestReq.cxx
*/
#include <FairMQDevice.h>
#include <FairMQLogger.h>
namespace fair
{
namespace mq
{
namespace test
{
class Req : public FairMQDevice
{
protected:
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,56 @@
/********************************************************************************
* 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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestSub.cxx
*/
#include <FairMQDevice.h>
#include <FairMQLogger.h>
namespace fair
{
namespace mq
{
namespace test
{
class Sub : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto ready = FairMQMessagePtr{NewMessage()};
auto r1 = Send(ready, "control");
if (r1 >= 0)
{
auto msg = FairMQMessagePtr{NewMessage()};
auto d1 = Receive(msg, "data");
if (d1 >= 0)
{
auto ack = FairMQMessagePtr{NewMessage()};
auto a1 = Send(ack, "control");
if (a1 < 0)
{
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,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" *
********************************************************************************/
/**
* @file fairmq/test/helper/devices/TestTransferTimeout.cxx
*/
#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,69 @@
/********************************************************************************
* 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" *
********************************************************************************/
/**
* @file fairmq/test/helper/runTestDevice.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
{
}
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
{
cerr << "Don't know id '" << id << "'" << endl;
return nullptr;
}
}