VirtualBox

source: vbox/trunk/include/iprt/test.h@ 92059

Last change on this file since 92059 was 88311, checked in by vboxsync, 4 years ago

IPRT/test: Added RTTestErrContext (with variations) for setting a print-once-on-failure message to help put a failure in context w/o needing to get verbose on successful runs. bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.0 KB
Line 
1/** @file
2 * IPRT - Testcase Framework.
3 */
4
5/*
6 * Copyright (C) 2009-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_test_h
27#define IPRT_INCLUDED_test_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34#include <iprt/stdarg.h>
35#include <iprt/assert.h>
36
37RT_C_DECLS_BEGIN
38
39/** @defgroup grp_rt_test RTTest - Testcase Framework.
40 * @ingroup grp_rt
41 * @{
42 */
43
44/** A test handle. */
45typedef R3PTRTYPE(struct RTTESTINT *) RTTEST;
46/** A pointer to a test handle. */
47typedef RTTEST *PRTTEST;
48/** A const pointer to a test handle. */
49typedef RTTEST const *PCRTTEST;
50
51/** A NIL Test handle. */
52#define NIL_RTTEST ((RTTEST)0)
53
54/**
55 * Test message importance level.
56 */
57typedef enum RTTESTLVL
58{
59 /** Invalid 0. */
60 RTTESTLVL_INVALID = 0,
61 /** Message should always be printed. */
62 RTTESTLVL_ALWAYS,
63 /** Failure message. */
64 RTTESTLVL_FAILURE,
65 /** Sub-test banner. */
66 RTTESTLVL_SUB_TEST,
67 /** Info message. */
68 RTTESTLVL_INFO,
69 /** Debug message. */
70 RTTESTLVL_DEBUG,
71 /** The last (invalid). */
72 RTTESTLVL_END
73} RTTESTLVL;
74
75
76/**
77 * Creates a test instance.
78 *
79 * @returns IPRT status code.
80 * @param pszTest The test name.
81 * @param phTest Where to store the test instance handle.
82 */
83RTR3DECL(int) RTTestCreate(const char *pszTest, PRTTEST phTest);
84
85/**
86 * Creates a test instance for a child process.
87 *
88 * This differs from RTTestCreate in that it disabled result reporting to file
89 * and pipe in order to avoid producing invalid XML.
90 *
91 * @returns IPRT status code.
92 * @param pszTest The test name.
93 * @param phTest Where to store the test instance handle.
94 */
95RTR3DECL(int) RTTestCreateChild(const char *pszTest, PRTTEST phTest);
96
97/** @name RTTEST_C_XXX - Flags for RTTestCreateEx.
98 * @{ */
99/** Whether to check the IPRT_TEST_XXX variables when constructing the
100 * instance. The following environment variables get checks:
101 *
102 * - IPRT_TEST_MAX_LEVEL: String value indicating which level.
103 * The env. var. is applied if the program specified the default level
104 * (by passing RTTESTLVL_INVALID).
105 *
106 * - IPRT_TEST_PIPE: The native pipe/fifo handle to write XML
107 * results to.
108 * The env. var. is applied if iNativeTestPipe is -1.
109 *
110 * - IPRT_TEST_FILE: Path to file/named-pipe/fifo/whatever to
111 * write XML results to.
112 * The env. var. is applied if the program specified a NULL path, it is
113 * not applied if the program hands us an empty string.
114 *
115 * - IPRT_TEST_OMIT_TOP_TEST: If present, this makes the XML output omit
116 * the top level test element.
117 * The env. var is applied when present.
118 *
119 */
120#define RTTEST_C_USE_ENV RT_BIT(0)
121/** Whether to omit the top test in the XML. */
122#define RTTEST_C_XML_OMIT_TOP_TEST RT_BIT(1)
123/** Whether to delay the top test XML element until testing commences. */
124#define RTTEST_C_XML_DELAY_TOP_TEST RT_BIT(2)
125/** Whether to try install the test instance in the test TLS slot. Setting
126 * this flag is incompatible with using the RTTestIXxxx variant of the API. */
127#define RTTEST_C_NO_TLS RT_BIT(3)
128/** Don't report to the pipe (IPRT_TEST_PIPE or other). */
129#define RTTEST_C_NO_XML_REPORTING_PIPE RT_BIT(4)
130/** Don't report to the results file (IPRT_TEST_FILE or other). */
131#define RTTEST_C_NO_XML_REPORTING_FILE RT_BIT(4)
132/** No XML reporting to pipes, file or anything.
133 * Child processes may want to use this so they don't garble the output of
134 * the main test process. */
135#define RTTEST_C_NO_XML_REPORTING (RTTEST_C_NO_XML_REPORTING_PIPE | RTTEST_C_NO_XML_REPORTING_FILE)
136/** Mask containing the valid bits. */
137#define RTTEST_C_VALID_MASK UINT32_C(0x0000003f)
138/** @} */
139
140
141/**
142 * Creates a test instance.
143 *
144 * @returns IPRT status code.
145 * @param pszTest The test name.
146 * @param fFlags Flags, see RTTEST_C_XXX.
147 * @param enmMaxLevel The max message level. Use RTTESTLVL_INVALID for
148 * the default output level or one from the
149 * environment. If specified, the environment variable
150 * will not be able to override it.
151 * @param iNativeTestPipe Native handle to a test pipe. -1 if not interested.
152 * @param pszXmlFile The XML output file name. If NULL the environment
153 * may be used. To selectively avoid that, pass an
154 * empty string.
155 * @param phTest Where to store the test instance handle.
156 *
157 * @note At the moment, we don't fail if @a pszXmlFile or @a iNativeTestPipe
158 * fails to open. This may change later.
159 */
160RTR3DECL(int) RTTestCreateEx(const char *pszTest, uint32_t fFlags, RTTESTLVL enmMaxLevel,
161 RTHCINTPTR iNativeTestPipe, const char *pszXmlFile, PRTTEST phTest);
162
163/**
164 * Initializes IPRT and creates a test instance.
165 *
166 * Typical usage is:
167 * @code
168 int main(int argc, char **argv)
169 {
170 RTTEST hTest;
171 int rc = RTTestInitAndCreate("tstSomething", &hTest);
172 if (rc)
173 return rc;
174 ...
175 }
176 @endcode
177 *
178 * @returns RTEXITCODE_SUCCESS on success. On failure an error message is
179 * printed and a suitable exit code is return.
180 *
181 * @param pszTest The test name.
182 * @param phTest Where to store the test instance handle.
183 */
184RTR3DECL(RTEXITCODE) RTTestInitAndCreate(const char *pszTest, PRTTEST phTest);
185
186/**
187 * Variant of RTTestInitAndCreate that includes IPRT init flags and argument
188 * vectors.
189 *
190 * @returns RTEXITCODE_SUCCESS on success. On failure an error message is
191 * printed and a suitable exit code is return.
192 *
193 * @param cArgs Pointer to the argument count.
194 * @param ppapszArgs Pointer to the argument vector pointer.
195 * @param fRtInit Flags, see RTR3INIT_XXX.
196 * @param pszTest The test name.
197 * @param phTest Where to store the test instance handle.
198 */
199RTR3DECL(RTEXITCODE) RTTestInitExAndCreate(int cArgs, char ***ppapszArgs, uint32_t fRtInit, const char *pszTest, PRTTEST phTest);
200
201/**
202 * Destroys a test instance previously created by RTTestCreate.
203 *
204 * @returns IPRT status code.
205 * @param hTest The test handle. NIL_RTTEST is ignored.
206 */
207RTR3DECL(int) RTTestDestroy(RTTEST hTest);
208
209/**
210 * Changes the default test instance for the calling thread.
211 *
212 * @returns IPRT status code.
213 *
214 * @param hNewDefaultTest The new default test. NIL_RTTEST is fine.
215 * @param phOldTest Where to store the old test handle. Optional.
216 */
217RTR3DECL(int) RTTestSetDefault(RTTEST hNewDefaultTest, PRTTEST phOldTest);
218
219/**
220 * Changes the test case name.
221 *
222 * @returns IRPT status code.
223 * @param hTest The test handle. If NIL_RTTEST we'll use the one
224 * associated with the calling thread.
225 * @param pszName The new test case name. Empty string is not accepted,
226 * nor are strings longer than 127 chars. Keep it short
227 * but descriptive.
228 */
229RTR3DECL(int) RTTestChangeName(RTTEST hTest, const char *pszName);
230
231/**
232 * Allocate a block of guarded memory.
233 *
234 * @returns IPRT status code.
235 * @param hTest The test handle. If NIL_RTTEST we'll use the one
236 * associated with the calling thread.
237 * @param cb The amount of memory to allocate.
238 * @param cbAlign The alignment of the returned block.
239 * @param fHead Head or tail optimized guard.
240 * @param ppvUser Where to return the pointer to the block.
241 */
242RTR3DECL(int) RTTestGuardedAlloc(RTTEST hTest, size_t cb, uint32_t cbAlign, bool fHead, void **ppvUser);
243
244/**
245 * Allocates a block of guarded memory where the guarded is immediately after
246 * the user memory.
247 *
248 * @returns Pointer to the allocated memory. NULL on failure.
249 * @param hTest The test handle. If NIL_RTTEST we'll use the one
250 * associated with the calling thread.
251 * @param cb The amount of memory to allocate.
252 */
253RTR3DECL(void *) RTTestGuardedAllocTail(RTTEST hTest, size_t cb);
254
255/**
256 * Allocates a block of guarded memory where the guarded is right in front of
257 * the user memory.
258 *
259 * @returns Pointer to the allocated memory. NULL on failure.
260 * @param hTest The test handle. If NIL_RTTEST we'll use the one
261 * associated with the calling thread.
262 * @param cb The amount of memory to allocate.
263 */
264RTR3DECL(void *) RTTestGuardedAllocHead(RTTEST hTest, size_t cb);
265
266/**
267 * Frees a block of guarded memory.
268 *
269 * @returns IPRT status code.
270 * @param hTest The test handle. If NIL_RTTEST we'll use the one
271 * associated with the calling thread.
272 * @param pv The memory. NULL is ignored.
273 */
274RTR3DECL(int) RTTestGuardedFree(RTTEST hTest, void *pv);
275
276/**
277 * Test vprintf making sure the output starts on a new line.
278 *
279 * @returns Number of chars printed.
280 * @param hTest The test handle. If NIL_RTTEST we'll use the one
281 * associated with the calling thread.
282 * @param enmLevel Message importance level.
283 * @param pszFormat The message.
284 * @param va Arguments.
285 */
286RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
287
288/**
289 * Test printf making sure the output starts on a new line.
290 *
291 * @returns Number of chars printed.
292 * @param hTest The test handle. If NIL_RTTEST we'll use the one
293 * associated with the calling thread.
294 * @param enmLevel Message importance level.
295 * @param pszFormat The message.
296 * @param ... Arguments.
297 */
298RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
299
300/**
301 * Test vprintf, makes sure lines are prefixed and so forth.
302 *
303 * @returns Number of chars printed.
304 * @param hTest The test handle. If NIL_RTTEST we'll use the one
305 * associated with the calling thread.
306 * @param enmLevel Message importance level.
307 * @param pszFormat The message.
308 * @param va Arguments.
309 */
310RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
311
312/**
313 * Test printf, makes sure lines are prefixed and so forth.
314 *
315 * @returns Number of chars printed.
316 * @param hTest The test handle. If NIL_RTTEST we'll use the one
317 * associated with the calling thread.
318 * @param enmLevel Message importance level.
319 * @param pszFormat The message.
320 * @param ... Arguments.
321 */
322RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
323
324/**
325 * Prints the test banner.
326 *
327 * @returns Number of chars printed.
328 * @param hTest The test handle. If NIL_RTTEST we'll use the one
329 * associated with the calling thread.
330 */
331RTR3DECL(int) RTTestBanner(RTTEST hTest);
332
333/**
334 * Summaries the test, destroys the test instance and return an exit code.
335 *
336 * @returns Test program exit code.
337 * @param hTest The test handle. If NIL_RTTEST we'll use the one
338 * associated with the calling thread.
339 */
340RTR3DECL(RTEXITCODE) RTTestSummaryAndDestroy(RTTEST hTest);
341
342/**
343 * Skips the test, destroys the test instance and return an exit code.
344 *
345 * @returns Test program exit code.
346 * @param hTest The test handle. If NIL_RTTEST we'll use the one
347 * associated with the calling thread.
348 * @param pszReasonFmt Text explaining why, optional (NULL).
349 * @param va Arguments for the reason format string.
350 */
351RTR3DECL(RTEXITCODE) RTTestSkipAndDestroyV(RTTEST hTest, const char *pszReasonFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
352
353/**
354 * Skips the test, destroys the test instance and return an exit code.
355 *
356 * @returns Test program exit code.
357 * @param hTest The test handle. If NIL_RTTEST we'll use the one
358 * associated with the calling thread.
359 * @param pszReasonFmt Text explaining why, optional (NULL).
360 * @param ... Arguments for the reason format string.
361 */
362RTR3DECL(RTEXITCODE) RTTestSkipAndDestroy(RTTEST hTest, const char *pszReasonFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
363
364/**
365 * Starts a sub-test.
366 *
367 * This will perform an implicit RTTestSubDone() call if that has not been done
368 * since the last RTTestSub call.
369 *
370 * @returns Number of chars printed.
371 * @param hTest The test handle. If NIL_RTTEST we'll use the one
372 * associated with the calling thread.
373 * @param pszSubTest The sub-test name.
374 */
375RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest);
376
377/**
378 * Format string version of RTTestSub.
379 *
380 * See RTTestSub for details.
381 *
382 * @returns Number of chars printed.
383 * @param hTest The test handle. If NIL_RTTEST we'll use the one
384 * associated with the calling thread.
385 * @param pszSubTestFmt The sub-test name format string.
386 * @param ... Arguments.
387 */
388RTR3DECL(int) RTTestSubF(RTTEST hTest, const char *pszSubTestFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
389
390/**
391 * Format string version of RTTestSub.
392 *
393 * See RTTestSub for details.
394 *
395 * @returns Number of chars printed.
396 * @param hTest The test handle. If NIL_RTTEST we'll use the one
397 * associated with the calling thread.
398 * @param pszSubTestFmt The sub-test name format string.
399 * @param va Arguments.
400 */
401RTR3DECL(int) RTTestSubV(RTTEST hTest, const char *pszSubTestFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
402
403/**
404 * Completes a sub-test.
405 *
406 * @returns Number of chars printed, negative numbers are IPRT error codes.
407 * @param hTest The test handle. If NIL_RTTEST we'll use the one
408 * associated with the calling thread.
409 */
410RTR3DECL(int) RTTestSubDone(RTTEST hTest);
411
412/**
413 * Prints an extended PASSED message, optional.
414 *
415 * This does not conclude the sub-test, it could be used to report the passing
416 * of a sub-sub-to-the-power-of-N-test.
417 *
418 * @returns Number of chars printed, negative numbers are IPRT error codes.
419 * @param hTest The test handle. If NIL_RTTEST we'll use the one
420 * associated with the calling thread.
421 * @param pszFormat The message. No trailing newline.
422 * @param va The arguments.
423 */
424RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
425
426/**
427 * Prints an extended PASSED message, optional.
428 *
429 * This does not conclude the sub-test, it could be used to report the passing
430 * of a sub-sub-to-the-power-of-N-test.
431 *
432 * @returns Number of chars printed, negative numbers are IPRT error codes.
433 * @param hTest The test handle. If NIL_RTTEST we'll use the one
434 * associated with the calling thread.
435 * @param pszFormat The message. No trailing newline.
436 * @param ... The arguments.
437 */
438RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
439
440/**
441 * Marks the current test as 'SKIPPED' and optionally displays a message
442 * explaining why.
443 *
444 * @returns Number of chars printed, negative numbers are IPRT error codes.
445 * @param hTest The test handle. If NIL_RTTEST we'll use the one
446 * associated with the calling thread.
447 * @param pszFormat The message. No trailing newline. Can be NULL or empty.
448 * @param ... The arguments.
449 */
450RTR3DECL(int) RTTestSkipped(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR_MAYBE_NULL(2, 3);
451
452/**
453 * Marks the current test as 'SKIPPED' and optionally displays a message
454 * explaining why.
455 *
456 * @returns Number of chars printed, negative numbers are IPRT error codes.
457 * @param hTest The test handle. If NIL_RTTEST we'll use the one
458 * associated with the calling thread.
459 * @param pszFormat The message. No trailing newline. Can be NULL or empty.
460 * @param va The arguments.
461 */
462RTR3DECL(int) RTTestSkippedV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR_MAYBE_NULL(2, 0);
463
464
465/**
466 * Value units.
467 *
468 * @remarks This is an interface where we have to be binary compatible with both
469 * older versions of this header and other components using the same
470 * contant values.
471 * @remarks When adding a new item:
472 * - Always add at the end of the list - do NOT group it.
473 * - Add it to rtTestUnitName in r3/test.cpp.
474 * - include/VBox/VMMDevTesting.h (VMMDEV_TESTING_UNIT_XXX).
475 * - Add it to g_aszBs2TestUnitNames in
476 * TestSuite/bootsectors/bootsector2-common-routines.mac.
477 *
478 */
479typedef enum RTTESTUNIT
480{
481 /** The customary invalid zero value. */
482 RTTESTUNIT_INVALID = 0,
483
484 RTTESTUNIT_PCT, /**< Percentage (10^-2). */
485 RTTESTUNIT_BYTES, /**< Bytes. */
486 RTTESTUNIT_BYTES_PER_SEC, /**< Bytes per second. */
487 RTTESTUNIT_KILOBYTES, /**< Kilobytes. */
488 RTTESTUNIT_KILOBYTES_PER_SEC, /**< Kilobytes per second. */
489 RTTESTUNIT_MEGABYTES, /**< Megabytes. */
490 RTTESTUNIT_MEGABYTES_PER_SEC, /**< Megabytes per second. */
491 RTTESTUNIT_PACKETS, /**< Packets. */
492 RTTESTUNIT_PACKETS_PER_SEC, /**< Packets per second. */
493 RTTESTUNIT_FRAMES, /**< Frames. */
494 RTTESTUNIT_FRAMES_PER_SEC, /**< Frames per second. */
495 RTTESTUNIT_OCCURRENCES, /**< Occurrences. */
496 RTTESTUNIT_OCCURRENCES_PER_SEC, /**< Occurrences per second. */
497 RTTESTUNIT_CALLS, /**< Calls. */
498 RTTESTUNIT_CALLS_PER_SEC, /**< Calls per second. */
499 RTTESTUNIT_ROUND_TRIP, /**< Round trips. */
500 RTTESTUNIT_SECS, /**< Seconds. */
501 RTTESTUNIT_MS, /**< Milliseconds. */
502 RTTESTUNIT_NS, /**< Nanoseconds. */
503 RTTESTUNIT_NS_PER_CALL, /**< Nanoseconds per call. */
504 RTTESTUNIT_NS_PER_FRAME, /**< Nanoseconds per frame. */
505 RTTESTUNIT_NS_PER_OCCURRENCE, /**< Nanoseconds per occurrence. */
506 RTTESTUNIT_NS_PER_PACKET, /**< Nanoseconds per frame. */
507 RTTESTUNIT_NS_PER_ROUND_TRIP, /**< Nanoseconds per round trip. */
508 RTTESTUNIT_INSTRS, /**< Instructions. */
509 RTTESTUNIT_INSTRS_PER_SEC, /**< Instructions per second. */
510 RTTESTUNIT_NONE, /**< No unit. */
511 RTTESTUNIT_PP1K, /**< Parts per thousand (10^-3). */
512 RTTESTUNIT_PP10K, /**< Parts per ten thousand (10^-4). */
513 RTTESTUNIT_PPM, /**< Parts per million (10^-6). */
514 RTTESTUNIT_PPB, /**< Parts per billion (10^-9). */
515
516 /** The end of valid units. */
517 RTTESTUNIT_END
518} RTTESTUNIT;
519AssertCompile(RTTESTUNIT_INSTRS == 0x19);
520AssertCompile(RTTESTUNIT_NONE == 0x1b);
521
522/**
523 * Report a named test result value.
524 *
525 * This is typically used for benchmarking but can be used for other purposes
526 * like reporting limits of some implementation. The value gets associated with
527 * the current sub test, the name must be unique within the sub test.
528 *
529 * @returns IPRT status code.
530 *
531 * @param hTest The test handle. If NIL_RTTEST we'll use the one
532 * associated with the calling thread.
533 * @param pszName The value name.
534 * @param u64Value The value.
535 * @param enmUnit The value unit.
536 */
537RTR3DECL(int) RTTestValue(RTTEST hTest, const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
538
539/**
540 * Same as RTTestValue, except that the name is now a format string.
541 *
542 * @returns IPRT status code.
543 *
544 * @param hTest The test handle. If NIL_RTTEST we'll use the one
545 * associated with the calling thread.
546 * @param u64Value The value.
547 * @param enmUnit The value unit.
548 * @param pszNameFmt The value name format string.
549 * @param ... String arguments.
550 */
551RTR3DECL(int) RTTestValueF(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit,
552 const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(4, 5);
553
554/**
555 * Same as RTTestValue, except that the name is now a format string.
556 *
557 * @returns IPRT status code.
558 *
559 * @param hTest The test handle. If NIL_RTTEST we'll use the one
560 * associated with the calling thread.
561 * @param u64Value The value.
562 * @param enmUnit The value unit.
563 * @param pszNameFmt The value name format string.
564 * @param va String arguments.
565 */
566RTR3DECL(int) RTTestValueV(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit,
567 const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
568
569/**
570 * Increments the error counter.
571 *
572 * @returns IPRT status code.
573 * @param hTest The test handle. If NIL_RTTEST we'll use the one
574 * associated with the calling thread.
575 */
576RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
577
578/**
579 * Get the current error count.
580 *
581 * @returns The error counter, UINT32_MAX if no valid test handle.
582 * @param hTest The test handle. If NIL_RTTEST we'll use the one
583 * associated with the calling thread.
584 */
585RTR3DECL(uint32_t) RTTestErrorCount(RTTEST hTest);
586
587/**
588 * Get the error count of the current sub test.
589 *
590 * @returns The error counter, UINT32_MAX if no valid test handle.
591 * @param hTest The test handle. If NIL_RTTEST we'll use the one
592 * associated with the calling thread.
593 */
594RTR3DECL(uint32_t) RTTestSubErrorCount(RTTEST hTest);
595
596/**
597 * Increments the error counter and prints a failure message.
598 *
599 * @returns IPRT status code.
600 * @param hTest The test handle. If NIL_RTTEST we'll use the one
601 * associated with the calling thread.
602 * @param pszFormat The message. No trailing newline.
603 * @param va The arguments.
604 */
605RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
606
607/**
608 * Increments the error counter and prints a failure message.
609 *
610 * @returns IPRT status code.
611 * @param hTest The test handle. If NIL_RTTEST we'll use the one
612 * associated with the calling thread.
613 * @param pszFormat The message. No trailing newline.
614 * @param ... The arguments.
615 */
616RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
617
618/**
619 * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
620 *
621 * @returns Number of chars printed.
622 * @param hTest The test handle. If NIL_RTTEST we'll use the one
623 * associated with the calling thread.
624 * @param pszFormat The message.
625 * @param va Arguments.
626 */
627RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
628
629/**
630 * Same as RTTestPrintf with RTTESTLVL_FAILURE.
631 *
632 * @returns Number of chars printed.
633 * @param hTest The test handle. If NIL_RTTEST we'll use the one
634 * associated with the calling thread.
635 * @param pszFormat The message.
636 * @param ... Arguments.
637 */
638RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
639
640/**
641 * Sets error context info to be printed with the first failure.
642 *
643 * @returns IPRT status code.
644 * @param hTest The test handle. If NIL_RTTEST we'll use the one
645 * associated with the calling thread.
646 * @param pszFormat The message, no trailing newline. NULL to clear the
647 * context message.
648 * @param va The arguments.
649 */
650RTR3DECL(int) RTTestErrContextV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
651
652/**
653 * Sets error context info to be printed with the first failure.
654 *
655 * @returns IPRT status code.
656 * @param hTest The test handle. If NIL_RTTEST we'll use the one
657 * associated with the calling thread.
658 * @param pszFormat The message, no trailing newline. NULL to clear the
659 * context message.
660 * @param ... The arguments.
661 */
662RTR3DECL(int) RTTestErrContext(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
663
664/**
665 * Disables and shuts up assertions.
666 *
667 * Max 8 nestings.
668 *
669 * @returns IPRT status code.
670 * @param hTest The test handle. If NIL_RTTEST we'll use the one
671 * associated with the calling thread.
672 * @sa RTAssertSetMayPanic, RTAssertSetQuiet.
673 */
674RTR3DECL(int) RTTestDisableAssertions(RTTEST hTest);
675
676/**
677 * Restores the previous call to RTTestDisableAssertions.
678 *
679 * @returns IPRT status code.
680 * @param hTest The test handle. If NIL_RTTEST we'll use the one
681 * associated with the calling thread.
682 */
683RTR3DECL(int) RTTestRestoreAssertions(RTTEST hTest);
684
685
686/** @def RTTEST_CHECK
687 * Check whether a boolean expression holds true.
688 *
689 * If the expression is false, call RTTestFailed giving the line number and expression.
690 *
691 * @param hTest The test handle.
692 * @param expr The expression to evaluate.
693 */
694#define RTTEST_CHECK(hTest, expr) \
695 do { if (!(expr)) { \
696 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
697 } \
698 } while (0)
699/** @def RTTEST_CHECK_RET
700 * Check whether a boolean expression holds true, returns on false.
701 *
702 * If the expression is false, call RTTestFailed giving the line number and
703 * expression, then return @a rcRet.
704 *
705 * @param hTest The test handle.
706 * @param expr The expression to evaluate.
707 * @param rcRet What to return on failure.
708 */
709#define RTTEST_CHECK_RET(hTest, expr, rcRet) \
710 do { if (!(expr)) { \
711 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
712 return (rcRet); \
713 } \
714 } while (0)
715/** @def RTTEST_CHECK_RETV
716 * Check whether a boolean expression holds true, returns void on false.
717 *
718 * If the expression is false, call RTTestFailed giving the line number and
719 * expression, then return void.
720 *
721 * @param hTest The test handle.
722 * @param expr The expression to evaluate.
723 */
724#define RTTEST_CHECK_RETV(hTest, expr) \
725 do { if (!(expr)) { \
726 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
727 return; \
728 } \
729 } while (0)
730/** @def RTTEST_CHECK_BREAK
731 * Check whether a boolean expression holds true.
732 *
733 * If the expression is false, call RTTestFailed giving the line number and
734 * expression, then break.
735 *
736 * @param hTest The test handle.
737 * @param expr The expression to evaluate.
738 */
739#define RTTEST_CHECK_BREAK(hTest, expr) \
740 if (!(expr)) { \
741 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
742 break; \
743 } else do {} while (0)
744
745
746/** @def RTTEST_CHECK_MSG
747 * Check whether a boolean expression holds true.
748 *
749 * If the expression is false, call RTTestFailed giving the line number and expression.
750 *
751 * @param hTest The test handle.
752 * @param expr The expression to evaluate.
753 * @param DetailsArgs Argument list for RTTestFailureDetails, including
754 * parenthesis.
755 */
756#define RTTEST_CHECK_MSG(hTest, expr, DetailsArgs) \
757 do { if (!(expr)) { \
758 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
759 RTTestFailureDetails DetailsArgs; \
760 } \
761 } while (0)
762/** @def RTTEST_CHECK_MSG_RET
763 * Check whether a boolean expression holds true, returns on false.
764 *
765 * If the expression is false, call RTTestFailed giving the line number and expression.
766 *
767 * @param hTest The test handle.
768 * @param expr The expression to evaluate.
769 * @param DetailsArgs Argument list for RTTestFailureDetails, including
770 * parenthesis.
771 * @param rcRet What to return on failure.
772 */
773#define RTTEST_CHECK_MSG_RET(hTest, expr, DetailsArgs, rcRet) \
774 do { if (!(expr)) { \
775 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
776 RTTestFailureDetails DetailsArgs; \
777 return (rcRet); \
778 } \
779 } while (0)
780/** @def RTTEST_CHECK_MSG_RETV
781 * Check whether a boolean expression holds true, returns void on false.
782 *
783 * If the expression is false, call RTTestFailed giving the line number and expression.
784 *
785 * @param hTest The test handle.
786 * @param expr The expression to evaluate.
787 * @param DetailsArgs Argument list for RTTestFailureDetails, including
788 * parenthesis.
789 */
790#define RTTEST_CHECK_MSG_RETV(hTest, expr, DetailsArgs) \
791 do { if (!(expr)) { \
792 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
793 RTTestFailureDetails DetailsArgs; \
794 return; \
795 } \
796 } while (0)
797
798
799/** @def RTTEST_CHECK_RC
800 * Check whether an expression returns a specific IPRT style status code.
801 *
802 * If a different status code is return, call RTTestFailed giving the line
803 * number, expression, actual and expected status codes.
804 *
805 * @param hTest The test handle.
806 * @param rcExpr The expression resulting in an IPRT status code.
807 * @param rcExpect The expected return code. This may be referenced
808 * more than once by the macro.
809 */
810#define RTTEST_CHECK_RC(hTest, rcExpr, rcExpect) \
811 do { \
812 int rcCheck = (rcExpr); \
813 if (rcCheck != (rcExpect)) { \
814 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
815 } \
816 } while (0)
817/** @def RTTEST_CHECK_RC_RET
818 * Check whether an expression returns a specific IPRT style status code.
819 *
820 * If a different status code is return, call RTTestFailed giving the line
821 * number, expression, actual and expected status codes, then return.
822 *
823 * @param hTest The test handle.
824 * @param rcExpr The expression resulting in an IPRT status code.
825 * This will be assigned to a local rcCheck variable
826 * that can be used as return value.
827 * @param rcExpect The expected return code. This may be referenced
828 * more than once by the macro.
829 * @param rcRet The return code.
830 */
831#define RTTEST_CHECK_RC_RET(hTest, rcExpr, rcExpect, rcRet) \
832 do { \
833 int rcCheck = (rcExpr); \
834 if (rcCheck != (rcExpect)) { \
835 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
836 return (rcRet); \
837 } \
838 } while (0)
839/** @def RTTEST_CHECK_RC_RETV
840 * Check whether an expression returns a specific IPRT style status code.
841 *
842 * If a different status code is return, call RTTestFailed giving the line
843 * number, expression, actual and expected status codes, then return.
844 *
845 * @param hTest The test handle.
846 * @param rcExpr The expression resulting in an IPRT status code.
847 * @param rcExpect The expected return code. This may be referenced
848 * more than once by the macro.
849 */
850#define RTTEST_CHECK_RC_RETV(hTest, rcExpr, rcExpect) \
851 do { \
852 int rcCheck = (rcExpr); \
853 if (rcCheck != (rcExpect)) { \
854 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
855 return; \
856 } \
857 } while (0)
858/** @def RTTEST_CHECK_RC_BREAK
859 * Check whether an expression returns a specific IPRT style status code.
860 *
861 * If a different status code is return, call RTTestFailed giving the line
862 * number, expression, actual and expected status codes, then break.
863 *
864 * @param hTest The test handle.
865 * @param rcExpr The expression resulting in an IPRT status code.
866 * @param rcExpect The expected return code. This may be referenced
867 * more than once by the macro.
868 */
869#define RTTEST_CHECK_RC_BREAK(hTest, rcExpr, rcExpect) \
870 if (1) { \
871 int rcCheck = (rcExpr); \
872 if (rcCheck != (rcExpect)) { \
873 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
874 break; \
875 } \
876 } else do {} while (0)
877
878
879/** @def RTTEST_CHECK_RC_OK
880 * Check whether a IPRT style status code indicates success.
881 *
882 * If the status indicates failure, call RTTestFailed giving the line number,
883 * expression and status code.
884 *
885 * @param hTest The test handle.
886 * @param rcExpr The expression resulting in an IPRT status code.
887 */
888#define RTTEST_CHECK_RC_OK(hTest, rcExpr) \
889 do { \
890 int rcCheck = (rcExpr); \
891 if (RT_FAILURE(rcCheck)) { \
892 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
893 } \
894 } while (0)
895/** @def RTTEST_CHECK_RC_OK_RET
896 * Check whether a IPRT style status code indicates success.
897 *
898 * If the status indicates failure, call RTTestFailed giving the line number,
899 * expression and status code, then return with the specified value.
900 *
901 * @param hTest The test handle.
902 * @param rcExpr The expression resulting in an IPRT status code.
903 * This will be assigned to a local rcCheck variable
904 * that can be used as return value.
905 * @param rcRet The return code.
906 */
907#define RTTEST_CHECK_RC_OK_RET(hTest, rcExpr, rcRet) \
908 do { \
909 int rcCheck = (rcExpr); \
910 if (RT_FAILURE(rcCheck)) { \
911 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
912 return (rcRet); \
913 } \
914 } while (0)
915/** @def RTTEST_CHECK_RC_OK_RETV
916 * Check whether a IPRT style status code indicates success.
917 *
918 * If the status indicates failure, call RTTestFailed giving the line number,
919 * expression and status code, then return.
920 *
921 * @param hTest The test handle.
922 * @param rcExpr The expression resulting in an IPRT status code.
923 */
924#define RTTEST_CHECK_RC_OK_RETV(hTest, rcExpr) \
925 do { \
926 int rcCheck = (rcExpr); \
927 if (RT_FAILURE(rcCheck)) { \
928 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
929 return; \
930 } \
931 } while (0)
932
933
934
935
936/** @name Implicit Test Handle API Variation
937 * The test handle is retrieved from the test TLS entry of the calling thread.
938 * @{
939 */
940
941/**
942 * Test vprintf, makes sure lines are prefixed and so forth.
943 *
944 * @returns Number of chars printed.
945 * @param enmLevel Message importance level.
946 * @param pszFormat The message.
947 * @param va Arguments.
948 */
949RTR3DECL(int) RTTestIPrintfV(RTTESTLVL enmLevel, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
950
951/**
952 * Test printf, makes sure lines are prefixed and so forth.
953 *
954 * @returns Number of chars printed.
955 * @param enmLevel Message importance level.
956 * @param pszFormat The message.
957 * @param ... Arguments.
958 */
959RTR3DECL(int) RTTestIPrintf(RTTESTLVL enmLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
960
961/**
962 * Starts a sub-test.
963 *
964 * This will perform an implicit RTTestSubDone() call if that has not been done
965 * since the last RTTestSub call.
966 *
967 * @returns Number of chars printed.
968 * @param pszSubTest The sub-test name.
969 */
970RTR3DECL(int) RTTestISub(const char *pszSubTest);
971
972/**
973 * Format string version of RTTestSub.
974 *
975 * See RTTestSub for details.
976 *
977 * @returns Number of chars printed.
978 * @param pszSubTestFmt The sub-test name format string.
979 * @param ... Arguments.
980 */
981RTR3DECL(int) RTTestISubF(const char *pszSubTestFmt, ...) RT_IPRT_FORMAT_ATTR(1, 2);
982
983/**
984 * Format string version of RTTestSub.
985 *
986 * See RTTestSub for details.
987 *
988 * @returns Number of chars printed.
989 * @param pszSubTestFmt The sub-test name format string.
990 * @param va Arguments.
991 */
992RTR3DECL(int) RTTestISubV(const char *pszSubTestFmt, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
993
994/**
995 * Completes a sub-test.
996 *
997 * @returns Number of chars printed.
998 */
999RTR3DECL(int) RTTestISubDone(void);
1000
1001/**
1002 * Prints an extended PASSED message, optional.
1003 *
1004 * This does not conclude the sub-test, it could be used to report the passing
1005 * of a sub-sub-to-the-power-of-N-test.
1006 *
1007 * @returns IPRT status code.
1008 * @param pszFormat The message. No trailing newline.
1009 * @param va The arguments.
1010 */
1011RTR3DECL(int) RTTestIPassedV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1012
1013/**
1014 * Prints an extended PASSED message, optional.
1015 *
1016 * This does not conclude the sub-test, it could be used to report the passing
1017 * of a sub-sub-to-the-power-of-N-test.
1018 *
1019 * @returns IPRT status code.
1020 * @param pszFormat The message. No trailing newline.
1021 * @param ... The arguments.
1022 */
1023RTR3DECL(int) RTTestIPassed(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1024
1025/**
1026 * Report a named test result value.
1027 *
1028 * This is typically used for benchmarking but can be used for other purposes
1029 * like reporting limits of some implementation. The value gets associated with
1030 * the current sub test, the name must be unique within the sub test.
1031 *
1032 * @returns IPRT status code.
1033 *
1034 * @param pszName The value name.
1035 * @param u64Value The value.
1036 * @param enmUnit The value unit.
1037 */
1038RTR3DECL(int) RTTestIValue(const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
1039
1040/**
1041 * Same as RTTestValue, except that the name is now a format string.
1042 *
1043 * @returns IPRT status code.
1044 *
1045 * @param u64Value The value.
1046 * @param enmUnit The value unit.
1047 * @param pszNameFmt The value name format string.
1048 * @param ... String arguments.
1049 */
1050RTR3DECL(int) RTTestIValueF(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
1051
1052/**
1053 * Same as RTTestValue, except that the name is now a format string.
1054 *
1055 * @returns IPRT status code.
1056 *
1057 * @param u64Value The value.
1058 * @param enmUnit The value unit.
1059 * @param pszNameFmt The value name format string.
1060 * @param va String arguments.
1061 */
1062RTR3DECL(int) RTTestIValueV(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
1063
1064/**
1065 * Increments the error counter.
1066 *
1067 * @returns IPRT status code.
1068 */
1069RTR3DECL(int) RTTestIErrorInc(void);
1070
1071/**
1072 * Get the current error count.
1073 *
1074 * @returns The error counter, UINT32_MAX if no valid test handle.
1075 */
1076RTR3DECL(uint32_t) RTTestIErrorCount(void);
1077
1078/**
1079 * Increments the error counter and prints a failure message.
1080 *
1081 * @returns IPRT status code.
1082 * @param pszFormat The message. No trailing newline.
1083 * @param va The arguments.
1084 */
1085RTR3DECL(int) RTTestIFailedV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1086
1087/**
1088 * Increments the error counter and prints a failure message.
1089 *
1090 * @returns IPRT status code.
1091 * @param pszFormat The message. No trailing newline.
1092 * @param ... The arguments.
1093 */
1094RTR3DECL(int) RTTestIFailed(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1095
1096/**
1097 * Increments the error counter, prints a failure message and returns the
1098 * specified status code.
1099 *
1100 * This is mainly a convenience method for saving vertical space in the source
1101 * code.
1102 *
1103 * @returns @a rcRet
1104 * @param rcRet The IPRT status code to return.
1105 * @param pszFormat The message. No trailing newline.
1106 * @param va The arguments.
1107 */
1108RTR3DECL(int) RTTestIFailedRcV(int rcRet, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
1109
1110/**
1111 * Increments the error counter, prints a failure message and returns the
1112 * specified status code.
1113 *
1114 * This is mainly a convenience method for saving vertical space in the source
1115 * code.
1116 *
1117 * @returns @a rcRet
1118 * @param rcRet The IPRT status code to return.
1119 * @param pszFormat The message. No trailing newline.
1120 * @param ... The arguments.
1121 */
1122RTR3DECL(int) RTTestIFailedRc(int rcRet, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
1123
1124/**
1125 * Same as RTTestIPrintfV with RTTESTLVL_FAILURE.
1126 *
1127 * @returns Number of chars printed.
1128 * @param pszFormat The message.
1129 * @param va Arguments.
1130 */
1131RTR3DECL(int) RTTestIFailureDetailsV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1132
1133/**
1134 * Same as RTTestIPrintf with RTTESTLVL_FAILURE.
1135 *
1136 * @returns Number of chars printed.
1137 * @param pszFormat The message.
1138 * @param ... Arguments.
1139 */
1140RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1141
1142/**
1143 * Sets error context info to be printed with the first failure.
1144 *
1145 * @returns IPRT status code.
1146 * @param pszFormat The message, no trailing newline. NULL to clear the
1147 * context message.
1148 * @param va The arguments.
1149 */
1150RTR3DECL(int) RTTestIErrContextV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1151
1152/**
1153 * Sets error context info to be printed with the first failure.
1154 *
1155 * @returns IPRT status code.
1156 * @param pszFormat The message, no trailing newline. NULL to clear the
1157 * context message.
1158 * @param ... The arguments.
1159 */
1160RTR3DECL(int) RTTestIErrContext(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1161
1162/**
1163 * Disables and shuts up assertions.
1164 *
1165 * Max 8 nestings.
1166 *
1167 * @returns IPRT status code.
1168 * @sa RTAssertSetMayPanic, RTAssertSetQuiet.
1169 */
1170RTR3DECL(int) RTTestIDisableAssertions(void);
1171
1172/**
1173 * Restores the previous call to RTTestDisableAssertions.
1174 *
1175 * @returns IPRT status code.
1176 */
1177RTR3DECL(int) RTTestIRestoreAssertions(void);
1178
1179
1180/** @def RTTESTI_CHECK
1181 * Check whether a boolean expression holds true.
1182 *
1183 * If the expression is false, call RTTestIFailed giving the line number and
1184 * expression.
1185 *
1186 * @param expr The expression to evaluate.
1187 */
1188#define RTTESTI_CHECK(expr) \
1189 do { if (!(expr)) { \
1190 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1191 } \
1192 } while (0)
1193/** @def RTTESTI_CHECK_RET
1194 * Check whether a boolean expression holds true, returns on false.
1195 *
1196 * If the expression is false, call RTTestIFailed giving the line number and
1197 * expression, then return @a rcRet.
1198 *
1199 * @param expr The expression to evaluate.
1200 * @param rcRet What to return on failure.
1201 */
1202#define RTTESTI_CHECK_RET(expr, rcRet) \
1203 do { if (!(expr)) { \
1204 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1205 return (rcRet); \
1206 } \
1207 } while (0)
1208/** @def RTTESTI_CHECK_RETV
1209 * Check whether a boolean expression holds true, returns void on false.
1210 *
1211 * If the expression is false, call RTTestIFailed giving the line number and
1212 * expression, then return void.
1213 *
1214 * @param expr The expression to evaluate.
1215 */
1216#define RTTESTI_CHECK_RETV(expr) \
1217 do { if (!(expr)) { \
1218 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1219 return; \
1220 } \
1221 } while (0)
1222/** @def RTTESTI_CHECK_BREAK
1223 * Check whether a boolean expression holds true, returns void on false.
1224 *
1225 * If the expression is false, call RTTestIFailed giving the line number and
1226 * expression, then break.
1227 *
1228 * @param expr The expression to evaluate.
1229 */
1230#define RTTESTI_CHECK_BREAK(expr) \
1231 if (!(expr)) { \
1232 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1233 break; \
1234 } else do {} while (0)
1235
1236
1237/** @def RTTESTI_CHECK_MSG
1238 * Check whether a boolean expression holds true.
1239 *
1240 * If the expression is false, call RTTestIFailed giving the line number and
1241 * expression.
1242 *
1243 * @param expr The expression to evaluate.
1244 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1245 * parenthesis.
1246 */
1247#define RTTESTI_CHECK_MSG(expr, DetailsArgs) \
1248 do { if (!(expr)) { \
1249 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1250 RTTestIFailureDetails DetailsArgs; \
1251 } \
1252 } while (0)
1253/** @def RTTESTI_CHECK_MSG_BREAK
1254 * Check whether a boolean expression holds true, returns on false.
1255 *
1256 * If the expression is false, call RTTestIFailed giving the line number and
1257 * expression.
1258 *
1259 * @param expr The expression to evaluate.
1260 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1261 * parenthesis.
1262 */
1263#define RTTESTI_CHECK_MSG_BREAK(expr, DetailsArgs) \
1264 if (!(expr)) { \
1265 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1266 RTTestIFailureDetails DetailsArgs; \
1267 break; \
1268 } else do {} while (0)
1269/** @def RTTESTI_CHECK_MSG_RET
1270 * Check whether a boolean expression holds true, returns on false.
1271 *
1272 * If the expression is false, call RTTestIFailed giving the line number and
1273 * expression.
1274 *
1275 * @param expr The expression to evaluate.
1276 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1277 * parenthesis.
1278 * @param rcRet What to return on failure.
1279 */
1280#define RTTESTI_CHECK_MSG_RET(expr, DetailsArgs, rcRet) \
1281 do { if (!(expr)) { \
1282 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1283 RTTestIFailureDetails DetailsArgs; \
1284 return (rcRet); \
1285 } \
1286 } while (0)
1287/** @def RTTESTI_CHECK_MSG_RETV
1288 * Check whether a boolean expression holds true, returns void on false.
1289 *
1290 * If the expression is false, call RTTestIFailed giving the line number and
1291 * expression.
1292 *
1293 * @param expr The expression to evaluate.
1294 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1295 * parenthesis.
1296 */
1297#define RTTESTI_CHECK_MSG_RETV(expr, DetailsArgs) \
1298 do { if (!(expr)) { \
1299 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1300 RTTestIFailureDetails DetailsArgs; \
1301 return; \
1302 } \
1303 } while (0)
1304
1305/** @def RTTESTI_CHECK_RC
1306 * Check whether an expression returns a specific IPRT style status code.
1307 *
1308 * If a different status code is return, call RTTestIFailed giving the line
1309 * number, expression, actual and expected status codes.
1310 *
1311 * @param rcExpr The expression resulting in an IPRT status code.
1312 * @param rcExpect The expected return code. This may be referenced
1313 * more than once by the macro.
1314 */
1315#define RTTESTI_CHECK_RC(rcExpr, rcExpect) \
1316 do { \
1317 int rcCheck = (rcExpr); \
1318 if (rcCheck != (rcExpect)) { \
1319 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1320 } \
1321 } while (0)
1322/** @def RTTESTI_CHECK_RC_RET
1323 * Check whether an expression returns a specific IPRT style status code.
1324 *
1325 * If a different status code is return, call RTTestIFailed giving the line
1326 * number, expression, actual and expected status codes, then return.
1327 *
1328 * @param rcExpr The expression resulting in an IPRT status code.
1329 * This will be assigned to a local rcCheck variable
1330 * that can be used as return value.
1331 * @param rcExpect The expected return code. This may be referenced
1332 * more than once by the macro.
1333 * @param rcRet The return code.
1334 */
1335#define RTTESTI_CHECK_RC_RET(rcExpr, rcExpect, rcRet) \
1336 do { \
1337 int rcCheck = (rcExpr); \
1338 if (rcCheck != (rcExpect)) { \
1339 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1340 return (rcRet); \
1341 } \
1342 } while (0)
1343/** @def RTTESTI_CHECK_RC_RETV
1344 * Check whether an expression returns a specific IPRT style status code.
1345 *
1346 * If a different status code is return, call RTTestIFailed giving the line
1347 * number, expression, actual and expected status codes, then return.
1348 *
1349 * @param rcExpr The expression resulting in an IPRT status code.
1350 * @param rcExpect The expected return code. This may be referenced
1351 * more than once by the macro.
1352 */
1353#define RTTESTI_CHECK_RC_RETV(rcExpr, rcExpect) \
1354 do { \
1355 int rcCheck = (rcExpr); \
1356 if (rcCheck != (rcExpect)) { \
1357 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1358 return; \
1359 } \
1360 } while (0)
1361/** @def RTTESTI_CHECK_RC_BREAK
1362 * Check whether an expression returns a specific IPRT style status code.
1363 *
1364 * If a different status code is return, call RTTestIFailed giving the line
1365 * number, expression, actual and expected status codes, then break.
1366 *
1367 * @param rcExpr The expression resulting in an IPRT status code.
1368 * @param rcExpect The expected return code. This may be referenced
1369 * more than once by the macro.
1370 */
1371#define RTTESTI_CHECK_RC_BREAK(rcExpr, rcExpect) \
1372 if (1) { \
1373 int rcCheck = (rcExpr); \
1374 if (rcCheck != (rcExpect)) { \
1375 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1376 break; \
1377 } \
1378 } else do {} while (0)
1379/** @def RTTESTI_CHECK_RC_OK
1380 * Check whether a IPRT style status code indicates success.
1381 *
1382 * If the status indicates failure, call RTTestIFailed giving the line number,
1383 * expression and status code.
1384 *
1385 * @param rcExpr The expression resulting in an IPRT status code.
1386 */
1387#define RTTESTI_CHECK_RC_OK(rcExpr) \
1388 do { \
1389 int rcCheck = (rcExpr); \
1390 if (RT_FAILURE(rcCheck)) { \
1391 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1392 } \
1393 } while (0)
1394/** @def RTTESTI_CHECK_RC_OK_BREAK
1395 * Check whether a IPRT style status code indicates success.
1396 *
1397 * If a different status code is return, call RTTestIFailed giving the line
1398 * number, expression, actual and expected status codes, then break.
1399 *
1400 * @param rcExpr The expression resulting in an IPRT status code.
1401 */
1402#define RTTESTI_CHECK_RC_OK_BREAK(rcExpr) \
1403 do { \
1404 int rcCheck = (rcExpr); \
1405 if (RT_FAILURE(rcCheck)) { \
1406 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1407 break; \
1408 } \
1409 } while (0)
1410/** @def RTTESTI_CHECK_RC_OK_RET
1411 * Check whether a IPRT style status code indicates success.
1412 *
1413 * If the status indicates failure, call RTTestIFailed giving the line number,
1414 * expression and status code, then return with the specified value.
1415 *
1416 * @param rcExpr The expression resulting in an IPRT status code.
1417 * This will be assigned to a local rcCheck variable
1418 * that can be used as return value.
1419 * @param rcRet The return code.
1420 */
1421#define RTTESTI_CHECK_RC_OK_RET(rcExpr, rcRet) \
1422 do { \
1423 int rcCheck = (rcExpr); \
1424 if (RT_FAILURE(rcCheck)) { \
1425 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1426 return (rcRet); \
1427 } \
1428 } while (0)
1429/** @def RTTESTI_CHECK_RC_OK_RETV
1430 * Check whether a IPRT style status code indicates success.
1431 *
1432 * If the status indicates failure, call RTTestIFailed giving the line number,
1433 * expression and status code, then return.
1434 *
1435 * @param rcExpr The expression resulting in an IPRT status code.
1436 */
1437#define RTTESTI_CHECK_RC_OK_RETV(rcExpr) \
1438 do { \
1439 int rcCheck = (rcExpr); \
1440 if (RT_FAILURE(rcCheck)) { \
1441 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1442 return; \
1443 } \
1444 } while (0)
1445
1446/** @} */
1447
1448
1449/** @} */
1450
1451RT_C_DECLS_END
1452
1453#endif /* !IPRT_INCLUDED_test_h */
1454
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette