Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+301
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* SRP Function Topic test executable
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-01-14
|
||||
*/
|
||||
|
||||
#include "srp_ft_tests.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include <SituationReplay/srp_ftc.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
namespace SituationReplay
|
||||
{
|
||||
|
||||
SrpFtTests::SrpFtTests(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_replayPartitionId(0)
|
||||
, m_testId(All)
|
||||
, m_bTestsSuccessful(true)
|
||||
, m_logger(getLogger("FtTest"))
|
||||
{
|
||||
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
SrpFtTests::~SrpFtTests()
|
||||
{}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
bool SrpFtTests::init(int domainId, TestId testId, int replayPartitionId, int srpId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "init begin";
|
||||
|
||||
m_testId = testId;
|
||||
m_replayPartitionId = replayPartitionId;
|
||||
|
||||
if (m_testId > 0)
|
||||
m_situationReplayId = srpId;
|
||||
|
||||
// initialize DDS
|
||||
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Replay, m_replayPartitionId));
|
||||
if (!m_ddsConnector->init())
|
||||
return false;
|
||||
|
||||
|
||||
// Publish/Subscribe on replayPartition
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
DEBUG_LOG(m_logger) << "create ftc";
|
||||
m_ftc = SituationReplay::Interface::Ftc::create(m_ddsConnector);
|
||||
DEBUG_LOG(m_logger) << "init ftc";
|
||||
bool bRet = m_ftc->enableAll();
|
||||
DEBUG_LOG(m_logger) << "init end - bRet = " << bRet;
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::startTest()
|
||||
{
|
||||
INFO_LOG(m_logger) << "startTest";
|
||||
|
||||
if (m_testId <= TryStart)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryStart);
|
||||
else if (m_testId == TryNotAllowedChange)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryNotAllowedChange);
|
||||
else if (m_testId == TryChangePaused)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryChangePaused);
|
||||
else if (m_testId == TryChangeResumed)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryChangeResumed);
|
||||
else if (m_testId == TryStop)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryStop);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::tryStart()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send startReplay";
|
||||
m_currentTestId = TryStart;
|
||||
|
||||
qint64 beginTime = 1468401389668;
|
||||
qint64 endTime = 1468401659954;
|
||||
double pace = 2.0;
|
||||
|
||||
ChangeReplayStateRequest req;
|
||||
req.id(0);
|
||||
req.replayPartitionId(m_replayPartitionId);
|
||||
req.state(SrpState::Started);
|
||||
req.beginTime(beginTime);
|
||||
req.endTime(endTime); // infinite
|
||||
req.pace(pace);
|
||||
|
||||
if (!m_ftc->changeReplayStateRequest(req, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error starting replay for srp " << m_replayPartitionId;
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::tryNotAllowedChange()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send changeReplayState (start) => should fail (not possible with this method)";
|
||||
m_currentTestId = TryNotAllowedChange;
|
||||
switchToState(SituationReplay::SrpState::Started);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::tryChangePaused()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send changeReplayState (Paused)";
|
||||
m_currentTestId = TryChangePaused;
|
||||
switchToState(SituationReplay::SrpState::Paused);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::tryChangeResumed()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send changeReplayState (Resumed)";
|
||||
m_currentTestId = TryChangeResumed;
|
||||
switchToState(SituationReplay::SrpState::Resumed);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::tryStop()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send stopReplay";
|
||||
m_currentTestId = TryStop;
|
||||
switchToState(SituationReplay::SrpState::Stopped);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::startReplayReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got startReplayReply with id " << replyObject.id();
|
||||
m_situationReplayId = replyObject.id();
|
||||
if (m_testId == 0 && !replyObject.error())
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryNotAllowedChange);
|
||||
else
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::changeReplayStateReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got changeReplayStateReply with id " << replyObject.id();
|
||||
if (replyObject.error())
|
||||
INFO_LOG(m_logger) << ", string: " << replyObject.translated();
|
||||
if (m_testId == 0 && !replyObject.error())
|
||||
{
|
||||
if (m_currentTestId == TryNotAllowedChange)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryChangePaused);
|
||||
else if (m_currentTestId == TryChangePaused)
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryChangeResumed);
|
||||
else
|
||||
QTimer::singleShot(0, this, &SrpFtTests::tryStop);
|
||||
}
|
||||
else
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::stopReplayReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got stopReplayReply with id " << replyObject.id() ;
|
||||
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::onChangeReplayStateReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
switch (m_currentTestId)
|
||||
{
|
||||
case TryStart:
|
||||
startReplayReply(replyObject);
|
||||
break;
|
||||
case TryNotAllowedChange:
|
||||
case TryChangePaused:
|
||||
case TryChangeResumed:
|
||||
changeReplayStateReply(replyObject);
|
||||
break;
|
||||
case TryStop:
|
||||
stopReplayReply(replyObject);
|
||||
break;
|
||||
case All:
|
||||
changeReplayStateReply(replyObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void SrpFtTests::failExit()
|
||||
{
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
void SrpFtTests::switchToState(SrpState state)
|
||||
{
|
||||
ChangeReplayStateRequest req;
|
||||
req.id(m_situationReplayId);
|
||||
req.replayPartitionId(m_replayPartitionId);
|
||||
req.state(state);
|
||||
|
||||
if (!m_ftc->changeReplayStateRequest(req, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error changing replay state for srp " << m_situationReplayId << "(" << m_replayPartitionId << ")";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
} // end namespace
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
addOption( { QStringList() << QLatin1String("t") << QLatin1String("testId")
|
||||
, QLatin1String("TestId.")
|
||||
, QLatin1String("Default: 0 (all tests)")
|
||||
, QLatin1String("0")
|
||||
} );
|
||||
|
||||
addOption( { QStringList() << QLatin1String("p") << QLatin1String("replayPartitionId")
|
||||
, QLatin1String("ReplayPartitionId.")
|
||||
, QLatin1String("required")
|
||||
, QLatin1String("0")
|
||||
} );
|
||||
|
||||
addOption( { QStringList() << QLatin1String("r") << QLatin1String("situationReplayId")
|
||||
, QLatin1String("SituationReplayId.")
|
||||
, QLatin1String("optional")
|
||||
, QLatin1String("0")
|
||||
} );
|
||||
|
||||
addHelpOption();
|
||||
}
|
||||
|
||||
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; }
|
||||
int replayPartitionId() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; }
|
||||
int situationReplayId() const { return isSet(QLatin1String("r")) ? value(QLatin1String("r")).toInt() : -1; }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("SRP", "log4cxx_srp.props");
|
||||
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
return -1;
|
||||
|
||||
if (options.exerciseId() <= 0 || options.replayPartitionId() <= 0)
|
||||
{
|
||||
ERROR_LOG(app.baseLogger()) << "Required parameter: exerciseId & replayPartitionId ";
|
||||
options.showHelp();
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (options.testId() > 0 && options.situationReplayId() <= 0)
|
||||
{
|
||||
ERROR_LOG(app.baseLogger()) << "Required parameter for single test: situationReplayId ";
|
||||
options.showHelp();
|
||||
return -2;
|
||||
}
|
||||
|
||||
std::unique_ptr<SituationReplay::SrpFtTests> SrpFtTests(new SituationReplay::SrpFtTests);
|
||||
|
||||
int iRet = -1;
|
||||
if(!SrpFtTests->init(options.domainId(), SituationReplay::SrpFtTests::TestId(options.testId()),
|
||||
options.replayPartitionId(), options.situationReplayId()))
|
||||
return iRet;
|
||||
|
||||
QTimer::singleShot(0, SrpFtTests.get(), &SituationReplay::SrpFtTests::startTest);
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
app.exec();
|
||||
|
||||
iRet = SrpFtTests->testsSuccessful() ? 0 : 1;
|
||||
fprintf(stderr, "%d\n", iRet);
|
||||
|
||||
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
|
||||
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
|
||||
return iRet;
|
||||
}
|
||||
Reference in new issue
Block a user