DDS Test Helpers API Reference
test_context.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_testContext_h
12#define ddsctesthelpers_testContext_h
13
14#include "rtitest/test_context.h"
15
16#include "ddsctesthelpers/test_helper.h"
17
18#include "ddsctesttypes/Foo.h"
19#include "ddsctesttypes/FooPlugin.h"
20#include "ddsctesttypes/FooSupport.h"
21#include "ddsctesttypes/Raw1k.h"
22#include "ddsctesttypes/Raw1kPlugin.h"
23#include "ddsctesttypes/Raw1kSupport.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#ifndef TEST_DOMAIN
30 #define TEST_DOMAIN 0
31#endif
32
33/* Test Stop Watch */
34
35struct DDSCTestStopWatch {
36 struct RTIClock *_clock;
37 RTIBool _running;
38 struct RTINtpTime _startTime;
39 struct RTINtpTime _stopTime;
40};
41
42extern DDSCTESTDllExport void DDSCTestStopWatch_initialize(
43 struct DDSCTestStopWatch *self,
44 struct RTIClock *clock);
45
46extern DDSCTESTDllExport RTIBool
47DDSCTestStopWatch_start(struct DDSCTestStopWatch *self);
48
49extern DDSCTESTDllExport RTIBool
50DDSCTestStopWatch_stop(struct DDSCTestStopWatch *self);
51
52extern DDSCTESTDllExport RTIBool DDSCTestStopWatch_getElapsedTime(
53 struct DDSCTestStopWatch *self,
54 struct DDS_Duration_t *elapsedTime);
55
56/* -------------------------------------------------------------------------- */
57
58/* Context Information */
59
60struct DDSCTestContext {
61 struct RTITestContext base;
62 struct RTIOsapiSemaphore *syncSem;
63 DDS_WaitSet *syncWaitSet;
64 struct RTIClock *clock;
65 int isInitialized;
66 struct DDSCTestStopWatch stopWatch;
67};
68
69extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTester_getParticipantQos(
70 DDS_DomainParticipantFactory *factory,
71 struct DDS_DomainParticipantQos *participantQos);
72
73extern DDSCTESTDllExport RTIBool
74DDSCTestContext_initialize(struct DDSCTestContext *self);
75
76extern DDSCTESTDllExport void DDSCTestContext_finalize(
77 struct DDSCTestContext *self);
78
79extern DDSCTESTDllExport struct DDSCTestContext *DDSCTestContext_new(void);
80
81extern DDSCTESTDllExport void DDSCTestContext_delete(
82 struct DDSCTestContext *self);
83
84extern DDSCTESTDllExport RTIBool DDSCTestContext_wait(
85 struct DDSCTestContext *self,
86 const struct RTINtpTime *timeout);
87
88extern DDSCTESTDllExport RTIBool
89DDSCTestContext_signal(struct DDSCTestContext *self);
90
91extern DDSCTESTDllExport int DDSCTestContext_getCurrentMatchedReaderCount(
92 DDS_DataWriter *writer);
93
94extern DDSCTESTDllExport int DDSCTestContext_getCurrentMatchedWriterCount(
95 DDS_DataReader *reader);
96
104extern DDSCTESTDllExport DDS_Long
106
107extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitForReadersAdv(
108 int numReaders,
109 DDS_DataWriter *writer,
110 int timeoutSecs,
111 RTIBool exactMatching,
112 RTIBool timeoutIsExpected);
113
126extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitForReaders(
127 int numReaders,
128 DDS_DataWriter *writer,
129 int timeoutSecs);
130
131extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitForWritersAdv(
132 int numWriters,
133 DDS_DataReader *reader,
134 int timeoutSecs,
135 RTIBool exactMatching,
136 RTIBool timeoutIsExpected);
137
152extern DDSCTESTDllExport DDS_ReturnCode_t
153DDSCTestContext_waitForAliveWritersAdv(
154 int expectedNumWriters,
155 DDS_DataReader *reader,
156 int timeoutSecs,
157 RTIBool exactMatching,
158 RTIBool timeoutIsExpected);
159
172extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitForWriters(
173 int numWriters,
174 DDS_DataReader *reader,
175 int timeoutSecs);
176
190extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitForAliveWriters(
191 int expectedNumWriters,
192 DDS_DataReader *reader,
193 int timeoutSecs);
194
195extern DDSCTESTDllExport DDS_ReturnCode_t DDSCTestContext_waitFordata(
196 const struct DDSCTestContext *self,
197 int numSamples,
198 DDS_DataReader *reader,
199 int timeoutSecs);
200
201extern DDSCTESTDllExport DDS_ReturnCode_t
202DDSCTestContextHelper_waitForUnacknowledgedSampleCount(
203 DDS_Long unacknowledgedSampleCount,
204 DDS_DataWriter *writer,
205 int timeoutSecs);
206
207extern DDSCTESTDllExport DDS_ReturnCode_t
208DDSCTestContextHelper_waitForReliableReaderActivityChanged(
209 DDS_Long activeCount,
210 DDS_Long inactiveCount,
211 DDS_DataWriter *writer,
212 int timeoutSecs);
213
214extern DDSCTESTDllExport DDS_Long DDSCTestContext_getMatchingPublicationsLength(
215 const struct DDSCTestContext *self,
216 DDS_DataReader *reader);
217
218extern DDSCTESTDllExport DDS_ReturnCode_t
219DDSCTestContext_waitMatchingPublications(
220 const struct DDSCTestContext *self,
221 DDS_DataReader *reader,
222 int expectedMatchingPublicationsLength);
223
224extern DDSCTESTDllExport DDS_Long
225DDSCTestContext_getMatchingSubscriptionsLength(
226 const struct DDSCTestContext *self,
227 DDS_DataWriter *writer);
228
229extern DDSCTESTDllExport DDS_ReturnCode_t
230DDSCTestContext_waitMatchingSubscriptions(
231 const struct DDSCTestContext *self,
232 DDS_DataWriter *writer,
233 int expectedMatchingSubscriptionsLength);
234
235extern DDSCTESTDllExport RTIBool
236DDSCTestContext_isParticipantDiscoveredWithHandle(
237 DDS_DomainParticipant *participant,
238 const DDS_InstanceHandle_t *remoteParticipantHandle);
239
240extern DDSCTESTDllExport RTIBool DDSCTestContext_isParticipantDiscovered(
241 DDS_DomainParticipant *participant,
242 DDS_DomainParticipant *remoteParticipant);
243
244/*
245 * Similar to DDSCTestContext_isParticipantDiscovered, but will
246 * also count participants that have only been partially discovered (may
247 * be pending configuration or authentication).
248 *
249 * @param participant Participant
250 * @param remoteParticipant Remote participant to check if discovvered.
251 *
252 * @return RTI_TRUE if participant has been partially discovered, RTI_FALSE
253 * if the participant has not been partially discovered at all.
254 */
255extern DDSCTESTDllExport RTIBool
256DDSCTestContext_isParticipantPartiallyDiscovered(
257 DDS_DomainParticipant *participant,
258 DDS_DomainParticipant *remoteParticipant);
259
260extern DDSCTESTDllExport RTIBool
261DDSCTestContext_waitForParticipantDiscoveryWithTime(
262 DDS_DomainParticipant *localParticipant,
263 DDS_DomainParticipant *remoteParticipant,
264 unsigned int sec);
265
266extern DDSCTESTDllExport RTIBool DDSCTestContext_waitForParticipantDiscovery(
267 DDS_DomainParticipant *localParticipant,
268 DDS_DomainParticipant *remoteParticipant);
269
270extern DDSCTESTDllExport DDS_LongLong DDSCTestContext_getReceivedSampleCount(
271 const struct DDSCTestContext *self,
272 DDS_DataReader *reader);
273
274extern DDSCTESTDllExport RTIBool DDSCTestContext_waitForReceivedSampleCount(
275 const struct DDSCTestContext *self,
276 DDS_DataReader *reader,
277 DDS_LongLong receivedSampleCount);
278
279/*
280 * Wait for the local participant to discover an expected number of
281 * remote participants. This only counts participants that are fully discovered.
282 *
283 * @param expected Number of expected remote participants
284 * @param participant Pointer to local participant
285 * @param discPartSeqPtr Out. Will contain list of instance handles of
286 * remote participants if not NULL. Can be NULL if you do not need the
287 * list of remote participants
288 * @param maxSeconds Maximum number of seconds to wait for expected participant
289 * count
290 *
291 * @return RTI_TRUE if participant discovered expected number of remote
292 * participants, RTI_FALSE otherwise.
293 */
294extern DDSCTESTDllExport RTIBool DDSCTestContext_waitForDiscoveredParticipants(
295 int expected,
296 DDS_DomainParticipant *participant,
297 struct DDS_InstanceHandleSeq *discPartSeqPtr,
298 int maxSeconds);
299
300/*
301 * Wait for the local participant to discover an expected number of
302 * remote participants. This only counts participants that are partially
303 * discovered (bootstrap received but not config).
304 *
305 * @param expected Number of expected remote participants
306 * @param participant Pointer to local participant
307 * @param discPartSeqPtr Out. Will contain list of instance handles of
308 * remote participants if not NULL. Can be NULL if you do not need the
309 * list of remote participants
310 * @param maxSeconds Maximum number of seconds to wait for expected participant
311 * count
312 *
313 * @return RTI_TRUE if participant discovered expected number of remote
314 * participants, RTI_FALSE otherwise.
315 */
316extern DDSCTESTDllExport RTIBool DDSCTestContext_waitForPartiallyDiscoveredParticipants(
317 int expected,
318 DDS_DomainParticipant *participant,
319 struct DDS_InstanceHandleSeq *discPartSeqPtr,
320 int maxSeconds);
321
322/* -------------------------------------------------------------------------- */
323
324/* DDSCPubSubTesterContext */
325
326struct DDSCPubSubDataReaderListenerData {
327 struct DDSCTestContext *testContext;
328 RTIBool error;
329 int numberOfSamplesReceived;
330 int numberOfNotValidSamplesReceived;
331 int numberOfDisposeSamplesReceived;
332 int numberOfNotAliveNoWritersSamplesReceived;
333 int numberOfInvalidAliveSamplesReceived;
334 int noWritersGenerationCount;
335 int disposedGenerationCount;
336 struct DDS_SampleLostStatus lostStatus;
337 struct DDS_SampleRejectedStatus rejectedStatus;
338 RTIBool doRead;
339 RTIBool keyed;
340 RTIBool blockInDataAvailable;
341 /* When enabled, the listener will log additional info in debug mode */
342 RTIBool additionalLogInfoIsEnabled;
343 /* Used when additionalLogInfo is enabled to include a reader id */
344 int additionalLogInfoReaderId;
345 struct RTIOsapiSemaphore *syncSem;
346 int numberOfMatches;
347 struct DDS_LivelinessChangedStatus livelinessChangedStatus;
348 RTIBool requestedIncompatibleQos;
349};
350
351#define DDSCPubSubDataReaderListenerData_INITIALIZER \
352 { \
353 NULL, /* testContext */ \
354 RTI_FALSE, /* error */ \
355 0, /* numberOfSamplesReceived */ \
356 0, /* numberOfNotValidSamplesReceived */ \
357 0, /* numberOfDisposeSamplesReceived */ \
358 0, /* numberOfNotAliveNoWritersSamplesReceived */ \
359 0, /* numberOfInvalidAliveSamplesReceived */ \
360 0, /* noWritersGenerationCount */ \
361 0, /* disposedGenerationCount */ \
362 DDS_SampleLostStatus_INITIALIZER, /* lostStatus */ \
363 DDS_SampleRejectedStatus_INITIALIZER, /* rejectedStatus */ \
364 RTI_FALSE, /* doRead */ \
365 RTI_TRUE, /* keyed */ \
366 RTI_FALSE, /* blockInDataAvailable */ \
367 RTI_FALSE, /* additionalLogInfoIsEnabled */ \
368 -1, /* additionalLogInfoReaderId */ \
369 NULL, /* syncSem */ \
370 0, /* numberOfMatches */ \
371 DDS_LivelinessChangedStatus_INITIALIZER, /* livelinessChangedStatus \
372 */ \
373 RTI_FALSE /* requestedIncompatibleQos */ \
374 }
375
376extern DDSCTESTDllExport void DDSCPubSubDataReaderListenerData_reset(
377 struct DDSCPubSubDataReaderListenerData *listener_data);
378
379extern DDSCTESTDllExport void DDSCPubSubDataReaderListener_onDataAvailable(
380 void *listener_data,
381 DDS_DataReader *reader);
382
383extern DDSCTESTDllExport void DDSCPubSubDataReaderListener_onSampleLost(
384 void *listener_data,
385 DDS_DataReader *reader,
386 const struct DDS_SampleLostStatus *status);
387
388extern DDSCTESTDllExport void DDSCPubSubDataReaderListener_onSampleRejected(
389 void *listener_data,
390 DDS_DataReader *reader,
391 const struct DDS_SampleRejectedStatus *status);
392
393extern DDSCTESTDllExport void
394DDSCPubSubDataReaderListener_onSubscriptionMatched(
395 void *listener_data,
396 DDS_DataReader *reader,
397 const struct DDS_SubscriptionMatchedStatus *status);
398
399extern DDSCTESTDllExport void DDSCPubSubDataReaderListener_onLivelinessChanged(
400 void *listener_data,
401 DDS_DataReader *reader,
402 const struct DDS_LivelinessChangedStatus *status);
403
404extern DDSCTESTDllExport void
405DDSCPubSubDataReaderListener_onRequestedIncompatibleQoS(
406 void *listener_data,
407 DDS_DataReader *reader,
408 const struct DDS_RequestedIncompatibleQosStatus *status);
409
410struct DDSCPubSubTestContext {
411 struct DDSCTestContext *baseContext;
412 DDS_DomainParticipantFactory *factory;
413 DDS_DomainParticipant *pubParticipant;
414 DDS_DomainParticipant *subParticipant;
415 DDS_Publisher *publisher;
416 DDS_Subscriber *subscriber;
417 DDS_Topic *keyedPubTopic;
418 DDS_Topic *keyedSubTopic;
419 DDS_DataWriter *writer;
420 DDS_Topic *unkeyedPubTopic;
421 DDS_Topic *unkeyedSubTopic;
422 DDS_DataReader *reader;
423 void *keyedInstance;
424 void *unkeyedInstance;
425 DDS_Boolean oldEnableEntities;
426 struct RTINtpTime livelinessLossTime;
427 DDS_Boolean shmemEnabled;
428
429 struct DDSCPubSubDataReaderListenerData readerListenerData;
430 struct DDS_DataReaderListener readerListener;
431
432 struct FooSeq unkeyedDataSeq;
433 struct Raw1kSeq keyedDataSeq;
434 struct DDS_SampleInfoSeq infoSeq;
435 RTIBool loanedSeq;
436 struct DDS_SampleInfo sampleInfo;
437};
438
439struct DDSCPubSubTestContextTypeCfg_t {
440 struct PRESTypePlugin *typePlugin;
441 const char *typeName;
442 const char *topicName;
443 void *registrationData;
444};
445
446struct DDSCPubSubTestContextTypeConfig {
447 struct DDSCPubSubTestContextTypeCfg_t keyed;
448 struct DDSCPubSubTestContextTypeCfg_t unkeyed;
449};
450
451#define DDSCPubSubTestContextTypeConfig_INITIALIZER \
452 { \
453 { NULL, NULL, NULL, NULL }, \
454 { NULL, NULL, NULL, NULL } \
455 }
456
457#define DDSCPubSubTestContextTypeConfig_initialize_keyed( \
458 typeConfig, \
459 keyedType) \
460 { \
461 typeConfig.keyed.typePlugin = keyedType##Plugin_new(); \
462 typeConfig.keyed.typeName = #keyedType "Type"; \
463 typeConfig.keyed.topicName = #keyedType "Topic"; \
464 }
465#define DDSCPubSubTestContextTypeConfig_initialize_unkeyed( \
466 typeConfig, \
467 unkeyedType) \
468 { \
469 typeConfig.unkeyed.typePlugin = unkeyedType##Plugin_new(); \
470 typeConfig.unkeyed.typeName = #unkeyedType "Type"; \
471 typeConfig.unkeyed.topicName = #unkeyedType "Topic"; \
472 }
473
474extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_forceLivelinessLoss(
475 struct DDSCPubSubTestContext *self,
476 RTIBool pubParticipant,
477 struct RTIClock *mockClock,
478 RTIBool waitForLivelinessLoss,
479 DDS_TransportBuiltinKind transportKind);
480
481extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_restoreLiveliness(
482 struct DDSCPubSubTestContext *self,
483 RTIBool pubParticipant,
484 struct RTIClock *mockClock,
485 RTIBool waitForLivelinessRestoration,
486 DDS_TransportBuiltinKind transportKind);
487
488extern DDSCTESTDllExport RTIBool
489DDSCPubSubTestContext_returnLoan(struct DDSCPubSubTestContext *context);
490
491
492extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_delete(
493 struct DDSCPubSubTestContext *context) RTI_NODISCARD;
494
495struct DDSCPubSubTestContextProperty {
496 RTIBool disableShmem;
497 /* If disableShmem is FALSE, but this is TRUE, SHMEM is disabled only in
498 * the subParticipant. */
499 RTIBool disableShmemInSubParticipant;
500 /* If enabled and the architecture supports IPv6, we will use the IPv6
501 * version of the built-in transport if available. */
502 RTIBool useIpv6;
503 RTIBool disableType;
504 /* Profile name applied to the participants created by the context.
505 * It overwrites the global profile name
506 */
507 const char *participantLibraryName;
508 const char *participantProfileName;
509 /* Profile name applied to all entities created by the context */
510 const char *globalLibraryName;
511 const char *globalProfileName;
512 const struct DDS_DomainParticipantQos *participantQos;
513
514 /*
515 * If you set createEntitiesDisabled to true, then creating a context sets
516 * the autoenable_created_entities factory QoS, and deleting the context
517 * restores the autoenable_created_entities factory QoS. If you create more
518 * than one context, it is important that you delete them in the opposite
519 * order of creation. That is, the first context to be created must be the
520 * last one to be deleted (because it stores the original value of the
521 * autoenable_created_entities factory QoS, so that value is the one that
522 * must be restored last).
523 */
524 RTIBool createEntitiesDisabled;
525
526 /* If enabled, the participants will be configured to assert/check
527 * liveliness within a short period. (Default: false) */
528 RTIBool useShortParticipantLiveliness;
529 /* If enabled, the liveliness readers will be created as reliable readers.
530 * (Default: false) */
531 RTIBool useReliableLivelinessReaders;
532 /* If enabled, the participant id of each participant will be automatically
533 * calculated. If now, it will be manually set by TestContext.
534 * (Default: true) */
535 RTIBool useAutoParticipantId;
536 int builtinTypeMaxSize;
537 RTIBool topicPresentation;
538 RTIBool coherentAccess;
539 RTIBool pubParticipantCrossEndian;
540 RTIBool subParticipantCrossEndian;
541 /* If enabled disables all builtin transports in the participant creation */
542 RTIBool disableBuiltinTransports;
543 /*
544 * Indicates if accept_unknown_peers can be overwritten by the context
545 * when creating a participant based on SHMEM settings.
546 */
547 RTIBool overwriteAcceptUnknownPeers;
548};
549
550#define DDSCPubSubTestContextProperty_INITIALIZER \
551 { \
552 RTI_FALSE, /* disableShmem*/ \
553 RTI_FALSE, /* disableShmemInSubParticipant */ \
554 RTI_FALSE, /* useIpv6 */ \
555 RTI_FALSE, /* disableType */ \
556 NULL, /* participantLibraryName */ \
557 NULL, /* participantProfileName */ \
558 NULL, /* globalLibraryName */ \
559 NULL, /* globalProfileName */ \
560 NULL, /* participantQos */ \
561 RTI_FALSE, /* createEntitiesDisabled */ \
562 RTI_FALSE, /* useShortParticipantLiveliness */ \
563 RTI_FALSE, /* useReliableLivelinessReaders */ \
564 RTI_TRUE, /* useAutoParticipantId */ \
565 -1, /* builtinTypeMaxSize */ \
566 RTI_TRUE, /* topicPresentation */ \
567 RTI_FALSE, /* coherentAccess */ \
568 RTI_FALSE, /* pubParticipantCrossEndian */ \
569 RTI_FALSE, /* subParticipantCrossEndian */ \
570 RTI_FALSE, /* disableBuiltinTransports */ \
571 RTI_TRUE /* overwriteAcceptUnknownPeers */ \
572 }
573
574extern DDSCTESTDllExport
575RTIBool DDSCPubSubTestContext_createWriterDisabled(
576 struct DDSCPubSubTestContext *context,
577 const struct DDS_DataWriterQos *writerQos,
578 struct DDS_DataWriterListener *listener,
579 DDS_StatusMask listenerMask);
580
581extern DDSCTESTDllExport
582RTIBool DDSCPubSubTestContext_createWriter(
583 struct DDSCPubSubTestContext *context,
584 const struct DDS_DataWriterQos *writerQos,
585 struct DDS_DataWriterListener *listener,
586 DDS_StatusMask listenerMask);
587
588extern DDSCTESTDllExport RTIBool
589DDSCPubSubTestContext_deleteSubscriber(struct DDSCPubSubTestContext *context);
590
591extern DDSCTESTDllExport RTIBool
592DDSCPubSubTestContext_deletePublisher(struct DDSCPubSubTestContext *context);
593
594extern DDSCTESTDllExport RTIBool
595DDSCPubSubTestContext_deleteReader(struct DDSCPubSubTestContext *context);
596
597extern DDSCTESTDllExport RTIBool
598DDSCPubSubTestContext_deleteWriter(struct DDSCPubSubTestContext *context);
599
600extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_getReliableWriterQos(
601 struct DDSCPubSubTestContext *context,
602 struct DDS_DataWriterQos *writerQos);
603
604extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createReliableWriter(
605 struct DDSCPubSubTestContext *context,
606 struct DDS_DataWriterListener *listener,
607 DDS_StatusMask listenerMask);
608
609extern DDSCTESTDllExport
610RTIBool DDSCPubSubTestContext_createReaderDisabled(
611 struct DDSCPubSubTestContext *context,
612 const struct DDS_DataReaderQos *readerQos,
613 struct DDS_DataReaderListener *listener,
614 DDS_StatusMask listenerMask);
615
616extern DDSCTESTDllExport
617RTIBool DDSCPubSubTestContext_createReader(
618 struct DDSCPubSubTestContext *context,
619 const struct DDS_DataReaderQos *readerQos,
620 struct DDS_DataReaderListener *listener,
621 DDS_StatusMask listenerMask);
622
623extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_getReliableReaderQos(
624 struct DDSCPubSubTestContext *context,
625 struct DDS_DataReaderQos *readerQos);
626
627extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createReliableReader(
628 struct DDSCPubSubTestContext *context,
629 struct DDS_DataReaderListener *listener,
630 DDS_StatusMask listenerMask);
631
632extern DDSCTESTDllExport RTIBool
633DDSCPubSubTestContext_createReaderWithDefaultListener(
634 struct DDSCPubSubTestContext *context,
635 const struct DDS_DataReaderQos *qos);
636
637extern DDSCTESTDllExport RTIBool
638DDSCPubSubTestContext_getTestDefaultParticipantQos(
639 struct DDS_DomainParticipantQos *participantQos,
640 const struct DDSCPubSubTestContextProperty *property);
641
642extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createTopicWithQos(
643 struct DDSCPubSubTestContext *context,
644 struct DDSCPubSubTestContextTypeConfig *typeConfig,
645 struct DDS_TopicQos *topicQos,
646 RTIBool isPub);
647
648extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createTopic(
649 struct DDSCPubSubTestContext *context,
650 struct DDSCPubSubTestContextTypeConfig *typeConfig,
651 RTIBool isPub);
652
653extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createPubOrSub(
654 struct DDSCPubSubTestContext *context,
655 const struct DDSCPubSubTestContextProperty *property,
656 RTIBool isPub);
657
658extern DDSCTESTDllExport struct DDSCPubSubTestContext *
659DDSCPubSubTestContext_createI(
660 const char *METHOD_NAME,
661 int id,
662 struct DDSCPubSubTestContextTypeConfig *typeConfig,
663 const struct DDSCPubSubTestContextProperty *property,
664 RTIBool createParticipants);
665
666extern DDSCTESTDllExport struct DDSCPubSubTestContext *
667DDSCPubSubTestContext_create(
668 const char *METHOD_NAME,
669 int id,
670 struct DDSCPubSubTestContextTypeConfig *typeConfig,
671 const struct DDSCPubSubTestContextProperty *property);
672
673extern DDSCTESTDllExport RTIBool
674DDSCPubSubTestContext_createPubParticipantWithTypeConfig(
675 struct DDSCPubSubTestContext *context,
676 int id,
677 struct DDSCPubSubTestContextTypeConfig *typeConfig,
678 const struct DDSCPubSubTestContextProperty *property);
679
680extern DDSCTESTDllExport RTIBool
681DDSCPubSubTestContext_createSubParticipantWithTypeConfig(
682 struct DDSCPubSubTestContext *context,
683 int id,
684 struct DDSCPubSubTestContextTypeConfig *typeConfig,
685 const struct DDSCPubSubTestContextProperty *property);
686
687extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createPubParticipant(
688 struct DDSCPubSubTestContext *context,
689 int domainId,
690 RTIBool keyed,
691 const struct DDSCPubSubTestContextProperty *property);
692
693extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_createSubParticipant(
694 struct DDSCPubSubTestContext *context,
695 int domainId,
696 RTIBool keyed,
697 const struct DDSCPubSubTestContextProperty *property);
698
699extern DDSCTESTDllExport void DDSCPubSubTestContext_initializeListener(
700 struct DDSCPubSubTestContext *context);
701
702extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_waitForReadersAndWriters(
703 struct DDSCPubSubTestContext *context,
704 int numReaders,
705 int numWriters);
706
707extern DDSCTESTDllExport RTIBool DDSCPubSubTestContext_waitForReaderAndWriter(
708 struct DDSCPubSubTestContext *context);
709
710extern DDSCTESTDllExport DDS_Boolean DDSCPubSubTestContext_getReceivedInteger(
711 struct DDSCPubSubTestContext *context,
712 int *receivedInteger, /* out */
713 int sampleIndex);
714
715extern DDSCTESTDllExport const struct DDS_SampleInfo *
716DDSCPubSubTestContext_getReceivedSampleInfo(
717 struct DDSCPubSubTestContext *context,
718 int sampleIndex);
719
720extern DDSCTESTDllExport int DDSCPubSubTestContext_read(
721 struct DDSCPubSubTestContext *context,
722 RTIBool doTake,
723 DDS_ReadCondition *rCond);
724
725extern DDSCTESTDllExport DDS_ReturnCode_t
726DDSCPubSubTestContext_unregisterInstance(
727 struct DDSCPubSubTestContext *context,
728 DDS_DataWriter *writer,
729 unsigned int instanceToUnregister);
730
731extern DDSCTESTDllExport DDS_ReturnCode_t DDSCPubSubTestContext_disposeInstance(
732 struct DDSCPubSubTestContext *context,
733 DDS_DataWriter *writer,
734 int instanceToDispose);
735
736extern DDSCTESTDllExport DDS_ReturnCode_t
737DDSCPubSubTestContext_disposeInstanceWithTimestamp(
738 struct DDSCPubSubTestContext *context,
739 DDS_DataWriter *writer,
740 int instanceToDispose,
741 const struct DDS_Time_t *sourceTimestamp);
742
743extern DDSCTESTDllExport DDS_ReturnCode_t DDSCPubSubTestContext_writeInstance(
744 struct DDSCPubSubTestContext *context,
745 DDS_DataWriter *writer,
746 int instanceToWrite);
747
748extern DDSCTESTDllExport DDS_ReturnCode_t
749DDSCPubSubTestContext_writeInstanceWithTimestamp(
750 struct DDSCPubSubTestContext *context,
751 DDS_DataWriter *writer,
752 int instanceToWrite,
753 const struct DDS_Time_t *sourceTimestamp);
754
755extern DDSCTESTDllExport DDS_ReturnCode_t DDSCPubSubTestContext_writeNumSamples(
756 struct DDSCPubSubTestContext *context,
757 DDS_DataWriter *writer,
758 unsigned int numSamples,
759 unsigned int numInstances);
760
761extern DDSCTESTDllExport DDS_ReturnCode_t
762DDSCPubSubTestContext_writeWithTimestamp(
763 struct DDSCPubSubTestContext *context,
764 DDS_DataWriter *writer,
765 void *data,
766 const DDS_InstanceHandle_t *instanceHandle,
767 struct DDS_Time_t *sourceTimestamp);
768
782extern DDSCTESTDllExport DDS_ReturnCode_t
783DDSCPubSubTestContext_writeWithParams(
784 struct DDSCPubSubTestContext *context,
785 DDS_DataWriter *writer,
786 const void *data,
787 struct DDS_WriteParams_t *params);
788
789extern DDSCTESTDllExport DDS_ReturnCode_t
790DDSCPubSubTestContext_disposeWithParams(
791 struct DDSCPubSubTestContext *context,
792 DDS_DataWriter *writer,
793 const void *data,
794 struct DDS_WriteParams_t *params);
795
796extern DDSCTESTDllExport DDS_ReturnCode_t DDSCPubSubTestContext_readNextSample(
797 struct DDSCPubSubTestContext *context,
798 RTIBool doTake);
799
800extern DDSCTESTDllExport int DDSCPubSubTestContext_readInstance(
801 struct DDSCPubSubTestContext *context,
802 RTIBool doTake,
803 int id);
804
805extern DDSCTESTDllExport struct DDSCPubSubTestContext *
806DDSCPubSubTestContext_newEx(
807 const char *METHOD_NAME,
808 int domainId,
809 RTIBool keyed,
810 const struct DDSCPubSubTestContextProperty *property,
811 RTIBool createParticipants);
812
813extern DDSCTESTDllExport struct DDSCPubSubTestContext *
814DDSCPubSubTestContext_new(
815 const char *FUNCTION_NAME,
816 int domainId,
817 RTIBool keyed,
818 const struct DDSCPubSubTestContextProperty *property);
819
832extern DDSCTESTDllExport RTIBool DDSCTestCommon_configureOdbcWriterHistory(
833 struct DDS_DomainParticipantQos *participantQos,
834 struct DDS_DataWriterQos *writerQos,
835 const struct RTITestSetting *setting,
836 RTIBool inMemoryOdbc,
837 RTIBool useClassLevelProperties);
838
843extern DDSCTESTDllExport RTIBool
844DDSCTestCommon_enableDurableWriterHistory(
845 const struct RTITestSetting *setting,
846 struct DDS_DataWriterQos *writerQos);
847
848/* -------------------------------------------------------------------------- */
849
850/* DDSCScenarioTester */
851
852typedef enum {
853 DDSCScenarioTester_NO_OP,
854 DDSCScenarioTester_WAIT_PEERS, /* param == reader | writer (0 | 1) */
855 DDSCScenarioTester_WRITE,
856 DDSCScenarioTester_DISPOSE,
857 DDSCScenarioTester_WAIT,
858 DDSCScenarioTester_WAIT_W_COND, /* param == index of condition */
859 DDSCScenarioTester_WAIT_RC, /* wait for matching read condition */
860 DDSCScenarioTester_WAIT_MATCHING_SUBSCRIPTIONS, /* param == expected subscriptions */
861 DDSCScenarioTester_WAIT_MATCHING_PUBLICATIONS, /* param == expected publications */
862 DDSCScenarioTester_IGNORE_ENTITY, /* param == reader | writer (0 | 1) */
863 DDSCScenarioTester_READ,
864 DDSCScenarioTester_TAKE,
865 DDSCScenarioTester_READ_INSTANCE,
866 DDSCScenarioTester_TAKE_INSTANCE,
867 DDSCScenarioTester_READ_NEXT_INSTANCE,
868 DDSCScenarioTester_TAKE_NEXT_INSTANCE,
869 DDSCScenarioTester_READ_W_COND, /* param == index of condition */
870 DDSCScenarioTester_TAKE_W_COND, /* param == index of condition */
871 DDSCScenarioTester_READ_INSTANCE_W_COND, /* param == index of condition */
872 DDSCScenarioTester_TAKE_INSTANCE_W_COND, /* param == index of condition */
873 DDSCScenarioTester_READ_NEXT_INSTANCE_W_COND,/* param == index of condition */
874 DDSCScenarioTester_TAKE_NEXT_INSTANCE_W_COND,/* param == index of condition */
875 DDSCScenarioTester_CREATE_QUERY_CONDITION,
876 DDSCScenarioTester_SET_QUERY_CONDITION_PARAM_1,/* param == index of condition */
877 DDSCScenarioTester_SET_QUERY_CONDITION_PARAM_2,/* param == index of condition */
878 DDSCScenarioTester_ASSERT_READCONDITION_STATUS, /* param == matching bit mask */
879 /* pseudo-ops */
880 DDSCScenarioTester_COMMON_KEYED_READ_TAKE,
881 DDSCScenarioTester_COMMON_UNKEYED_READ_TAKE
882} DDSCScenarioTester_op;
883
884struct DDSCScenarioTester_data {
885 int value;
886 int instance;
887};
888
889/* configuration of read|take mask, or of a ReadCondition */
890struct DDSCScenarioTester_readConditionCfg_t {
891 DDS_SampleStateMask sample_state;
892 DDS_ViewStateMask view_state;
893 DDS_InstanceStateMask instance_state;
894};
895
896/* a single step of the unit test */
897struct DDSCScenarioTester_operation {
898 DDSCScenarioTester_op op;
899 RTIBool success;
900 int param; /* operation dependent parameter */
901 struct DDSCScenarioTester_readConditionCfg_t read_mask;
902 int rep_count; /* negative rep_count interpreted to use UNLIMITED on read,
903 and abs(rep_count) for seq length */
904
905 /* data - single data for write & read
906 instance ID for read_instance, read_next_instance
907 timeout - timeout value for wait
908 */
909 union {
910 struct DDSCScenarioTester_data data;
911 struct DDS_Duration_t timeout;
912 } u;
913 /* pointer to data for:
914 array of data for multi-data write and read
915 single or array of data for all read_instance, read_next_instance */
916 struct DDSCScenarioTester_data *data_ptr;
917};
918
919/* configuration for read (filter_expression == NULL) or query condition */
920struct DDSCScenarioTester_filterCfg_t {
921 struct DDSCScenarioTester_readConditionCfg_t filter_states;
922 char *filter_expression;
923 /* The filter input parameter when using SET_QUERY_CONDITION_PARAM_1 */
924 char *filter_parameter_0;
925 /* The filter input parameter when using SET_QUERY_CONDITION_PARAM_2 */
926 char *filter_parameter_1;
927 /* If RTI_TRUE, we force the use of evaluateOnSerialized for evaluating
928 * samples. This is useful for testing the code path followed by APIs that
929 * rely on the serialized form of the samples (e.g., Java). */
930 RTIBool force_filter_on_serialized;
931 /* If RTI_TRUE, the QueryCondition will always pass for not-alive samples,
932 * independently of any value cached in the filter. */
933 RTIBool querycondition_pass_not_alive_samples;
934};
935
936/* configuration for one scenario of the unit test */
937struct DDSCScenarioTester_config {
938 DDS_PresentationQosPolicyAccessScopeKind access_scope;
939 DDS_HistoryQosPolicyKind history_kind;
940 /* DDS_DataWriterProtocolQosPolicy's serialize key with dispose */
941 RTIBool serialize_key_with_dispose;
942 /* DDS_DataReaderProtocolQosPolicy's propagate dispose of unregister */
943 RTIBool propagate_dispose_of_unregistered_instances;
944 DDS_Long history_depth;
945 DDS_Long max_samples;
946 DDS_Long max_samples_per_instance;
947 RTIBool useWaitSet; /* to insure delay multi-sample should NOT use WaitSet
948 */
949 RTIBool keyed; /* keyed or unkeyed */
950 RTIBool createMonitorReadConditions;
951 RTIBool enableEntities;
952 /* True: v1 writer, false: v2 writer */
953 RTIBool useV1Writer;
954 int allocThreshold;
955};
956
957#define DDSCScenarioTester_rep_count_to_read_count(x__) \
958 ((x__) < 0 ? DDS_LENGTH_UNLIMITED : (x__))
959
960#define DDS_SCENARIO_TESTER_LENGTH_UNLIMITED (-1)
961
962#define DDS_TEST_CONTEXT_ANY_SAMPLE_STATE \
963 (DDS_READ_SAMPLE_STATE | DDS_NOT_READ_SAMPLE_STATE)
964#define DDS_TEST_CONTEXT_ANY_VIEW_STATE \
965 (DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE)
966#define DDS_TEST_CONTEXT_ANY_INSTANCE_STATE \
967 (DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE \
968 | DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)
969
970#define DDSC_SCENARIO_TESTER_READ_CONDITION_COMBINATIONS 12
971
972extern DDSCTESTDllExport RTIBool DDSCScenarioTester(
973 const struct RTITestSetting *setting,
974 const struct DDSCScenarioTester_config *cfg,
975 const struct DDSCScenarioTester_operation *sequence,
976 const struct DDSCScenarioTester_filterCfg_t *filterCfg,
977 const char *METHOD_NAME);
978
979/* -------------------------------------------------------------------------- */
980
981/* Topic Query */
982
983extern DDSCTESTDllExport int DDSCTestHelper_getWriterSessionSampleCount(
984 struct DDSCPubSubTestContext *context,
985 RTIBool topicQuerySession);
986
987extern DDSCTESTDllExport RTIBool DDSCTestHelper_getTopicQueryTestWriterQos(
988 struct DDSCPubSubTestContext *testContext,
989 struct DDS_DataWriterQos *writerQos);
990
991extern DDSCTESTDllExport RTIBool DDSCTestHelper_getTopicQueryTestReaderQos(
992 struct DDSCPubSubTestContext *testContext,
993 struct DDS_DataReaderQos *readerQos);
994
995/*
996 * Used with DDSCTestContextRelatedEntityTestObjects_write to log number
997 * of related entity discovery messages.
998 */
999struct DDSCTestContextRelatedEntityTestObjectsLoggerDeviceData {
1000 /*
1001 * Number of messages logged when running
1002 * PRESPsService_onLinkEndpointWithRelatedGuid when the local reader can
1003 * be linked.
1004 */
1005 int linkRelatedMessageCount;
1006 /*
1007 * Number of messages logged when posting the
1008 * PRESPsService_onLinkEndpointWithRelatedGuid event from
1009 * PRESPsServiceLink_setMatchToCompatible.
1010 */
1011 int notReadyToLinkMessageCount;
1012};
1013
1014#define DDSCTestContextRelatedEntityTestObjectsLoggerDeviceData_INITIALIZER \
1015 { \
1016 0, /* linkRelatedMessageCount*/ \
1017 0 /* notReadyToLinkMessageCount */ \
1018 }
1019
1020/*
1021 * Structure used by tests in BuiltinTester and DomainDiscoveryTester that
1022 * set related entity GUIDs.
1023 */
1024struct DDSCTestContextRelatedEntityTestObjects {
1025 /* Test context */
1026 struct DDSCPubSubTestContext *context;
1027 /* Writer, belongs to subParticipant */
1028 DDS_DataWriter *subWriter;
1029 /* Reader, belongs to pubParticipant */
1030 DDS_DataReader *pubReader;
1031 /* Key of context->writer */
1032 DDS_InstanceHandle_t pubWriterKey;
1033 /* Key of pubReader */
1034 DDS_InstanceHandle_t pubReaderKey;
1035 /* Key of context->reader */
1036 DDS_InstanceHandle_t subReaderKey;
1037 /* Key of subWriter */
1038 DDS_InstanceHandle_t subWriterKey;
1039 struct DDS_DomainParticipantQos participantQos;
1040 /* Used to corrupt packets to stop endpoint discovery from occurring */
1041 struct MIGGeneratorListener tamperingListener;
1042 /*
1043 * Configures tampering listener, contains info like what writer OID
1044 * to corrupt and when to stop corrupting
1045 */
1046 struct DDSCTestHelperTamperingListenerData tamperingListenerData;
1047 /* Used to check for log messages from events */
1048 NDDS_Config_Logger *logger;
1049 RTIBool loggingConfigurationIsCached;
1050 struct NDDS_Config_LoggerDevice loggingDevice;
1051 struct DDSCTestContextRelatedEntityTestObjectsLoggerDeviceData
1052 loggingDeviceData;
1053};
1054
1055#define DDSCTestContextRelatedEntityTestObjects_INITIALIZER \
1056 { \
1057 NULL, /* context */ \
1058 NULL, /* subWriter */ \
1059 NULL, /* pubReader */ \
1060 DDS_HANDLE_NIL, /* pubWriterKey */ \
1061 DDS_HANDLE_NIL, /* pubReaderKey */ \
1062 DDS_HANDLE_NIL, /* subReaderKey */ \
1063 DDS_HANDLE_NIL, /* subWriterKey */ \
1064 DDS_DomainParticipantQos_INITIALIZER, /* participantQos */ \
1065 MIGGeneratorListener_INITIALIZER, /* tamperingListener */ \
1066 DDSCTestHelperTamperingListenerData_INITIALIZER, /* tamperingListenerData \
1067 */ \
1068 NULL /* logger */, RTI_FALSE, /* loggingConfigurationIsCached \
1069 */ \
1070 NDDS_Config_LoggerDevice_INITIALIZER, /* loggingDevice */ \
1071 DDSCTestContextRelatedEntityTestObjectsLoggerDeviceData_INITIALIZER /* loggingDeviceData */ \
1072 }
1073
1074/*
1075 * Initializes the members of a DDSCTestContextRelatedEntityTestObjects.
1076 * This creates 2 participants, each with a reader and the writer. Each writer
1077 * has the reader's GUID as its related entity GUID, and each reader has
1078 * the writer's GUID as its related entity GUID.
1079 *
1080 * @param objects DDSCTestContextRelatedEntityTestObjects to initialize
1081 * @param domainId domain for participants to use
1082 * @param delayReaderDiscovery If TRUE we will set the tampering listener to
1083 * tamper DATA(R)s
1084 * @param delayWriterDiscovery If TRUE we will set the tampering listener to
1085 * tamper DATA(W)s
1086 * @param tamperDirected If TRUE and either delayReaderDiscovery or
1087 * delayWriterDiscovery are TRUE, we will only tamper messages directed to
1088 * context->pubParticipant. If FALSE and either delayReaderDiscovery or
1089 * delayWriterDiscovery are TRUE, we will tamper all messages.
1090 *
1091 * @return RTI_TRUE if success, RTI_FALSE if failure
1092 */
1093RTIBool DDSCTestContextRelatedEntityTestObjects_initialize(
1094 struct DDSCTestContextRelatedEntityTestObjects *objects,
1095 DDS_DomainId_t domainId,
1096 RTIBool delayReaderDiscovery,
1097 RTIBool delayWriterDiscovery,
1098 RTIBool tamperDirected);
1099
1100/*
1101 * Delete the objects in a DDSCTestContextRelatedEntityTestObjects.
1102 *
1103 * @param objects DDSCTestContextRelatedEntityTestObjects to delete
1104 *
1105 * @return RTI_TRUE if success, RTI_FALSE if failure
1106 */
1107RTIBool
1108DDSCTestContextRelatedEntityTestObjects_finalize(
1109 struct DDSCTestContextRelatedEntityTestObjects *objects);
1110
1124RTIBool DDSCPubSubTestContextProperty_initializeForDynamicData(
1125 struct DDSCPubSubTestContextProperty *property,
1126 struct DDS_DomainParticipantQos *participantQos,
1127 RTIBool useTypeObjectV2);
1128
1129#ifdef __cplusplus
1130}
1131#endif
1132
1133#endif /* ddsctesthelpers_testContext_h */
DDS_Long DDSCTestContext_getCurrentAliveWriterCount(DDS_DataReader *reader)
Get the current count of alive writers matched with the given reader.
DDS_ReturnCode_t DDSCTestContext_waitForReaders(int numReaders, DDS_DataWriter *writer, int timeoutSecs)
Does an active wait until numReaders readers are discovered by writer, or during timeoutSecs until fa...
DDS_ReturnCode_t DDSCTestContext_waitForWriters(int numWriters, DDS_DataReader *reader, int timeoutSecs)
Does an active wait until numWriters writers are discovered by reader, or during timeoutSecs until fa...