Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
#
# $Id$
# $HeadURL$
# $Author$
#
SET(SRCS_DT_TEST
data_topic_tests.cpp
data_topic_tests_main.cpp
log4cxx_scm_unit_tests.props
)
SET(HDRS_DT_TEST
data_topic_tests.h
data_topic_tests_main.h
)
IF(BUILD_TESTING AND TARGET svcScmCommon)
# Testing DataTopic Functionality (DTS/DTC)
ADD_EXECUTABLE(scmDtUnitTest ${SRCS_DT_TEST} ${HDRS_DT_TEST})
TARGET_LINK_LIBRARIES(scmDtUnitTest
nglcoreapplication
NGLLogger
RTI::nddscpp2
svcScmCommon
ddsgen
ddsdts
ddsdtc
ddsQoS
ProjectConfig
Qt5::Core
Qt5::Test
)
ADD_TEST(NAME scmDtUnitTest COMMAND $<TARGET_FILE:scmDtUnitTest>)
IF(NOT BUILD_RPM)
NGL_INSTALL(AAR SV TARGETS scmDtUnitTest DESTINATION bin/test)
NGL_INSTALL(AAR SV FILES log4cxx_scm_unit_tests.props DESTINATION bin/test)
ENDIF()
ENDIF()
@@ -0,0 +1,244 @@
/**
* @RDE_HEADER@
* Unit test for ServiceManagement (SCM)
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2015-03-14
*/
#include "data_topic_tests.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <DDS/QosProfile/DDS_DefaultQos.h>
#include <Common/ProjectConfig/project_defines.h>
#include <DDS/DTS/generic_dts_impl.h>
#include <DDS/DTC/generic_dtc_impl.h>
#include <QtTest/QTest>
#include <QVariant>
#include <QThread>
DataTopicTests::DataTopicTests()
: m_domainParticipantPub(nullptr)
, m_domainParticipantSub(nullptr)
, m_domainId(0)
, m_ddsPublisher(nullptr)
, m_dtsServiceInformation(nullptr)
, m_dtsGroupInformation(nullptr)
, m_ddsSubscriber(nullptr)
, m_subscriberListener(nullptr)
, m_subscriberListenerBinder(nullptr)
, m_dtcServiceInformation(nullptr)
, m_dtcGroupInformation(nullptr)
, m_mainThreadId(QThread::currentThreadId())
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.DataTopicTests"))
{
if (!DDS::QosProfile::setDefault())
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
DEBUG_LOG(m_logger) << "Main thread ID is " << m_mainThreadId;
}
DataTopicTests::~DataTopicTests()
{
// Publisher
delete m_dtsServiceInformation;
delete m_dtsGroupInformation;
// Subscriber
delete m_dtcServiceInformation;
delete m_dtcGroupInformation;
m_subscriberListener->prepareShutdown();
m_subscriberListenerBinder = nullptr;
m_ddsSubscriber = nullptr;
m_ddsPublisher = nullptr;
m_domainParticipantSub = nullptr;
m_domainParticipantPub = nullptr;
}
/**
* Publisher
**/
bool DataTopicTests::initPublisher()
{
m_domainParticipantPub =
dds::domain::DomainParticipant(m_domainId,
DDS::QosProfile::domainParticipantShm());
dds::pub::qos::PublisherQos publisherQos = m_domainParticipantPub.default_publisher_qos();
// ExerciseData will be published to Partition 0
// use only selected partition
const std::string partition = IDL::exercisePartition(0);
dds::core::policy::Partition partitionQos;
partitionQos.name( { partition } );
publisherQos << partitionQos;
DEBUG_LOG(m_logger) << "Publish on partition " << partition;
m_ddsPublisher = dds::pub::Publisher(m_domainParticipantPub, publisherQos);
// Create DTSs
m_dtsServiceInformation = new DTS::ServiceInformationImpl(m_domainParticipantPub, m_ddsPublisher);
m_dtsGroupInformation = new DTS::GroupInformationImpl(m_domainParticipantPub, m_ddsPublisher);
return true;
}
bool DataTopicTests::write(const ServiceManagement::ServiceInformation &data)
{
INFO_LOG(m_logger) << "Publish topic ServiceInformation ";
DEBUG_LOG(m_logger) << "Id: " << data.id()
<< ", Name: " << data.name()
<< ", State: " << data.state()
<< ", Timestamp: " << data.timestamp()
<< ", ErrorString: " << data.errorString()
;
return m_dtsServiceInformation->write(data);
}
bool DataTopicTests::write(const ServiceManagement::GroupInformation &data)
{
INFO_LOG(m_logger) << "Publish topic GroupInformation ";
if(m_logger.isDebugEnabled())
{
QString services;
for(int serviceId : data.services())
{
services.append(QString::number(serviceId));
services.append(QLatin1Char(','));
}
if(services.endsWith(QLatin1Char(',')))
services.chop(1);
DEBUG_LOG(m_logger) << "Type: " << data.type()
<< ", Domain: " << data.domainId()
<< ", Partition: " << data.exercisePartitionId()
<< ", Partition: " << data.replayPartitionId()
<< ", Services: " << services
<< ", Timestamp: " << data.timestamp();
}
return m_dtsGroupInformation->write(data);
}
ServiceManagement::ServiceInformation DataTopicTests::getReceivedServiceInformationData() const
{
return m_receivedServiceInformationData;
}
ServiceManagement::GroupInformation DataTopicTests::getReceivedGroupInformationData() const
{
return m_receivedGroupInformationData;
}
void DataTopicTests::processData(const ServiceManagement::ServiceInformation &instance, DataModification modType)
{
Q_UNUSED(modType);
INFO_LOG(m_logger) << "process Lts_ServiceInformation";
DEBUG_LOG(m_logger) << "Id: " << instance.id();
DEBUG_LOG(m_logger) << "Name: " << instance.name();
DEBUG_LOG(m_logger) << "State: " << instance.state();
DEBUG_LOG(m_logger) << "Timestamp: " << instance.timestamp();
DEBUG_LOG(m_logger) << "ErrorString: " << instance.errorString();
m_receivedServiceInformationData = instance;
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
emit serviceInformationDataArrived();
}
void DataTopicTests::processData(const ServiceManagement::GroupInformation &instance, DataModification modType)
{
Q_UNUSED(modType);
INFO_LOG(m_logger) << "process Lts_ServiceInformation";
if(m_logger.isDebugEnabled())
{
QString services;
for(int serviceId : instance.services())
{
services.append(QString::number(serviceId));
services.append(QLatin1Char(','));
}
if(services.endsWith(QLatin1Char(',')))
services.chop(1);
DEBUG_LOG(m_logger) << "Type: " << instance.type();
DEBUG_LOG(m_logger) << "Domain: " << instance.domainId();
DEBUG_LOG(m_logger) << "Partition: " << instance.exercisePartitionId();
DEBUG_LOG(m_logger) << "Replay Partition: " << instance.replayPartitionId();
DEBUG_LOG(m_logger) << "Services: " << services;
DEBUG_LOG(m_logger) << "Timestamp: " << instance.timestamp();
}
m_receivedGroupInformationData = instance;
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
emit groupInformationDataArrived();
}
/**
* Subscriber
**/
bool DataTopicTests::initSubscriber()
{
DEBUG_LOG(m_logger) << "Initialisation DDS (Subscriber/Reader)";
m_domainParticipantSub =
dds::domain::DomainParticipant(m_domainId,
DDS::QosProfile::domainParticipantShm());
dds::sub::qos::SubscriberQos subscriberQos = m_domainParticipantSub.default_subscriber_qos();
// Initial Partition for listening on topic Exercise => partition 0
// + Listening for Topics in partition 1
dds::core::StringSeq partitions;
partitions.reserve(2);
for(int partitionId : { 0, 1 } )
{
partitions.push_back(IDL::exercisePartition(partitionId));
}
dds::core::policy::Partition partitionQos;
partitionQos.name( partitions );
subscriberQos << partitionQos;
DEBUG_LOG(m_logger) << "Initialise DTC::SubscriberListener";
m_subscriberListener = new DDSGeneric::SubscriberListener;
m_ddsSubscriber = dds::sub::Subscriber(m_domainParticipantSub,
subscriberQos);
m_subscriberListenerBinder = rti::core::bind_and_manage_listener(m_ddsSubscriber,
m_subscriberListener,
DDSGeneric::SubscriberListener::mask());
// Initialise DTCs
m_dtcServiceInformation = new DTC::ServiceInformationImpl(m_domainParticipantSub, m_ddsSubscriber, m_subscriberListener);
m_dtcGroupInformation = new DTC::GroupInformationImpl(m_domainParticipantSub, m_ddsSubscriber, m_subscriberListener);
m_dtcServiceInformation->setSubscriberCallback([this] (const ServiceManagement::ServiceInformation &data, DataModification modType) { processData(data, modType); } );
m_dtcGroupInformation->setSubscriberCallback([this] (const ServiceManagement::GroupInformation &data, DataModification modType) { processData(data, modType); } );
return true;
}
@@ -0,0 +1,81 @@
/**
* @RDE_HEADER@
* Unit test for ServiceManagement (SCM)
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2015-03-14
*/
#pragma once
#include <QObject>
// For Topic Exercise
#include <ServiceManagement/scm_dtc_types.h>
#include <ServiceManagement/scm_dts_types.h>
#include <ServiceManagement/scm.hpp>
#include <DDS/Generic/subscriber_listener.h>
#include <LtsUtilsCore/data_modification_enum.h>
#include <rti/core/ListenerBinder.hpp>
namespace NGL {
class INGLLogger;
}
class DataTopicTests : public QObject
{
Q_OBJECT
public:
DataTopicTests();
virtual ~DataTopicTests();
// Initialisation
bool initPublisher();
bool initSubscriber();
// Publisher
bool write(const ServiceManagement::ServiceInformation &data);
bool write(const ServiceManagement::GroupInformation &data);
// Subscriber
ServiceManagement::ServiceInformation getReceivedServiceInformationData() const;
ServiceManagement::GroupInformation getReceivedGroupInformationData() const;
protected:
// Subscriber Methods
void processData(const ServiceManagement::ServiceInformation& instance, DataModification modType);
void processData(const ServiceManagement::GroupInformation& instance, DataModification modType);
Q_SIGNALS:
void serviceInformationDataArrived();
void groupInformationDataArrived();
private:
dds::domain::DomainParticipant m_domainParticipantPub;
dds::domain::DomainParticipant m_domainParticipantSub;
int m_domainId;
// Publisher
dds::pub::Publisher m_ddsPublisher;
DTS::ServiceInformation *m_dtsServiceInformation;
DTS::GroupInformation *m_dtsGroupInformation;
// Subscriber
dds::sub::Subscriber m_ddsSubscriber;
DDSGeneric::SubscriberListener *m_subscriberListener;
rti::core::ListenerBinder< dds::sub::Subscriber, dds::sub::SubscriberListener> m_subscriberListenerBinder;
DTC::ServiceInformation *m_dtcServiceInformation;
DTC::GroupInformation *m_dtcGroupInformation;
Qt::HANDLE m_mainThreadId;
// For returning TestData
ServiceManagement::ServiceInformation m_receivedServiceInformationData;
ServiceManagement::GroupInformation m_receivedGroupInformationData;
NGL::INGLLogger& m_logger;
};
@@ -0,0 +1,120 @@
/**
* @RDE_HEADER@
* UnitTests for ExerciseManagement (EXM)
* $Id$
* $HeadURL$
* $Author$
* Created by Hanna E. Rathje, SLSE, 2015-08-20
*/
#include "data_topic_tests_main.h"
#include "data_topic_tests.h"
#include <Common/ProjectConfig/project_defines.h>
#include <QtTest/QTest>
#include <nglapplication/nglcoreapplication.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
int main(int argc, char *argv[])
{
NGLCoreApplication app(argc, argv);
app.createLogger("UnitTests", "log4cxx_exm_unit_tests.props");
DataTopicTestsMain *tc = new DataTopicTestsMain;
int retCode = QTest::qExec(tc, argc, argv);
delete tc;
return retCode;
}
DataTopicTestsMain::DataTopicTestsMain()
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.DataTopicTestsMain"))
{
}
void DataTopicTestsMain::initTestCase()
{
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: initTestCase";
m_dtTest = new DataTopicTests();
QVERIFY2(m_dtTest, "Initialisation of DataTopicTest failed");
QVERIFY2(m_dtTest->initPublisher(), "Initialisation Publisher failed");
QVERIFY2(m_dtTest->initSubscriber(), "Initialisation Subscriber failed");
m_serviceInformationDataArrivedSpy = new QSignalSpy(m_dtTest, &DataTopicTests::serviceInformationDataArrived);
m_groupInformationDataArrivedSpy = new QSignalSpy(m_dtTest, &DataTopicTests::groupInformationDataArrived);
}
void DataTopicTestsMain::publishServiceInformationTestCase()
{
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: publish ServiceInformation data";
// Topic ServiceInformation
m_sentServiceInformationData.id(13);
m_sentServiceInformationData.name("UnitTest dummy Service");
m_sentServiceInformationData.state(Core::RunningState::inner_enum::NotYetStarted);
m_sentServiceInformationData.timestamp(QDateTime::currentMSecsSinceEpoch());
m_sentServiceInformationData.errorString(QStringLiteral("UnitTest dummy Error").toStdString());
QVERIFY2(m_dtTest->write(m_sentServiceInformationData), "Publishing Topic ServiceInformation failed");
}
void DataTopicTestsMain::subscribeServiceInformationTestCase()
{
DEBUG_LOG(m_logger) << "IN subscribeServiceInformationTestCase";
QTRY_COMPARE(m_serviceInformationDataArrivedSpy->count(), 1);
ServiceManagement::ServiceInformation recvServiceInformation = m_dtTest->getReceivedServiceInformationData();
QCOMPARE(recvServiceInformation.id(), m_sentServiceInformationData.id());
QCOMPARE(recvServiceInformation.name(), m_sentServiceInformationData.name());
QCOMPARE(recvServiceInformation.state(), m_sentServiceInformationData.state());
QCOMPARE(recvServiceInformation.timestamp(), m_sentServiceInformationData.timestamp());
QCOMPARE(recvServiceInformation.errorString(), m_sentServiceInformationData.errorString());
}
void DataTopicTestsMain::publishGroupInformationTestCase()
{
DEBUG_LOG(m_logger) << "DataTopicTestsMain: publish GroupInformation data";
std::vector<int> services = {1, 3, 5, 7, 11, 13, 17, 19, 23, 42};
// Topic GroupInformation
m_sentGroupInformationData.type(Core::ServiceGroupType::inner_enum::Master);
m_sentGroupInformationData.exercisePartitionId(113);
m_sentGroupInformationData.domainId(42);
m_sentGroupInformationData.services(services);
m_sentGroupInformationData.timestamp(QDateTime::currentMSecsSinceEpoch());
QVERIFY2(m_dtTest->write(m_sentGroupInformationData), "Publishing Topic GroupInformation failed");
}
void DataTopicTestsMain::subscribeGroupInformationTestCase()
{
DEBUG_LOG(m_logger) << "IN subscribeGroupInformationTestCase";
QTRY_COMPARE(m_groupInformationDataArrivedSpy->count(), 1);
ServiceManagement::GroupInformation recvGroupInformation = m_dtTest->getReceivedGroupInformationData();
QCOMPARE(recvGroupInformation.type(), m_sentGroupInformationData.type());
QCOMPARE(recvGroupInformation.exercisePartitionId(), m_sentGroupInformationData.exercisePartitionId());
QCOMPARE(recvGroupInformation.domainId(), m_sentGroupInformationData.domainId());
QCOMPARE(recvGroupInformation.services(), m_sentGroupInformationData.services());
QCOMPARE(recvGroupInformation.timestamp(), m_sentGroupInformationData.timestamp());
}
void DataTopicTestsMain::cleanupTestCase()
{
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: cleanupTestCase";
delete m_dtTest; m_dtTest = nullptr;
delete m_serviceInformationDataArrivedSpy; m_serviceInformationDataArrivedSpy = nullptr;
delete m_groupInformationDataArrivedSpy; m_groupInformationDataArrivedSpy = nullptr;
}
@@ -0,0 +1,45 @@
/**
* @RDE_HEADER@
* UnitTests for ExerciseManagement (EXM)
* $Id$
* $HeadURL$
* $Author$
* Created by Hanna E. Rathje, SLSE, 2015-08-20
*/
#pragma once
#include <QObject>
#include <QSignalSpy>
#include <ServiceManagement/scm_dts_types.h>
namespace NGL
{
class INGLLogger;
}
class DataTopicTests;
class DataTopicTestsMain : public QObject
{
Q_OBJECT
public:
DataTopicTestsMain();
private Q_SLOTS:
void initTestCase();
void publishServiceInformationTestCase();
void subscribeServiceInformationTestCase();
void publishGroupInformationTestCase();
void subscribeGroupInformationTestCase();
void cleanupTestCase();
protected:
private:
ServiceManagement::ServiceInformation m_sentServiceInformationData;
ServiceManagement::GroupInformation m_sentGroupInformationData;
QSignalSpy *m_serviceInformationDataArrivedSpy = nullptr;
QSignalSpy *m_groupInformationDataArrivedSpy = nullptr;
DataTopicTests *m_dtTest = nullptr;
NGL::INGLLogger &m_logger;
};
@@ -0,0 +1,109 @@
log4j.reset=true
log4j.rootLogger=WARN, file
# Service: ServiceManagement
###########################################################
log4j.logger.UnitTests.main=WARN
# GenericDataTests
log4j.logger.UnitTests.Initialisation=WARN
log4j.logger.UnitTests.GenericDataTests=WARN
# DataTopicTests
log4j.logger.UnitTests.DataTopicTestsMain=WARN
log4j.logger.UnitTests.DataTopicTests=WARN
# FunctionTopicTests
log4j.logger.UnitTests.FtTest=INFO
# Generic
log4j.logger.GenericBase=WARN
log4j.logger.Generic.DataWriter=WARN
log4j.logger.Generic.DataReader=WARN
log4j.logger.Generic.DroTypeInfo=WARN
# DTCs
log4j.logger.Generic.DTC=WARN
log4j.logger.DTC.SubscriberListener=WARN
log4j.logger.DTC.Topic=WARN
log4j.logger.DTC=WARN
# FTSs / FTCs
log4j.logger.FTS=WARN
log4j.logger.FTC=INFO
log4j.logger.Generic.FTS=WARN
log4j.logger.Generic.FTC=INFO
# connext (request/reply feature)
log4j.logger.connext=WARN
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=9
log4j.appender.file.file=${LOG4QT_LOGDIR}/${LOG4QT_USER}_dds_unittests.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
# Appnd_Console
###########################################################
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d %p %c %c{1} - %m (%-.30F:%L) %n
# Appnd_Syslog
###########################################################
log4j.appender.syslog=org.apache.log4j.SyslogAppender
log4j.appender.syslog.Threshold=ERROR
log4j.appender.syslog.SysLogHost=localhost
log4j.appender.syslog.Facility=LOCAL7
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
###########################################################
###########################################################
###########################################################
# 1) Available Levels in LOG4CXX Version 0.10.0:
# TRACE,
# DEBUG,
# INFO,
# WARN,
# ERROR
# FATAL
#
# d = date/time
# p = priority (Level)
# c = category/channel
# m = message
# F = file
# L = line
# n = platform dependent line separator character or characters.
# ....
#
# Examples for console:
# a)
# %d %p %c #%m# (%.50F:%L)%n
# date/time
# priority
# category/channel
# #message#
# (Maximal 50Character des Filename von rechts:Line)
# line separator
#
# b)
# %d (%.15F:%L) %-5p %c |#| %m%n
# date/time
# (Maximal 15Character des Filename von rechts:Line)
# priority, Right pad with spaces if the priority name is less than 5 characters long.
# category/channel
# message
# line separator
#
# Examples for files: