DDS Test Helpers API Reference
test_helper.h
1/*
2 * (c) Copyright, Real-Time Innovations, 2023.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef ddsctesthelpers_testHelper_h
12#define ddsctesthelpers_testHelper_h
13
14#include "rtitest/test_setting.h"
15#include "dds_c/dds_c_typecode.h"
16#include "ndds/ndds_config_c.h"
17#include "ndds/ndds_transport_c.h"
18#include "dds_c/dds_c_publication.h"
19#include "dds_c/dds_c_subscription.h"
20#include "dds_c/dds_c_trust_plugins.h"
21#include "pres/pres_readerQueue.h"
22#include "commend/commend_readerService.h"
23#include "disc/disc_simple_discovery_plugin.h"
24#include "clock/clock_mock.h"
25
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define DDSC_TESTER_DEFAULT_LIB "BuiltinQosLib"
41#define DDSC_TESTER_DEFAULT_PROFILE "Baseline"
42
43/*
44 * RTI_OSAPI_THREAD_STACK_SIZE_DEFAULT is sufficient for internal threads such
45 * as the event and receive threads, but sometimes you need to use
46 * DDS_C_TEST_THREAD_STACK_SIZE_DEFAULT for threads that directly call DDS
47 * APIs.
48 */
49#ifdef RTI_VXWORKS
50 /*
51 * This number comes from the "Core Libraries Getting Started Guide Addendum
52 * for Embedded Systems", "Getting Started on VxWorks Systems" chapter,
53 * "Building and Running a Hello World Example" section, "Building and
54 * Running an Application as a Real-Time Process" subsection.
55 */
56 #define DDS_C_TEST_THREAD_STACK_SIZE_DEFAULT (0x100000)
57#else
58 #define DDS_C_TEST_THREAD_STACK_SIZE_DEFAULT \
59 RTI_OSAPI_THREAD_STACK_SIZE_DEFAULT
60#endif
61
62#define DDS_C_TEST_DSN_MAX_LENGTH 100
63#define DDS_C_TEST_LIBNAME_MAX_LENGTH 255
64#define DDS_C_TEST_MAX_TEST_DATABASES 10
65
66#define DDS_C_TEST_HELPER_LOGGER_DEVICE_DATA_MAX_SUBSTRINGS 10
67
68/*
69 * PREDIX-283: With current configuration, we make sure we do not reuse
70 * ports for the domains in range 0-199. We map the ports to the range
71 * [55005-57004]. We are starting in 55005 so we avoid collisions with service
72 * running on ubuntu on 55002.
73 */
74#define DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_BASE 55005
75#define DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_RANGE 2000
76#define DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_RANGE_PER_DOMAIN 10
77
78#define DDSCTestHelper_calculateReceivePort(domainId__, offset__) \
79 (DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_BASE + (offset__) + \
80 ((DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_RANGE_PER_DOMAIN * (domainId__)) \
81 % DDS_C_TEST_HELPER_MULTICHANNEL_RECEIVE_PORT_RANGE))
82
83struct DDSCTesterHelperLoggerDeviceData {
84 unsigned int foundMessages;
85 /*
86 * The expected log message. The device will increase foundMessages if a
87 * log message matches expectedMessage.
88 */
89 const char *expectedMessage;
90 /*
91 * Match against a non-constant string that can be modified at run-time.
92 * The log first has to match against expectedMessage. If that happens and
93 * additionalMessage is not NULL, a match for additionalMessage is also
94 * looked for.
95 */
96 const char *additionalMessage;
97 /*
98 * The expected substrings in the log messages. The device will
99 * increase foundMessages if a log message contains all of the
100 * expectedSubStrings.
101 *
102 * If expectedSubStrings is set, expectedMessage and additionalMessage
103 * are ignored. expectedSubStrings is preferred over expectedMessage and
104 * additionalMessage.
105 */
106 const char *expectedSubStrings[DDS_C_TEST_HELPER_LOGGER_DEVICE_DATA_MAX_SUBSTRINGS];
107 /*
108 * Use this semaphore when multiple participants are concurrently producing
109 * the expected log message. In that case, two participants may try to
110 * increment foundMessages at the same time, and the final result could be
111 * that foundMessages is only incremented once. So we need a mutex to
112 * protect foundMessages.
113 *
114 * Use it as well when your test changes the expected message at runtime.
115 * DDSCTesterHelperLoggerDeviceData_changeExpectedMessage takes care of it.
116 */
117 struct RTIOsapiSemaphore *semaphore;
118 /*
119 * When a DomainParticipant is created in licensed builds, a log message
120 * with the license information is printed. This boolean indicates
121 * whether we want to ignore that message or not.
122 * By default, it is set to RTI_TRUE;
123 */
124 RTIBool ignoreLicenseRelatedMessages;
125};
126
127#define DDSCTesterHelperLoggerDeviceData_INITIALIZER(expectedMessage__) { \
128 0, /* foundMessages */ \
129 (expectedMessage__), \
130 NULL, /* additionalMessage */ \
131 {NULL}, /* expectedSubStrings */ \
132 NULL, /* semaphore */ \
133 RTI_TRUE /* ignoreLicenseRelatedMessages */ \
134}
135
136#define DDSCTesterHelperLoggerDeviceDataPropertyValidation_INITIALIZER \
137 DDSCTesterHelperLoggerDeviceData_INITIALIZER("Unexpected property")
138
139extern DDSCTESTDllExport void DDSCTesterHelper_loggerDeviceWrite(
140 struct NDDS_Config_LoggerDevice *device,
141 const struct NDDS_Config_LogMessage *message);
142
143extern DDSCTESTDllExport void DDSCTesterHelperLoggerDeviceData_finalize(
144 struct DDSCTesterHelperLoggerDeviceData *deviceData);
145
146extern DDSCTESTDllExport RTIBool DDSCTesterHelperLoggerDeviceData_initialize(
147 struct DDSCTesterHelperLoggerDeviceData *deviceData);
148
149/*
150 * Update the expected message safely when you may get multiple occurrences of
151 * the previous expected message. Use it when the previous and the new expected
152 * messages may be logged very closely together in time.
153 *
154 * This function takes the logger device data semaphore before changing the
155 * expected message, and gives it afterwards. Doing so prevents against race
156 * conditions in DDSCTesterHelper_loggerDeviceWrite between matching of the
157 * expectedMessage and increments of the foundMessages:
158 * - A match happens for the (old) expectedMessage.
159 * - foundMessage becomes true.
160 * - We change the expectedMessage and reset foundMessages to 0.
161 * - foundMessages is increased because of the match with the old
162 * expectedMessage.
163 */
164extern DDSCTESTDllExport RTIBool
165DDSCTesterHelperLoggerDeviceData_changeExpectedMessage(
166 struct DDSCTesterHelperLoggerDeviceData *deviceData,
167 const char *expectedMessage);
168
169/*
170 * Caches the logging configuration so it can be restored later.
171 *
172 * This function is not thread safe: it should only be called in the tester main
173 * thread.
174 */
175extern DDSCTESTDllExport RTIBool
176DDSCTesterHelper_cacheLoggingConfiguration(void);
177
178/*
179 * Restores a cached logging configuration.
180 *
181 * This function is not thread safe: it should only be called in the tester main
182 * thread, and only after a successful call to
183 * DDSCTesterHelper_cacheLoggingConfiguration.
184 */
185extern DDSCTESTDllExport RTIBool
186DDSCTesterHelper_restoreLoggingConfiguration(void);
187
188/*
189 * Gets the instanceHandle of a participant so that another participant can
190 * refer to it when calling APIs.
191 */
192extern DDSCTESTDllExport RTIBool DDSCTesterHelper_getParticipantInstanceHandle(
193 DDS_InstanceHandle_t *instanceHandle,
194 DDS_DomainParticipant *participant);
195
196struct RTIDDSCTestOdbcDatabaseInfo {
197 char DSN[DDS_C_TEST_DSN_MAX_LENGTH];
198 char odbcDatabaseLib[DDS_C_TEST_LIBNAME_MAX_LENGTH];
199};
200
201/*
202 * If you modify this structure, make sure you properly update both dds_c and
203 * security initializers (this includes all the different versions of
204 * RTIDDSCTestSetting_init and the RTISecurityTestSetting_init function).
205 */
206struct RTIDDSCTestSetting {
207 struct RTITestSetting parent;
208 int numOdbcDatabases;
209 int odbcDatabaseIndex;
210 struct RTIDDSCTestOdbcDatabaseInfo
211 testOdbcDatabaseInfo[DDS_C_TEST_MAX_TEST_DATABASES];
212 const char *libraryName;
213 const char *profileName;
214};
215
222extern DDSCTESTDllExport RTIBool
224
225/*
226 * @brief Sets the builtin_discovery_plugins in the default domain participant
227 * profile and caches the current value.
228 *
229 * @param plugins In. Plugins to set default to.
230 * @param cachedPlugins Out. Previous value of plugins in default profile.
231 *
232 * @return RTI_TRUE if success, RTI_FALSE if failure.
233 */
234extern DDSCTESTDllExport RTIBool
235DDSCTesterHelper_setAndCacheDefaultDomainParticipantQosDiscoveryPlugins(
236 DDS_DiscoveryConfigBuiltinPluginKindMask plugins,
237 DDS_DiscoveryConfigBuiltinPluginKindMask *cachedPlugins);
238
250Public DDSCTESTDllExport RTIBool
251DDSCTesterHelper_skipInlineQos(struct RTICdrStream *stream, RTI_UINT8 flags);
252
264Public DDSCTESTDllExport RTIBool DDSCTesterHelper_isRemoteEndpointMatched(
265 DDS_DomainParticipant *localParticipant,
266 MIGRtpsObjectId localEndpointOid,
267 struct MIGRtpsGuid *remoteEndpointGuid,
268 RTIBool requiresCompatibility);
269
277Public DDSCTESTDllExport void
278DDSCDomainParticipantTrustPluginsTester_securityCreate(
279 struct DDS_TrustPluginSuite **security,
280 const struct DDS_PropertyQosPolicy *properties);
281
282extern DDSCTESTDllExport RTIBool
283DDSCTestHelper_initializeFactoryQosForXMLWithExtraProfileFile(
284 const struct RTITestSetting *setting,
285 struct DDS_DomainParticipantFactoryQos *factoryQos,
286 const char *extraProfileFile);
287
288extern DDSCTESTDllExport RTIBool DDSCTestHelper_initializeFactoryQosForXML(
289 const struct RTITestSetting *setting,
290 struct DDS_DomainParticipantFactoryQos *factoryQos);
291
292extern DDSCTESTDllExport
293RTIBool DDSCTestHelper_initializeMultiChannelQosPolicy(
294 struct DDS_MultiChannelQosPolicy *policy,
295 DDS_DomainId_t domainId,
296 RTIBool keyed);
297
298extern DDSCTESTDllExport RTIBool
299DDSCTestHelper_configureFactoryWithSingleXmlFile(
300 const struct RTITestSetting *setting,
301 const char *profileFile);
302
303extern DDSCTESTDllExport void DDSCTestHelper_finalizeFactoryQosForXML(void);
304
305extern DDSCTESTDllExport RTIBool
306DDSCTestHelper_DomainParticipantFactoryQosEquals(
307 const struct DDS_DomainParticipantFactoryQos *left,
308 const struct DDS_DomainParticipantFactoryQos *right);
309
310extern DDSCTESTDllExport RTIBool DDSCTestHelper_DomainParticipantQosEquals(
311 struct DDS_DomainParticipantQos *left,
312 const struct DDS_DomainParticipantQos *right);
313
314extern DDSCTESTDllExport RTIBool DDSCTestHelper_DataWriterQosEquals(
315 struct DDS_DataWriterQos *left,
316 const struct DDS_DataWriterQos *right);
317
318extern DDSCTESTDllExport RTIBool DDSCTestHelper_PublisherQosEquals(
319 const struct DDS_PublisherQos *left,
320 const struct DDS_PublisherQos *right);
321
322extern DDSCTESTDllExport RTIBool DDSCTestHelper_DataReaderQosEquals(
323 struct DDS_DataReaderQos *left,
324 const struct DDS_DataReaderQos *right);
325
326extern DDSCTESTDllExport RTIBool DDSCTestHelper_SubscriberQosEquals(
327 const struct DDS_SubscriberQos *left,
328 const struct DDS_SubscriberQos *right);
329
330extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestHelper_waitForData(
331 int numSamples,
332 DDS_DataReader *reader,
333 int timeoutSecs);
334
335extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestHelper_waitForDataAdv(
336 int numSamples,
337 DDS_DataReader *reader,
338 int timeoutSecs,
339 RTIBool timeoutIsExpected);
340
350extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestHelper_waitForDispose(
351 int numDisposed,
352 DDS_DataReader *reader,
353 int timeoutSecs);
354
365extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestHelper_waitForAck(
366 DDS_DataWriter *writer,
367 DDS_DataReader *reader,
368 int timeoutSecs);
369
370extern DDSCTESTDllExport struct DDS_TypeCode *
371DDSCTestHelper_getTypeCodeFromXMLFile(
372 const char *typeName,
373 const char *fileName,
374 const char *filePath);
375
376extern DDSCTESTDllExport struct DDS_TypeObject *
377DDSCTestHelper_getTypeObjectFromXMLFile(
378 const char *typeName,
379 const char *fileName,
380 const char *filePath);
381
382extern DDSCTESTDllExport struct DDS_TypeObjectV2 *
383DDSCTestHelper_getTypeObjectV2FromXMLFile(
384 const char *typeName,
385 const char *fileName,
386 const char *filePath);
387
388extern DDSCTESTDllExport void
389DDSCTestHelperParticipantQos_disableTypePropagation(
390 struct DDS_DomainParticipantQos *participantQos);
391
392extern DDSCTESTDllExport RTIBool
393DDSCTestHelperParticipantQos_typePropagationDisabled(
394 const struct DDS_DomainParticipantQos *participantQos);
395
396extern DDSCTESTDllExport RTIBool DDSCTestHelperParticipantQos_setEndianness(
397 struct DDS_DomainParticipantQos *participantQos,
398 MIGGeneratorEndian endian);
399
400extern DDSCTESTDllExport void DDSCTestHelperEntity_printWithGuid(
401 DDS_Entity *entity,
402 const char *stringToPrint);
403
404/*
405 * Get instance handles of fully discovered participants and the count.
406 *
407 * @param participant Local participant to get discovered participants of.
408 * @param discPartSeqPtr Out. Populated with instance handles of discovered
409 * remote participants.
410 *
411 * @return Number of fully discovered participants.
412 */
413extern DDSCTESTDllExport int
414DDSCDomainParticipantTester_getDiscoveredParticipants(
415 DDS_DomainParticipant *participant,
416 struct DDS_InstanceHandleSeq *discPartSeqPtr);
417
418/*
419 * Get instance handles of partially discovered participants and the count.
420 *
421 * @param participant Local participant to get discovered participants of.
422 * @param discPartSeqPtr Out. Populated with instance handles of discovered
423 * remote participants.
424 *
425 * @return Number of partially discovered participants.
426 */
427extern DDSCTESTDllExport int
428DDSCDomainParticipantTester_getPartiallyDiscoveredParticipants(
429 DDS_DomainParticipant *participant,
430 struct DDS_InstanceHandleSeq *discPartSeqPtr);
431
432extern DDSCTESTDllExport RTIBool
433DDSCTestHelperUdpv4Property_setOnlyLoopbackAllowed(
434 struct NDDS_Transport_UDPv4_Property_t *udpv4Property);
435
436extern DDSCTESTDllExport RTIBool
437DDSCTestHelperUdpv4Property_setNoInterfacesAllowed(
438 struct NDDS_Transport_UDPv4_Property_t *udpv4Property);
439
440extern DDSCTESTDllExport void DDSCTestHelperUdpv4Property_finalizeInterfaceList(
441 struct NDDS_Transport_UDPv4_Property_t *udpv4Property);
442
443extern DDSCTESTDllExport RTIBool DDSCTestHelper_setDefaultQosFromProfile(
444 DDS_DomainParticipant *participant,
445 DDS_Publisher *publisher,
446 DDS_Subscriber *subscriber,
447 const char *libraryName,
448 const char *profileName);
449
450extern DDSCTESTDllExport RTITestReturnCode DDSCTestHelper_runTestWithQoSProfile(
451 const struct RTITestSetting *setting,
452 const char *libraryName,
453 const char *profileName,
454 RTITestFunction testFunction);
455
456extern DDSCTESTDllExport RTITestReturnCode
457DDSCTestHelper_runTestWithDiscoveryPlugins(
458 const struct RTITestSetting *setting,
459 const char *METHOD_NAME,
460 RTITestFunction testToRun,
461 DDS_DiscoveryConfigBuiltinPluginKindMask plugins);
462
463#define DDSCTestHelper_runTestWithSpdp2(setting__, METHOD_NAME__, testToRun__) \
464 DDSCTestHelper_runTestWithDiscoveryPlugins( \
465 (setting__), \
466 (METHOD_NAME__), \
467 (testToRun__), \
468 DDS_DISCOVERYCONFIG_BUILTIN_SDP2)
469
470extern DDSCTESTDllExport RTIBool DDSCTestHelper_fileExistsInResourceDir(
471 const struct RTITestSetting *setting,
472 const char *fileName);
473
496extern DDSCTESTDllExport RTIBool
497DDSCTesterHelper_ignoreExternalRemoteDomainParticipant(
498 DDS_DataReader *reader,
499 struct DDS_ParticipantBuiltinTopicData *participantData,
500 struct DDS_SampleInfo *sampleInfo,
501 RTIBool *participantIgnored);
502
503extern DDSCTESTDllExport RTIBool
504DDSCTesterTypeCodeHelper_initialize_enum_member(
505 struct DDS_EnumMemberSeq *members,
506 DDS_Long index,
507 const char *name,
508 DDS_Long ordinal);
509
510extern DDSCTESTDllExport RTIBool DDSCTesterTypeCodeHelper_finalize_enum_member(
511 struct DDS_EnumMemberSeq *members,
512 DDS_Long index);
513
514extern DDSCTESTDllExport RTIBool
515DDSCTesterTypeCodeHelper_initialize_union_member(
516 struct DDS_UnionMemberSeq *members,
517 DDS_Long index,
518 const char *name,
519 struct DDS_LongSeq *labels,
520 DDS_TypeCode *tc);
521
522extern DDSCTESTDllExport RTIBool DDSCTesterTypeCodeHelper_finalize_union_member(
523 struct DDS_UnionMemberSeq *members,
524 DDS_Long index);
525
526extern DDSCTESTDllExport RTIBool
527DDSCTesterTypeCodeHelper_initialize_value_member(
528 struct DDS_ValueMemberSeq *members,
529 DDS_Long index,
530 const char *name,
531 DDS_Boolean isKey,
532 DDS_Boolean isOptional,
533 DDS_TypeCode *tc,
534 DDS_Visibility access);
535
536extern DDSCTESTDllExport RTIBool DDSCTesterTypeCodeHelper_finalize_value_member(
537 struct DDS_ValueMemberSeq *members,
538 DDS_Long index);
539
540extern DDSCTESTDllExport RTIBool DDSCTesterTypeCodeHelper_initialize_st_member(
541 struct DDS_StructMemberSeq *stMembers,
542 DDS_Long index,
543 const char *name,
544 DDS_Boolean isKey,
545 DDS_Long id,
546 DDS_Boolean isOptional,
547 DDS_TypeCode *tc);
548
549extern DDSCTESTDllExport RTIBool DDSCTesterTypeCodeHelper_finalize_st_member(
550 struct DDS_StructMemberSeq *stMembers,
551 DDS_Long index);
552
567extern DDSCTESTDllExport RTIBool DDSCTestHelper_blockTransportSend(
568 DDS_DomainParticipant *participant,
569 NDDS_Transport_Send_Fcn *oldSendFunction,
570 const char *transportName);
571
578extern DDSCTESTDllExport RTIBool DDSCTestHelper_unblockTransportSend(
579 DDS_DomainParticipant *participant,
580 NDDS_Transport_Send_Fcn oldSendFunction,
581 const char *transportName);
582
592RTIBool DDSCTestHelper_blockReceiveFromParticipant(
593 DDS_DomainParticipant *participant,
594 DDS_DomainParticipant *participantToBlock,
595 DDS_TransportBuiltinKind transportKind);
596
606RTIBool DDSCTestHelper_unblockReceiveFromParticipant(
607 DDS_DomainParticipant *participant,
608 DDS_TransportBuiltinKind transportKind);
609
610/*
611 * @brief Get the value of some internal state in the reader queue.
612 *
613 * @param reader the reader to get the queue from
614 * @param topicQueryGuid if you would like access to a specific topic query
615 * queue instead of the live data queue pass in a non-nil guid for the
616 * topic query. passing in DDS_GUID_UNKNOWN for the topicQueryGuid param
617 * will return the live data reader queue
618 * @param status the status to populate with various counters from the queue
619 *
620 * @return DDS_BOOLEAN_TRUE on success. DDS_BOOLEAN_FALSE on failure, most
621 * likely because the queue is not found
622 */
623extern DDSCTESTDllExport
624DDS_Boolean DDSCTestHelper_getDataReaderQueueStatus(
625 DDS_DataReader *reader,
626 const struct DDS_GUID_t *topicQueryGuid,
627 PRESReaderQueueStatus *status);
628
643DDS_Boolean DDSCTestHelper_dataReaderRemoteWriterQueueExists(
644 DDS_DataReader *reader,
645 const struct DDS_GUID_t *topicQueryGuid,
646 const struct DDS_GUID_t *writerGuid);
647
648/*
649 * @brief Get the value of some internal state in the remote writer queue.
650 *
651 * @param reader the reader to get the queue from
652 * @param topicQueryGuid if you would like access to a specific topic query
653 * queue instead of the live data queue pass in a non-nil guid for the
654 * topic query. passing in DDS_GUID_UNKNOWN for the topicQueryGuid param
655 * will return the live data reader queue
656 * @param writerGuid the guid of the remote writer to look the count up for
657 * @param status the status to populate with various counters from the queue
658 *
659 * @return DDS_BOOLEAN_TRUE on success. DDS_BOOLEAN_FALSE on failure, most
660 * likely because the queue is not found
661 */
662extern DDSCTESTDllExport
663DDS_Boolean DDSCTestHelper_getDataReaderRemoteWriterQueueStatus(
664 DDS_DataReader *reader,
665 const struct DDS_GUID_t *topicQueryGuid,
666 const struct DDS_GUID_t *writerGuid,
667 PRESReaderQueueRemoteWriterQueueStatus *status);
668
669extern DDSCTESTDllExport RTIBool
670DDSCTestHelper_checkDataReaderInstanceStatistics(
671 const struct DDS_DataReaderCacheStatus *expected,
672 const struct DDS_DataReaderCacheStatus *actual);
673
674extern DDSCTESTDllExport RTIBool
675DDSCTestHelper_checkDataWriterInstanceStatistics(
676 const struct DDS_DataWriterCacheStatus *expected,
677 const struct DDS_DataWriterCacheStatus *actual);
678
679extern DDSCTESTDllExport int DDSCTestHelper_getUDPv4interfacesCount(
680 DDS_DomainParticipant *self,
681 NDDS_Transport_ClassId_t transport);
682
683extern DDSCTESTDllExport
684RTIBool DDSCTestHelper_setSubmessageLength(
685 struct RTICdrStream *stream, /* out */
686 struct REDABuffer *buffers, /* in */
687 RTI_UINT16 newLength);
688
689extern DDSCTESTDllExport RTIBool DDSCTestHelper_positionStreamToBinaryProperty(
690 struct RTICdrStream *stream,
691 char *buffer,
692 RTI_INT32 bufferLength,
693 const char *propertyName);
694
695extern DDSCTESTDllExport RTIBool
696DDSCTestHelper_positionStreamToNextPid(struct RTICdrStream *stream);
697
698extern DDSCTESTDllExport RTIBool DDSCTestHelper_positionStreamToPid(
699 struct RTICdrStream *stream,
700 struct REDABuffer *buffer,
701 MIGRtpsParameterId pidToFind,
702 RTIBool skipEncapsulation);
703
717extern DDSCTESTDllExport DDS_ReturnCode_t
718DDSCTestHelper_positionBufferToSubmessageId(
719 struct REDABuffer *bufferOut,
720 int *bytesSkipped,
721 const struct REDABuffer *bufferIn,
722 MIGRtpsSubmessageId requestedSubmessageId);
723
724extern DDSCTESTDllExport void
725DDSCTestHelper_onAfterRemoteParticipantAuthenticatedCheckLiveliness(
726 struct DISCParticipantDiscoveryListener *listener,
727 struct DISCParticipantDiscoveryPlugin *plugin,
728 const struct DISCBuiltinTopicParticipantData *data,
729 const struct DISCPluginCustomOptions *pluginOptions,
730 const struct DISCPluginListenerStorage *listenerStorage,
731 struct REDAWorker *worker);
732
733struct DDSCTestHelper_onDataAvailableListenerStorage {
734 int nonSecureAliveSamplesReceived;
735 int secureAliveSamplesReceived;
736 int nonSecureDisposeSamplesReceived;
737 int secureDisposeSamplesReceived;
738 struct PRESParticipantChannelReaderListener originalListener;
739};
740
741
742#define DDSCTestHelper_onDataAvailableListenerStorage_INITIALIZER \
743 { \
744 0, /* nonSecureAliveSamplesReceived */ \
745 0, /* secureAliveSamplesReceived */ \
746 0, /* nonSecureDisposeSamplesReceived */ \
747 0, /* secureDisposeSamplesReceived */ \
748 PRESParticipantChannelReaderListener_INITIALIZER /* originalListener */ \
749 }
750
751extern DDSCTESTDllExport RTIBool
752DDSCTestHelper_setTestOnAfterRemoteParticipantAuthenticated(
753 DDS_DomainParticipant *participant,
754 RTIBool *result,
755 RTIBool shutdownLivelinessOnAuth,
756 DISCParticipantDiscoveryListenerOnAfterRemoteParticipantAuthenticatedCallback
757 onAfterRemoteParticipantAuthenticated);
758
759extern DDSCTESTDllExport RTIBool
760DDSCDomainParticipantQos_setTestSPDP2LivelinessQosPolicies(
761 struct DDS_DomainParticipantQos *participantQos,
762 int initialParticipantAnnouncements,
763 const struct DDS_Duration_t *minInitialParticipantAnnouncementPeriod,
764 const struct DDS_Duration_t *maxInitialParticipantAnnouncementPeriod,
765 const struct DDS_Duration_t *participantLivelinessAssertPeriod,
766 const struct DDS_Duration_t *participantAnnouncementPeriod,
767 const struct DDS_Duration_t *participantLivelinessLeaseDuration,
768 const struct DDS_Duration_t *maxLivelinessLossDetectionPeriod,
769 const struct DDS_Duration_t *secureVolatileWriterFastHeartBeatPeriod);
770
771struct DDSCTestHelperDirectedWriteListenerData {
772 RTIBool success;
773 PRESDirectedWriteSerializationKind serializationKind;
774 RTIBool isRti;
775 RTIBool isRtps24;
776 RTIBool delayPublicationDiscovery;
777 struct PRESProductVersion *productVersion;
778 struct MIGRtpsGuid *guid;
779};
780
781#define DDSCTestHelperDirectedWriteListenerData_INITIALIZER \
782 { \
783 RTI_FALSE, /* success */ \
784 PRES_DIRECTED_WRITE_AUTO_SERIALIZATION, /* serializationKind */ \
785 RTI_FALSE, /* isRti */ \
786 RTI_FALSE, /* isRtps24 */ \
787 RTI_FALSE, /* delayPublicationDiscovery */ \
788 NULL, /* productVersion */ \
789 NULL /* guid */ \
790 }
791
792extern DDSCTESTDllExport void
793DDSCTestHelper_onBeforeFlushChangeVendorIdAndProtocolVersion(
794 void *ldata,
795 struct REDABuffer *buffers,
796 int bufferCount,
797 const struct MIGRtpsGuid *senderParticipantId);
798
799extern DDSCTESTDllExport void
800DDSCTestHelper_onBeforeEndSubmessageChangeVendorId(
801 void *ldata,
802 struct REDABuffer *buffers,
803 int bufferCount,
804 MIGRtpsSubmessageId submessageId,
805 const struct MIGRtpsGuid *senderGuid);
806
807extern DDSCTESTDllExport void DDSCTestHelper_setupNonRtiTamperingListener(
808 struct MIGGeneratorListener *listener,
809 struct DDSCTestHelperDirectedWriteListenerData *listenerData,
810 RTIBool isUsingSecurity);
811
812struct DDSCTestHelperVendorBuiltinEndpointsListenerData {
813 DDS_UnsignedLong expectedVendorBuiltinEndpoints;
814 RTIBool result;
815};
816
817#define DDSCTestHelperVendorBuiltinEndpointsListenerData_INITIALIZER \
818 { \
819 0, /* expectedVendorBuiltinEndpoints */ \
820 RTI_FALSE /* result */ \
821 }
822
823extern DDSCTESTDllExport void
824DDSCTestHelper_checkVendorBuiltinEndpointsOnBeforeEndSubmessage(
825 void *ldata,
826 struct REDABuffer *buffers,
827 int bufferCount,
828 MIGRtpsSubmessageId submessageId,
829 const struct MIGRtpsGuid *senderGuid);
830
831extern DDSCTESTDllExport RTIBool
832DDSCTestHelper_setAndCacheAutoEnableCreatedEntities(
833 DDS_Boolean *cachedValue,
834 DDS_Boolean setValue);
835
836extern DDSCTESTDllExport RTIBool DDSCTestHelper_setBuiltinReaderListener(
837 DDS_DomainParticipant *participant,
838 const char *builtinTopicName,
839 const struct DDS_DataReaderListener *listener,
840 DDS_StatusMask listenerStatusMask);
841
842typedef struct DDSCTestHelperLocatorCheckerListenerData {
843 struct DDS_Locator_t expectedLocator;
844 /*
845 * Set to RTI_TRUE by the participant builtin listener to indicate that
846 * it discovered a participant with a locator equals to expectedLocator.
847 */
848 RTIBool locatorFound;
849 RTI_INT32 maxLocatorExpected;
850 RTIBool error;
851} DDSCTestHelperLocatorCheckerListenerData;
852
853/*
854 * The constant static variable DDS_LOCATOR_INVALID can not be used to
855 * initialize a structure as some compilers.
856 */
857#define DDSC_TEST_HELPER_DDS_LOCATOR_INVALID { \
858 -1, /* kind */ \
859 0, /* port */ \
860 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* address */ \
861 DDS_SEQUENCE_INITIALIZER /* encapsulations */ \
862}
863
864#define DDSCTestHelperLocatorCheckerListenerData_INITIALIZER { \
865 DDSC_TEST_HELPER_DDS_LOCATOR_INVALID, /* expectedLocator */ \
866 RTI_FALSE, /* locatorFound */ \
867 RTI_INT32_MAX, /* maxLocatorExpected */ \
868 RTI_FALSE /* error */ \
869}
870
871extern DDSCTESTDllExport void
872DDSCTestHelper_onDataAvailableParticipantLocatorChecker(
873 void *listener_data,
874 DDS_DataReader *reader);
875
876extern DDSCTESTDllExport void
877DDSCTestHelper_onDataAvailableSubscriptionLocatorChecker(
878 void *listener_data,
879 DDS_DataReader *reader);
880
881extern DDSCTESTDllExport void
882DDSCTestHelper_onDataAvailablePublicationLocatorChecker(
883 void *listener_data,
884 DDS_DataReader *reader);
885
886extern DDSCTESTDllExport struct RTIClock *DDSCTestHelper_installMockClock(
887 const struct RTIMockClockProperty *mockClockProperty);
888
889extern DDSCTESTDllExport DDS_Boolean DDSCTestHelper_uninstallMockClock(
890 struct RTIClock *clock);
891
892extern DDSCTESTDllExport
893RTIBool DDSCTestHelper_setTestParticipantDiscOnDataAvailable(
894 DDS_DomainParticipant *participant,
895 MIGRtpsObjectId readerObjectId,
896 MIGRtpsObjectId secureReaderObjectId,
897 struct DDSCTestHelper_onDataAvailableListenerStorage *listenerStorage,
898 PRESPsReaderListenerOnDataAvailableCallback onDataAvailable);
899
900extern DDSCTESTDllExport
901RTIBool DDSCTestHelper_getRemoteParticipantData(
902 DDS_DomainParticipant *participant,
903 struct DDS_ParticipantBuiltinTopicData *participantData,
904 DDS_DomainParticipant *remoteParticipant);
905
906extern DDSCTESTDllExport
907MIGRtpsObjectId DDSCTestHelper_getWriterObjectIdInFlush(
908 struct REDABuffer *buffers,
909 const int bufferCount);
910
911/*
912 * FUZZ TESTING RELATED
913 */
914
915typedef enum {
916 DDS_C_TEST_HELPER_NO_LOG_EXPECTED = 0,
917 DDS_C_TEST_HELPER_EXPECTED_WARNING = 1,
918 DDS_C_TEST_HELPER_EXPECTED_ERROR = 2
919} DDSCTestHelperExpectedLogging;
920
921/*
922 * @brief Reads a binary file named fileName, which should be located in
923 * dds_c.1.0/resource/fuzzerTestFiles, and store the content in data.
924 * @pre The tester must be able to open file. We can use
925 * RTITestSetting_fileTestIsSupport to verify this.
926 * @param setting \b In. Test settings.
927 * @param data \b Out. Array where the file content will be stored. Should be
928 * NULL and should be freed after use it.
929 * @param size \b Out. Size of the file content. Cannot be NULL.
930 * @param fileName \b In. File name of the packet. It should be located in
931 * dds_c.1.0/resource/fuzzerTestFiles.
932 * @return DDS_RETCODE_OK if success, DDS_RETCODE_UNSUPPORTED if we don't have
933 * available a file system, DDS_RETCODE_ERROR otherwise.
934 */
935extern DDSCTESTDllExport
936DDS_ReturnCode_t DDSCTestHelper_readFuzzInputFile(
937 const struct RTITestSetting *setting,
938 unsigned char **data,
939 size_t *size,
940 const char *fileName);
941
957extern DDSCTESTDllExport
958DDS_ReturnCode_t DDSCTestHelper_copyStringAndNullTerminate(
959 char **dest,
960 const RTI_UINT8 *src,
961 size_t size);
962
963/*
964 * END OF FUZZ TESTING RELATED
965 */
966
967/*
968 * Enum used by
969 * DDSCDomainParticipantDiscoverySpdp2Tester_testSpdp2NoConfigNewParticipantWithParams
970 * and
971 * DDSCBuiltinUdpv4WanTester_testSpdp2NoConfigNewParticipantWithParams
972 * to determine when to call add_peer() with an existing locator.
973 */
974typedef enum {
975 /* Do not call add_peer(), existing locator should be on initial_peers */
976 DDSC_SPDP2_TESTER_NO_ADD_PEER,
977 /*
978 * Call add_peer() before rediscovering a new participant with the same
979 * locators
980 */
981 DDSC_SPDP2_TESTER_ADD_PEER_BEFORE_REDISCOVERY,
982 /*
983 * Call add_peer() after rediscovering a new participant with the same
984 * locators
985 */
986 DDSC_SPDP2_TESTER_ADD_PEER_AFTER_REDISCOVERY
987} DDSCDomainParticipantDiscoverySpdp2TesterAddPeerTestCase;
988
989/*
990 * Used with
991 * DDSCTestHelper_onBeforeEndSubmessageTamperData
992 * and
993 * RTI_Security_DomainParticipantSpdp2Tester_onBeforeEndSubmessageTamperConfigChannel
994 * to test a lost sample on the config channel or on the secure volatile
995 * channel.
996 */
997Package struct DDSCTestHelperTamperingListenerData {
998 /* Set to true if there is a failure when tampering the data */
999 RTIBool error;
1000 /*
1001 * If this is true we will corrupt the data section of messages from
1002 * writerToCorrupt
1003 */
1004 RTIBool corruptData;
1005 /*
1006 * If this is true we will corrupt the INFO_DST of messages from
1007 * writerToCorrupt with the matching destGuidToCorrupt.
1008 */
1009 RTIBool corruptInfoDst;
1010 /*
1011 * If this is true and corruptData is true we will corrupt either
1012 * the related writer guid or the related reader guid of messages sent
1013 * by writerToCorrupt.
1014 */
1015 RTIBool corruptRelatedEntityGuid;
1016 /* Object ID of the writer to corrupt outgoing messages on */
1017 MIGRtpsObjectId writerToCorrupt;
1018 /*
1019 * This field is used to either corrupt messages with an INFO_DST going
1020 * to this GUID (in nonsecure tests, through
1021 * DDSCTestHelper_onBeforeFlushTamperInfoDst) OR to corrupt secure volatile
1022 * messages related to this endpoint (in secure tests, through
1023 * DDSCTestHelper_onBeforeEndSubmessageTamperData).
1024 *
1025 * To corrupt the INFO_DST, corruptInfoDst must also be true. To corrupt
1026 * the secure volatile messages, corruptData must also be true.
1027 */
1028 struct MIGRtpsGuid destGuidToCorrupt;
1029 /*
1030 * Set to TRUE when the first message is corrupted, use this to ensure
1031 * you don't move on before a corrupted message is sent
1032 */
1033 RTIBool messageCorrupted;
1034};
1035
1036#define DDSCTestHelperTamperingListenerData_INITIALIZER \
1037 { \
1038 RTI_FALSE, /* error */ \
1039 RTI_FALSE, /* corruptData */ \
1040 RTI_FALSE, /* corruptInfoDst */ \
1041 RTI_FALSE, /* corruptRelatedEntityGuid */ \
1042 MIG_RTPS_OBJECT_ID_UNKNOWN, /* writerToCorrupt */ \
1043 MIG_RTPS_GUID_UNKNOWN, /* destGuidToCorrupt */ \
1044 RTI_FALSE /* messageCorrupted */ \
1045 }
1046
1047/*
1048 * Tampers the submessage ID of a DATA submessage to cause it to be dropped
1049 * if listenerData->writerToCorrupt matches the writer OID of the sender or its
1050 * secure counterpart.
1051 *
1052 * @param lData Listener data
1053 * @param buffers Pointer to buffers
1054 * @param bufferCount Number of buffers
1055 * @param submessageId Submessage ID of the message being tampered
1056 * @param senderGuid GUID of the writer sending the message
1057 */
1058void DDSCTestHelper_onBeforeEndSubmessageTamperData(
1059 void *lData,
1060 struct REDABuffer *buffers,
1061 int bufferCount,
1062 MIGRtpsSubmessageId submessageId,
1063 const struct MIGRtpsGuid *senderGuid);
1064
1065/*
1066 * If the first submessage is an INFO_DST attached to a large message (> 128
1067 * bytes) tamper the message. If listenerData->destGuidToCorrupt is set,
1068 * only tamper the message if the destination GUID matches. Otherwise tamper
1069 * all large INFO_DST messages.
1070 *
1071 * @param lData Listener data
1072 * @param buffers Pointer to buffers
1073 * @param bufferCount Number of buffers
1074 * @param submessageId Submessage ID of the message being tampered
1075 * @param senderGuid GUID of the writer sending the message
1076
1077 */
1078void DDSCTestHelper_onBeforeFlushTamperInfoDst(
1079 /* inouts */
1080 void *listenerData,
1081 struct REDABuffer *buffers,
1082 /* inputs */
1083 int bufferCount,
1084 const struct MIGRtpsGuid *senderParticipantId);
1085
1086extern DDSCTESTDllExport
1087RTIBool DDSCTestHelper_addPartition(
1088 struct DDS_PartitionQosPolicy *partitionQos,
1089 const char *partitionName);
1090
1153extern DDSCTESTDllExport
1154RTIBool DDSCTestHelper_assertDataReaderLossPercentagePropertyExt(
1155 DDS_PropertyQosPolicy *policy,
1156 COMMENDReaderLossKind dropPolicy,
1157 int percentageLoss,
1158 int firstLostSN,
1159 int lastLostSN,
1160 int firstLostFrag,
1161 int lastLostFrag,
1162 int lossDuration);
1163
1184extern DDSCTESTDllExport DDS_DomainParticipantFactory *
1185DDSCTestHelper_disableMonitoringAndGetFactory(void);
1186
1198extern DDSCTESTDllExport DDS_Boolean
1199DDSCTestHelper_restoreMonitoringDefaults(void);
1200
1208void DDSCTestHelper_configureParticipantQosTypeObject(
1209 struct DDS_DomainParticipantQos *participantQos,
1210 RTIBool useTypeObjectV2);
1211
1212#ifdef __cplusplus
1213}
1214#endif
1215
1216#endif /* ddsctesthelpers_testHelper_h */
RTIBool DDSCTestHelper_detectInterferingParticipants(int domainId)
Creates a participant in an scenario where no participants are expected to detect interferences.