Unit Test Framework C and Traditional C++ API Reference
test_setting.h
1/*
2 * (c) Copyright, Real-Time Innovations, 2002-2022.
3 * All rights reserved.
4 * No duplications, whole or partial, manual or electronic, may be made
5 * without express written permission. Any such copies, or
6 * revisions thereof, must display this notice unaltered.
7 * This code contains trade secrets of Real-Time Innovations, Inc.
8 */
9
10#ifndef rtitest_setting_h
11#define rtitest_setting_h
12
22#include "rtitest/test_log.h"
23#include "rtitest/test_dll.h"
24#include "rtitest/test_assert.h"
25#include "rtitest/test_types.h"
26#include "rtitest/test_time.h"
27
28#define RTI_TEST_MAX_FILE_NAME_LENGTH (1024)
29#define RTI_TEST_MAX_USER_LENGTH (128)
30
31#if defined(RTI_WIN32) || defined(RTI_WINCE)
32 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (1)
33#elif defined(RTI_VXWORKS)
34 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (99)
35#elif defined(RTI_LYNX)
36 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (18)
37#elif defined(RTI_PSOS)
38 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (101)
39#elif defined(RTI_NETOS)
40 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (16)
41#elif defined(RTI_INTY)
42 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (17)
43#elif defined(RTI_QNX)
44 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (10)
45#else
46 #define RTI_TEST_RECEIVE_THREAD_PRIORITY (-9999999)
47#endif /* defined(RTI_WIN32) || defined(RTI_WINCE) */
48
49#include <stdio.h>
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54#if defined(RTI_WINCE)
55 #include <windows.h>
56#endif /*#if defined(RTI_WINCE)*/
57
58
131struct RTITestNumber {
132 /* The number of the submodule that contains the unit test. */
133 int submoduleTestNumber;
134 /* The number that identifies the unit test within the submodule. */
135 int unitTestNumber;
136};
137
182struct RTITestSetting {
183 /*
184 * if you modify this structure also modify RTI_TEST_SETTING_DEFAULT in
185 * setting_impl
186 */
187 /*
188 * Defines first submodule in range of tests and first unit test
189 * within each submodule.
190 * That is, if first unit test = 2, all submodule tests will start with
191 * unit test 2.
192 *
193 * The submodule and unit test indices start at 0.
194 */
195
196 struct RTITestNumber begin;
197
198 /*
199 * Defines last submodule in range of tests and last unit test
200 * within each submodule.
201 * That is, if last unit test = 4, all submodule tests will only
202 * run up to unit test 4 (or will stop sooner if there are not that
203 * many unit tests).
204 *
205 * Use a negative number to run all available tests
206 * (submodule and/or unit test).
207 * For example, if last submodule = -1 and last unit test = 2,
208 * the recursive test will enter \e all submodules and run up to
209 * unit test 2 in each
210 * submodule.
211 */
212 struct RTITestNumber end;
213
214 /* bitmap to specify verbosity of logging &&& needs work */
215 RTITestLogBitmap instrumentationMask;
216
217 /*
218 * If set to 1, all tests in specified range will be run, even if
219 * one or more tests fail. If set to 0, the testing stops as soon as
220 * one of the tests fails.
221 */
222 int ignoreFailure;
223
224 /*
225 * If set to 1, run interactive tests as well. Otherwise, skip all
226 * the interactive tests. Default is 0.
227 */
228 int runInteractiveTest;
229
230 /* ID used for port/multicast address calculation. Range is 0-99 */
231 int id;
232
233 /* Domain Tag used for tester isolation */
234 char *tag;
235
236 /*
237 * If set to 1, tests that fail or hang when run over activeSync will not
238 * be run. This is only applicable to Windows CE
239 */
240 int activeSync;
241
242 /*
243 * If set to 1, include tests which use external (plugin) ODBC databases.
244 */
245 int testOdbcDatabases;
246
247 /*
248 * If set to 1, DB and inst ini file will not be deleted after the test
249 * has finished.
250 */
251 int keepOdbcResources;
252
253 /*
254 * The path to the odbc.ini file.
255 */
256 char *odbcIniPath;
257
258 /*
259 * name by which program was invoked
260 */
261 char *execPath;
262
263 /*
264 * Name of the database that will be tested
265 * If this name is empty all databases will be tested unless
266 * -noOdbcdatabase is used
267 */
268 const char *database;
269
270 /*
271 * If set to 1, then show the execution times for the tests(Windows and
272 * Linux only).
273 */
274 int showTime;
275
276 /*
277 * user name
278 */
279 char user[RTI_TEST_MAX_USER_LENGTH];
280
281
282 /*
283 * The following variables are internal to test.1.0
284 */
285
286 /*
287 * JUnit output file name
288 */
289 char _jUnitOutputFile[RTI_TEST_MAX_FILE_NAME_LENGTH + 1];
290
291 /*
292 * JUnit output file descriptor
293 */
294 FILE *_jUnitOutputFD;
295
296 /*
297 * Level of iteration
298 */
299 int _level;
300
301 /*
302 * Maximum number of times to retry a failed test.
303 */
304 int _maxRetries;
305
306 /*
307 * If set to 1, tests that require the RTI LAN will not
308 * be run.
309 */
310 int noRtiLan;
311
312 /*
313 * If set to 1, tests that require files will not
314 * be run.
315 */
316 int noTestFiles;
317
318 /*
319 * If set to 1, tests that require writing to files will not be run.
320 */
321 int noWritableFileSystem;
322
323 /*
324 * If set to 1, the test range runs forever. Useful to reproduce crashes.
325 */
326 int repeatTests;
327
328 /* It specifies the number of times the tests are going to be run */
329 unsigned int numberOfRepeats;
330
331 /*
332 * If set to non-negative integer, it will overwrite all hardcoded retry
333 * values to this value. By default, it is -1 to indicate to use user
334 * specified value. The value overwritten will be numRetries in
335 * RTITestSetting_retryIfFailed(... , numRetries)
336 */
337 int globalIndividualUnitTestRetryCount;
338
339 /*
340 * A placeholder for custom parameters. This member contains the value
341 * provided as part of the -option argument. The value is treated as an
342 * string and it is up to the client to interpret it.
343 */
344 const char *option;
345
346 /*
347 * When set to 1, heap monitoring will be enabled.
348 */
349 int enableHeapMonitoring;
350
351 /*
352 * When set to 1, network capture will be enabled.
353 */
354 int enableNetworkCapture;
355
356 /*e
357 * When set to 1, a leak analysis will be run per test when using
358 * Valgrind. Requires to build with PLATFORM_SUPPORT_VALGRIND_PER_TEST=ON
359 */
360 int valgrindPerTest;
361
362 /*
363 * When set to 1, detection of unexpected participants will be activated
364 * when a test fails if possible
365 */
366 int detectInterferingParticipants;
367
372 RTIBool enableLeakSanitizerCheck;
373
377 RTIBool failOnLeak;
378};
379
410extern RTITestDllExport void RTITestSetting_set(
411 struct RTITestSetting *setting,
412 int beginSubmodule,
413 int beginUnit,
414 int endSubmodule,
415 int endUnit,
416 RTITestLogBitmap submodMask,
417 RTITestLogBitmap instMask,
418 int ignoreFailure,
419 int id,
420 int runInteractiveTest);
421
462extern RTITestDllExport int RTITestSetting_parseArgumentFromString(
463 struct RTITestSetting *setting,
464 char *args);
465
509extern RTITestDllExport RTIBool RTITestSetting_parseArgument(
510 struct RTITestSetting *setting,
511 int argCount,
512 char **argv);
513
514#if defined(RTI_WINCE)
515
545extern RTITestDllExport int RTITestSetting_parseWcharArgument(
546 struct RTITestSetting *setting,
547 int argCount,
548 wchar_t **argv);
549
550#endif /* RTI_WINCE */
551
571typedef enum {
572 RTI_TEST_LEVEL_UNIT,
573 RTI_TEST_LEVEL_SUBMODULE
574} RTITestLevel;
575
598extern RTITestDllExport void RTITestSetting_getRange(
599 const struct RTITestSetting *setting,
600 int *begin,
601 int *end,
602 RTITestLevel currentLevel);
603
614extern RTITestDllExport RTIBool
615RTITestSetting_isRangeSpecified(int begin, int end);
616
643 const struct RTITestSetting *setting);
644
679 const struct RTITestSetting *setting,
680 const char *methodName,
681 const RTITestFunction *test,
682 int testCount,
683 int begin,
684 int end);
685
700extern RTITestDllExport RTITestReturnCode RTITestSetting_runTestsExt(
701 const struct RTITestSetting *setting,
702 const char *methodName,
703 const RTITestFunction *testBasic,
704 int testCountBasic,
705 const RTITestFunction *testAdditional,
706 int testCountAdditional,
707 int begin,
708 int end);
709
717extern RTITestDllVariable int RTITestSetting_g_individualUnitTestRetryCount;
718
729extern RTITestDllExport void RTITestSetting_retryIfFailed(
730 const struct RTITestSetting *setting,
731 int numRetries);
732
738extern RTITestDllExport void RTITestSetting_printComplete(const char *methodName);
739
755extern RTITestDllExport RTIBool RTITestSetting_getFullResourcePathFileName(
756 const struct RTITestSetting *setting,
757 char *fullPathFileName,
758 const char *relativeResourcePathFileName);
759
768extern RTITestDllExport RTIBool RTITestSetting_getFullResourcePathFileNameEx(
769 const struct RTITestSetting *setting,
770 char *fullPathFileName,
771 const char *resourceRelativePath,
772 const char *relativeResourcePathFileName);
773
780extern RTITestDllExport
781void RTITestSetting_logNetworkCaptureNotSupportedMessage(void);
782
783#ifndef RTI_TEST_EXAMPLE_RELATIVE_PATH
784 #ifdef RTI_ANDROID
785 #define RTI_TEST_EXAMPLE_RELATIVE_PATH "/sdcard/example"
786 #else
787 #define RTI_TEST_EXAMPLE_RELATIVE_PATH "../../example"
788 #endif
789#endif
790
791#ifndef RTI_TEST_RESOURCE_RELATIVE_PATH
792 #ifdef RTI_ANDROID
793 #define RTI_TEST_RESOURCE_RELATIVE_PATH "/sdcard/resource"
794 #else
795 #define RTI_TEST_RESOURCE_RELATIVE_PATH "../../resource"
796 #endif
797#endif
798
814extern RTITestDllExport RTIBool RTITestSetting_getFullExamplePathFileName(
815 const struct RTITestSetting *setting,
816 char *fullPathFileName,
817 const char *relativeExamplePathFileName);
818
827extern RTITestDllExport RTIBool RTITestSetting_getFullExamplePathFileNameEx(
828 const struct RTITestSetting *setting,
829 char *fullPathFileName,
830 const char *exampleRelativePath,
831 const char *relativeExamplePathFileName);
832
845extern RTITestDllExport RTIBool RTITestSetting_getExecutableFullPathFileName(
846 const struct RTITestSetting *setting,
847 char *fullPathFileName);
848
854extern RTITestDllExport RTIBool
855RTITestSetting_fileTestIsSupport(const struct RTITestSetting *setting);
856
862extern RTITestDllExport RTIBool
863RTITestSetting_fileSystemIsWritable(const struct RTITestSetting *setting);
864
877extern RTITestDllExport FILE *RTITestSetting_createTempFile(
878 const struct RTITestSetting *setting,
879 char *fullPathFileName,
880 const char *relativeFileName,
881 const char *fileAccessMode);
882
895extern RTITestDllExport void RTITestSetting_init(
896 struct RTITestSetting *setting);
897
921extern RTITestDllExport RTIBool RTITestSetting_getTempFileName(
922 char *fileName,
923 size_t fileNameMaxSize,
924 const char *filePrefix,
925 const char *fileSuffix);
926
934extern RTITestDllExport
935RTIBool RTITestSetting_isLowMemoryParticipantQosSetting(void);
936
944extern RTITestDllExport
945RTIBool RTITestSetting_isMinimalValidationArchitecture(void);
946
956extern RTITestDllExport
957RTIBool RTITestSetting_isExtendedValidationArchitecture(void);
958
966extern RTITestDllExport
967RTIBool RTITestSetting_isCoreBasicPubSubValidationArchitecture(void);
968
974extern RTITestDllExport
975RTIBool RTITestSetting_disableShmem(void);
976
1001extern RTITestDllExport int RTITestSetting_enableHeapMonitoringSupport(void);
1002
1023extern RTITestDllExport void RTITestSetting_disableHeapMonitoringSupport(int *ok);
1024
1033extern RTITestDllVariable
1034char RTITestSetting_g_networkCaptureFileNamePrefix[
1035 RTI_TEST_MAX_FILE_NAME_LENGTH];
1036
1059extern RTITestDllExport
1060void RTITestSetting_enableAndStartNetworkCaptureSupport(RTIBool *ok);
1061
1074extern RTITestDllExport
1075void RTITestSetting_stopAndDisableNetworkCaptureSupport(
1076 RTITestReturnCode *result);
1077
1082#define RTITestSetting_getTestCount(testArray) \
1083 (sizeof((testArray)) / sizeof(RTITestFunction))
1084
1089#define RTITestSetting_getDomainId(setting) \
1090 ((setting->id == 0) ? TEST_DOMAIN : setting->id)
1091
1101extern RTITestDllExport int RTITestSetting_getCurrentNumberOfRetries(void);
1102
1103/************************************ Setup ***********************************/
1104
1110extern RTITestDllExport RTIBool RTITestSetting_isSetupInitialized(void);
1111
1116extern RTITestDllExport void RTITestSetting_initializeSetup(void);
1117
1118#ifdef __cplusplus
1119} /* extern "C" */
1120#endif
1121
1122#include "rtitest/test_setting_impl.h"
1123
1124#endif /* rtitest_setting_h */
#define RTITestReturnCode
Return code used for tests.
Definition: test_types.h:48
RTITestReturnCode(* RTITestFunction)(const struct RTITestSetting *setting)
Function prototype for all tests.
Definition: test_setting.h:642
void RTITestSetting_init(struct RTITestSetting *setting)
Fill setting with default values.
int RTITestSetting_getCurrentNumberOfRetries(void)
Get the current number of retries.
void RTITestSetting_getRange(const struct RTITestSetting *setting, int *begin, int *end, RTITestLevel currentLevel)
Given the test setting and the test level, this function extracts the index of the first and last tes...
void RTITestSetting_printComplete(const char *methodName)
Printout to indicate completion of a Tester.
int RTITestSetting_enableHeapMonitoringSupport(void)
Enables heap monitoring support.
RTIBool RTITestSetting_parseArgument(struct RTITestSetting *setting, int argCount, char **argv)
Parses command-line arguments to initialize an RTITestSetting structure.
void RTITestSetting_disableHeapMonitoringSupport(int *ok)
Disables heap monitoring support and checks if there are memory leaks.
RTITestReturnCode RTITestSetting_runTests(const struct RTITestSetting *setting, const char *methodName, const RTITestFunction *test, int testCount, int begin, int end)
Given a set of tests and a test setting, run a subset of these tests with that test setting.