VirtualBox

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

Last change on this file since 92258 was 92258, checked in by vboxsync, 3 years ago

IPRT,VMMDev,ValKit: Some new test units. bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.6 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.
473 * - Add it to rtTestUnitName in r3/test.cpp.
474 * - Add it as VMMDEV_TESTING_UNIT_ in include/VBox/VMMDevTesting.h.
475 * - Add it to g_aszBs2TestUnitNames in
476 * ValidationKit/bootsectors/bootsector2-common-routines.mac.
477 * - Add it to g_aszBs3TestUnitNames in bs3kit/bs3-cmn-TestData.c.
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 RTTESTUNIT_TICKS, /**< CPU ticks. */
516 RTTESTUNIT_TICKS_PER_CALL, /**< CPU ticks per call. */
517 RTTESTUNIT_TICKS_PER_OCCURENCE, /**< CPU ticks per occurence. */
518 RTTESTUNIT_PAGES, /**< Page count. */
519 RTTESTUNIT_PAGES_PER_SEC, /**< Pages per second. */
520 RTTESTUNIT_TICKS_PER_PAGE, /**< CPU ticks per page. */
521 RTTESTUNIT_NS_PER_PAGE, /**< Nanoseconds per page. */
522
523 /** The end of valid units. */
524 RTTESTUNIT_END
525} RTTESTUNIT;
526AssertCompile(RTTESTUNIT_INSTRS == 0x19);
527AssertCompile(RTTESTUNIT_NONE == 0x1b);
528AssertCompile(RTTESTUNIT_NS_PER_PAGE == 0x26);
529
530/**
531 * Report a named test result value.
532 *
533 * This is typically used for benchmarking but can be used for other purposes
534 * like reporting limits of some implementation. The value gets associated with
535 * the current sub test, the name must be unique within the sub test.
536 *
537 * @returns IPRT status code.
538 *
539 * @param hTest The test handle. If NIL_RTTEST we'll use the one
540 * associated with the calling thread.
541 * @param pszName The value name.
542 * @param u64Value The value.
543 * @param enmUnit The value unit.
544 */
545RTR3DECL(int) RTTestValue(RTTEST hTest, const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
546
547/**
548 * Same as RTTestValue, except that the name is now a format string.
549 *
550 * @returns IPRT status code.
551 *
552 * @param hTest The test handle. If NIL_RTTEST we'll use the one
553 * associated with the calling thread.
554 * @param u64Value The value.
555 * @param enmUnit The value unit.
556 * @param pszNameFmt The value name format string.
557 * @param ... String arguments.
558 */
559RTR3DECL(int) RTTestValueF(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit,
560 const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(4, 5);
561
562/**
563 * Same as RTTestValue, except that the name is now a format string.
564 *
565 * @returns IPRT status code.
566 *
567 * @param hTest The test handle. If NIL_RTTEST we'll use the one
568 * associated with the calling thread.
569 * @param u64Value The value.
570 * @param enmUnit The value unit.
571 * @param pszNameFmt The value name format string.
572 * @param va String arguments.
573 */
574RTR3DECL(int) RTTestValueV(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit,
575 const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
576
577/**
578 * Increments the error counter.
579 *
580 * @returns IPRT status code.
581 * @param hTest The test handle. If NIL_RTTEST we'll use the one
582 * associated with the calling thread.
583 */
584RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
585
586/**
587 * Get the current error count.
588 *
589 * @returns The error counter, UINT32_MAX if no valid test handle.
590 * @param hTest The test handle. If NIL_RTTEST we'll use the one
591 * associated with the calling thread.
592 */
593RTR3DECL(uint32_t) RTTestErrorCount(RTTEST hTest);
594
595/**
596 * Get the error count of the current sub test.
597 *
598 * @returns The error counter, UINT32_MAX if no valid test handle.
599 * @param hTest The test handle. If NIL_RTTEST we'll use the one
600 * associated with the calling thread.
601 */
602RTR3DECL(uint32_t) RTTestSubErrorCount(RTTEST hTest);
603
604/**
605 * Increments the error counter and prints a failure message.
606 *
607 * @returns IPRT status code.
608 * @param hTest The test handle. If NIL_RTTEST we'll use the one
609 * associated with the calling thread.
610 * @param pszFormat The message. No trailing newline.
611 * @param va The arguments.
612 */
613RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
614
615/**
616 * Increments the error counter and prints a failure message.
617 *
618 * @returns IPRT status code.
619 * @param hTest The test handle. If NIL_RTTEST we'll use the one
620 * associated with the calling thread.
621 * @param pszFormat The message. No trailing newline.
622 * @param ... The arguments.
623 */
624RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
625
626/**
627 * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
628 *
629 * @returns Number of chars printed.
630 * @param hTest The test handle. If NIL_RTTEST we'll use the one
631 * associated with the calling thread.
632 * @param pszFormat The message.
633 * @param va Arguments.
634 */
635RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
636
637/**
638 * Same as RTTestPrintf with RTTESTLVL_FAILURE.
639 *
640 * @returns Number of chars printed.
641 * @param hTest The test handle. If NIL_RTTEST we'll use the one
642 * associated with the calling thread.
643 * @param pszFormat The message.
644 * @param ... Arguments.
645 */
646RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
647
648/**
649 * Sets error context info to be printed with the first failure.
650 *
651 * @returns IPRT status code.
652 * @param hTest The test handle. If NIL_RTTEST we'll use the one
653 * associated with the calling thread.
654 * @param pszFormat The message, no trailing newline. NULL to clear the
655 * context message.
656 * @param va The arguments.
657 */
658RTR3DECL(int) RTTestErrContextV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
659
660/**
661 * Sets error context info to be printed with the first failure.
662 *
663 * @returns IPRT status code.
664 * @param hTest The test handle. If NIL_RTTEST we'll use the one
665 * associated with the calling thread.
666 * @param pszFormat The message, no trailing newline. NULL to clear the
667 * context message.
668 * @param ... The arguments.
669 */
670RTR3DECL(int) RTTestErrContext(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
671
672/**
673 * Disables and shuts up assertions.
674 *
675 * Max 8 nestings.
676 *
677 * @returns IPRT status code.
678 * @param hTest The test handle. If NIL_RTTEST we'll use the one
679 * associated with the calling thread.
680 * @sa RTAssertSetMayPanic, RTAssertSetQuiet.
681 */
682RTR3DECL(int) RTTestDisableAssertions(RTTEST hTest);
683
684/**
685 * Restores the previous call to RTTestDisableAssertions.
686 *
687 * @returns IPRT status code.
688 * @param hTest The test handle. If NIL_RTTEST we'll use the one
689 * associated with the calling thread.
690 */
691RTR3DECL(int) RTTestRestoreAssertions(RTTEST hTest);
692
693
694/** @def RTTEST_CHECK
695 * Check whether a boolean expression holds true.
696 *
697 * If the expression is false, call RTTestFailed giving the line number and expression.
698 *
699 * @param hTest The test handle.
700 * @param expr The expression to evaluate.
701 */
702#define RTTEST_CHECK(hTest, expr) \
703 do { if (!(expr)) { \
704 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
705 } \
706 } while (0)
707/** @def RTTEST_CHECK_RET
708 * Check whether a boolean expression holds true, returns on false.
709 *
710 * If the expression is false, call RTTestFailed giving the line number and
711 * expression, then return @a rcRet.
712 *
713 * @param hTest The test handle.
714 * @param expr The expression to evaluate.
715 * @param rcRet What to return on failure.
716 */
717#define RTTEST_CHECK_RET(hTest, expr, rcRet) \
718 do { if (!(expr)) { \
719 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
720 return (rcRet); \
721 } \
722 } while (0)
723/** @def RTTEST_CHECK_RETV
724 * Check whether a boolean expression holds true, returns void on false.
725 *
726 * If the expression is false, call RTTestFailed giving the line number and
727 * expression, then return void.
728 *
729 * @param hTest The test handle.
730 * @param expr The expression to evaluate.
731 */
732#define RTTEST_CHECK_RETV(hTest, expr) \
733 do { if (!(expr)) { \
734 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
735 return; \
736 } \
737 } while (0)
738/** @def RTTEST_CHECK_BREAK
739 * Check whether a boolean expression holds true.
740 *
741 * If the expression is false, call RTTestFailed giving the line number and
742 * expression, then break.
743 *
744 * @param hTest The test handle.
745 * @param expr The expression to evaluate.
746 */
747#define RTTEST_CHECK_BREAK(hTest, expr) \
748 if (!(expr)) { \
749 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
750 break; \
751 } else do {} while (0)
752
753
754/** @def RTTEST_CHECK_MSG
755 * Check whether a boolean expression holds true.
756 *
757 * If the expression is false, call RTTestFailed giving the line number and expression.
758 *
759 * @param hTest The test handle.
760 * @param expr The expression to evaluate.
761 * @param DetailsArgs Argument list for RTTestFailureDetails, including
762 * parenthesis.
763 */
764#define RTTEST_CHECK_MSG(hTest, expr, DetailsArgs) \
765 do { if (!(expr)) { \
766 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
767 RTTestFailureDetails DetailsArgs; \
768 } \
769 } while (0)
770/** @def RTTEST_CHECK_MSG_RET
771 * Check whether a boolean expression holds true, returns on false.
772 *
773 * If the expression is false, call RTTestFailed giving the line number and expression.
774 *
775 * @param hTest The test handle.
776 * @param expr The expression to evaluate.
777 * @param DetailsArgs Argument list for RTTestFailureDetails, including
778 * parenthesis.
779 * @param rcRet What to return on failure.
780 */
781#define RTTEST_CHECK_MSG_RET(hTest, expr, DetailsArgs, rcRet) \
782 do { if (!(expr)) { \
783 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
784 RTTestFailureDetails DetailsArgs; \
785 return (rcRet); \
786 } \
787 } while (0)
788/** @def RTTEST_CHECK_MSG_RETV
789 * Check whether a boolean expression holds true, returns void on false.
790 *
791 * If the expression is false, call RTTestFailed giving the line number and expression.
792 *
793 * @param hTest The test handle.
794 * @param expr The expression to evaluate.
795 * @param DetailsArgs Argument list for RTTestFailureDetails, including
796 * parenthesis.
797 */
798#define RTTEST_CHECK_MSG_RETV(hTest, expr, DetailsArgs) \
799 do { if (!(expr)) { \
800 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
801 RTTestFailureDetails DetailsArgs; \
802 return; \
803 } \
804 } while (0)
805
806
807/** @def RTTEST_CHECK_RC
808 * Check whether an expression returns a specific IPRT style status code.
809 *
810 * If a different status code is return, call RTTestFailed giving the line
811 * number, expression, actual and expected status codes.
812 *
813 * @param hTest The test handle.
814 * @param rcExpr The expression resulting in an IPRT status code.
815 * @param rcExpect The expected return code. This may be referenced
816 * more than once by the macro.
817 */
818#define RTTEST_CHECK_RC(hTest, rcExpr, rcExpect) \
819 do { \
820 int rcCheck = (rcExpr); \
821 if (rcCheck != (rcExpect)) { \
822 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
823 } \
824 } while (0)
825/** @def RTTEST_CHECK_RC_RET
826 * Check whether an expression returns a specific IPRT style status code.
827 *
828 * If a different status code is return, call RTTestFailed giving the line
829 * number, expression, actual and expected status codes, then return.
830 *
831 * @param hTest The test handle.
832 * @param rcExpr The expression resulting in an IPRT status code.
833 * This will be assigned to a local rcCheck variable
834 * that can be used as return value.
835 * @param rcExpect The expected return code. This may be referenced
836 * more than once by the macro.
837 * @param rcRet The return code.
838 */
839#define RTTEST_CHECK_RC_RET(hTest, rcExpr, rcExpect, rcRet) \
840 do { \
841 int rcCheck = (rcExpr); \
842 if (rcCheck != (rcExpect)) { \
843 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
844 return (rcRet); \
845 } \
846 } while (0)
847/** @def RTTEST_CHECK_RC_RETV
848 * Check whether an expression returns a specific IPRT style status code.
849 *
850 * If a different status code is return, call RTTestFailed giving the line
851 * number, expression, actual and expected status codes, then return.
852 *
853 * @param hTest The test handle.
854 * @param rcExpr The expression resulting in an IPRT status code.
855 * @param rcExpect The expected return code. This may be referenced
856 * more than once by the macro.
857 */
858#define RTTEST_CHECK_RC_RETV(hTest, rcExpr, rcExpect) \
859 do { \
860 int rcCheck = (rcExpr); \
861 if (rcCheck != (rcExpect)) { \
862 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
863 return; \
864 } \
865 } while (0)
866/** @def RTTEST_CHECK_RC_BREAK
867 * Check whether an expression returns a specific IPRT style status code.
868 *
869 * If a different status code is return, call RTTestFailed giving the line
870 * number, expression, actual and expected status codes, then break.
871 *
872 * @param hTest The test handle.
873 * @param rcExpr The expression resulting in an IPRT status code.
874 * @param rcExpect The expected return code. This may be referenced
875 * more than once by the macro.
876 */
877#define RTTEST_CHECK_RC_BREAK(hTest, rcExpr, rcExpect) \
878 if (1) { \
879 int rcCheck = (rcExpr); \
880 if (rcCheck != (rcExpect)) { \
881 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
882 break; \
883 } \
884 } else do {} while (0)
885
886
887/** @def RTTEST_CHECK_RC_OK
888 * Check whether a IPRT style status code indicates success.
889 *
890 * If the status indicates failure, call RTTestFailed giving the line number,
891 * expression and status code.
892 *
893 * @param hTest The test handle.
894 * @param rcExpr The expression resulting in an IPRT status code.
895 */
896#define RTTEST_CHECK_RC_OK(hTest, rcExpr) \
897 do { \
898 int rcCheck = (rcExpr); \
899 if (RT_FAILURE(rcCheck)) { \
900 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
901 } \
902 } while (0)
903/** @def RTTEST_CHECK_RC_OK_RET
904 * Check whether a IPRT style status code indicates success.
905 *
906 * If the status indicates failure, call RTTestFailed giving the line number,
907 * expression and status code, then return with the specified value.
908 *
909 * @param hTest The test handle.
910 * @param rcExpr The expression resulting in an IPRT status code.
911 * This will be assigned to a local rcCheck variable
912 * that can be used as return value.
913 * @param rcRet The return code.
914 */
915#define RTTEST_CHECK_RC_OK_RET(hTest, rcExpr, rcRet) \
916 do { \
917 int rcCheck = (rcExpr); \
918 if (RT_FAILURE(rcCheck)) { \
919 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
920 return (rcRet); \
921 } \
922 } while (0)
923/** @def RTTEST_CHECK_RC_OK_RETV
924 * Check whether a IPRT style status code indicates success.
925 *
926 * If the status indicates failure, call RTTestFailed giving the line number,
927 * expression and status code, then return.
928 *
929 * @param hTest The test handle.
930 * @param rcExpr The expression resulting in an IPRT status code.
931 */
932#define RTTEST_CHECK_RC_OK_RETV(hTest, rcExpr) \
933 do { \
934 int rcCheck = (rcExpr); \
935 if (RT_FAILURE(rcCheck)) { \
936 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
937 return; \
938 } \
939 } while (0)
940
941
942
943
944/** @name Implicit Test Handle API Variation
945 * The test handle is retrieved from the test TLS entry of the calling thread.
946 * @{
947 */
948
949/**
950 * Test vprintf, makes sure lines are prefixed and so forth.
951 *
952 * @returns Number of chars printed.
953 * @param enmLevel Message importance level.
954 * @param pszFormat The message.
955 * @param va Arguments.
956 */
957RTR3DECL(int) RTTestIPrintfV(RTTESTLVL enmLevel, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
958
959/**
960 * Test printf, makes sure lines are prefixed and so forth.
961 *
962 * @returns Number of chars printed.
963 * @param enmLevel Message importance level.
964 * @param pszFormat The message.
965 * @param ... Arguments.
966 */
967RTR3DECL(int) RTTestIPrintf(RTTESTLVL enmLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
968
969/**
970 * Starts a sub-test.
971 *
972 * This will perform an implicit RTTestSubDone() call if that has not been done
973 * since the last RTTestSub call.
974 *
975 * @returns Number of chars printed.
976 * @param pszSubTest The sub-test name.
977 */
978RTR3DECL(int) RTTestISub(const char *pszSubTest);
979
980/**
981 * Format string version of RTTestSub.
982 *
983 * See RTTestSub for details.
984 *
985 * @returns Number of chars printed.
986 * @param pszSubTestFmt The sub-test name format string.
987 * @param ... Arguments.
988 */
989RTR3DECL(int) RTTestISubF(const char *pszSubTestFmt, ...) RT_IPRT_FORMAT_ATTR(1, 2);
990
991/**
992 * Format string version of RTTestSub.
993 *
994 * See RTTestSub for details.
995 *
996 * @returns Number of chars printed.
997 * @param pszSubTestFmt The sub-test name format string.
998 * @param va Arguments.
999 */
1000RTR3DECL(int) RTTestISubV(const char *pszSubTestFmt, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1001
1002/**
1003 * Completes a sub-test.
1004 *
1005 * @returns Number of chars printed.
1006 */
1007RTR3DECL(int) RTTestISubDone(void);
1008
1009/**
1010 * Prints an extended PASSED message, optional.
1011 *
1012 * This does not conclude the sub-test, it could be used to report the passing
1013 * of a sub-sub-to-the-power-of-N-test.
1014 *
1015 * @returns IPRT status code.
1016 * @param pszFormat The message. No trailing newline.
1017 * @param va The arguments.
1018 */
1019RTR3DECL(int) RTTestIPassedV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1020
1021/**
1022 * Prints an extended PASSED message, optional.
1023 *
1024 * This does not conclude the sub-test, it could be used to report the passing
1025 * of a sub-sub-to-the-power-of-N-test.
1026 *
1027 * @returns IPRT status code.
1028 * @param pszFormat The message. No trailing newline.
1029 * @param ... The arguments.
1030 */
1031RTR3DECL(int) RTTestIPassed(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1032
1033/**
1034 * Report a named test result value.
1035 *
1036 * This is typically used for benchmarking but can be used for other purposes
1037 * like reporting limits of some implementation. The value gets associated with
1038 * the current sub test, the name must be unique within the sub test.
1039 *
1040 * @returns IPRT status code.
1041 *
1042 * @param pszName The value name.
1043 * @param u64Value The value.
1044 * @param enmUnit The value unit.
1045 */
1046RTR3DECL(int) RTTestIValue(const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
1047
1048/**
1049 * Same as RTTestValue, except that the name is now a format string.
1050 *
1051 * @returns IPRT status code.
1052 *
1053 * @param u64Value The value.
1054 * @param enmUnit The value unit.
1055 * @param pszNameFmt The value name format string.
1056 * @param ... String arguments.
1057 */
1058RTR3DECL(int) RTTestIValueF(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
1059
1060/**
1061 * Same as RTTestValue, except that the name is now a format string.
1062 *
1063 * @returns IPRT status code.
1064 *
1065 * @param u64Value The value.
1066 * @param enmUnit The value unit.
1067 * @param pszNameFmt The value name format string.
1068 * @param va String arguments.
1069 */
1070RTR3DECL(int) RTTestIValueV(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
1071
1072/**
1073 * Increments the error counter.
1074 *
1075 * @returns IPRT status code.
1076 */
1077RTR3DECL(int) RTTestIErrorInc(void);
1078
1079/**
1080 * Get the current error count.
1081 *
1082 * @returns The error counter, UINT32_MAX if no valid test handle.
1083 */
1084RTR3DECL(uint32_t) RTTestIErrorCount(void);
1085
1086/**
1087 * Increments the error counter and prints a failure message.
1088 *
1089 * @returns IPRT status code.
1090 * @param pszFormat The message. No trailing newline.
1091 * @param va The arguments.
1092 */
1093RTR3DECL(int) RTTestIFailedV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1094
1095/**
1096 * Increments the error counter and prints a failure message.
1097 *
1098 * @returns IPRT status code.
1099 * @param pszFormat The message. No trailing newline.
1100 * @param ... The arguments.
1101 */
1102RTR3DECL(int) RTTestIFailed(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1103
1104/**
1105 * Increments the error counter, prints a failure message and returns the
1106 * specified status code.
1107 *
1108 * This is mainly a convenience method for saving vertical space in the source
1109 * code.
1110 *
1111 * @returns @a rcRet
1112 * @param rcRet The IPRT status code to return.
1113 * @param pszFormat The message. No trailing newline.
1114 * @param va The arguments.
1115 */
1116RTR3DECL(int) RTTestIFailedRcV(int rcRet, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
1117
1118/**
1119 * Increments the error counter, prints a failure message and returns the
1120 * specified status code.
1121 *
1122 * This is mainly a convenience method for saving vertical space in the source
1123 * code.
1124 *
1125 * @returns @a rcRet
1126 * @param rcRet The IPRT status code to return.
1127 * @param pszFormat The message. No trailing newline.
1128 * @param ... The arguments.
1129 */
1130RTR3DECL(int) RTTestIFailedRc(int rcRet, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
1131
1132/**
1133 * Same as RTTestIPrintfV with RTTESTLVL_FAILURE.
1134 *
1135 * @returns Number of chars printed.
1136 * @param pszFormat The message.
1137 * @param va Arguments.
1138 */
1139RTR3DECL(int) RTTestIFailureDetailsV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1140
1141/**
1142 * Same as RTTestIPrintf with RTTESTLVL_FAILURE.
1143 *
1144 * @returns Number of chars printed.
1145 * @param pszFormat The message.
1146 * @param ... Arguments.
1147 */
1148RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1149
1150/**
1151 * Sets error context info to be printed with the first failure.
1152 *
1153 * @returns IPRT status code.
1154 * @param pszFormat The message, no trailing newline. NULL to clear the
1155 * context message.
1156 * @param va The arguments.
1157 */
1158RTR3DECL(int) RTTestIErrContextV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
1159
1160/**
1161 * Sets error context info to be printed with the first failure.
1162 *
1163 * @returns IPRT status code.
1164 * @param pszFormat The message, no trailing newline. NULL to clear the
1165 * context message.
1166 * @param ... The arguments.
1167 */
1168RTR3DECL(int) RTTestIErrContext(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
1169
1170/**
1171 * Disables and shuts up assertions.
1172 *
1173 * Max 8 nestings.
1174 *
1175 * @returns IPRT status code.
1176 * @sa RTAssertSetMayPanic, RTAssertSetQuiet.
1177 */
1178RTR3DECL(int) RTTestIDisableAssertions(void);
1179
1180/**
1181 * Restores the previous call to RTTestDisableAssertions.
1182 *
1183 * @returns IPRT status code.
1184 */
1185RTR3DECL(int) RTTestIRestoreAssertions(void);
1186
1187
1188/** @def RTTESTI_CHECK
1189 * Check whether a boolean expression holds true.
1190 *
1191 * If the expression is false, call RTTestIFailed giving the line number and
1192 * expression.
1193 *
1194 * @param expr The expression to evaluate.
1195 */
1196#define RTTESTI_CHECK(expr) \
1197 do { if (!(expr)) { \
1198 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1199 } \
1200 } while (0)
1201/** @def RTTESTI_CHECK_RET
1202 * Check whether a boolean expression holds true, returns on false.
1203 *
1204 * If the expression is false, call RTTestIFailed giving the line number and
1205 * expression, then return @a rcRet.
1206 *
1207 * @param expr The expression to evaluate.
1208 * @param rcRet What to return on failure.
1209 */
1210#define RTTESTI_CHECK_RET(expr, rcRet) \
1211 do { if (!(expr)) { \
1212 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1213 return (rcRet); \
1214 } \
1215 } while (0)
1216/** @def RTTESTI_CHECK_RETV
1217 * Check whether a boolean expression holds true, returns void on false.
1218 *
1219 * If the expression is false, call RTTestIFailed giving the line number and
1220 * expression, then return void.
1221 *
1222 * @param expr The expression to evaluate.
1223 */
1224#define RTTESTI_CHECK_RETV(expr) \
1225 do { if (!(expr)) { \
1226 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1227 return; \
1228 } \
1229 } while (0)
1230/** @def RTTESTI_CHECK_BREAK
1231 * Check whether a boolean expression holds true, returns void on false.
1232 *
1233 * If the expression is false, call RTTestIFailed giving the line number and
1234 * expression, then break.
1235 *
1236 * @param expr The expression to evaluate.
1237 */
1238#define RTTESTI_CHECK_BREAK(expr) \
1239 if (!(expr)) { \
1240 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1241 break; \
1242 } else do {} while (0)
1243
1244
1245/** @def RTTESTI_CHECK_MSG
1246 * Check whether a boolean expression holds true.
1247 *
1248 * If the expression is false, call RTTestIFailed giving the line number and
1249 * expression.
1250 *
1251 * @param expr The expression to evaluate.
1252 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1253 * parenthesis.
1254 */
1255#define RTTESTI_CHECK_MSG(expr, DetailsArgs) \
1256 do { if (!(expr)) { \
1257 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1258 RTTestIFailureDetails DetailsArgs; \
1259 } \
1260 } while (0)
1261/** @def RTTESTI_CHECK_MSG_BREAK
1262 * Check whether a boolean expression holds true, returns on false.
1263 *
1264 * If the expression is false, call RTTestIFailed giving the line number and
1265 * expression.
1266 *
1267 * @param expr The expression to evaluate.
1268 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1269 * parenthesis.
1270 */
1271#define RTTESTI_CHECK_MSG_BREAK(expr, DetailsArgs) \
1272 if (!(expr)) { \
1273 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1274 RTTestIFailureDetails DetailsArgs; \
1275 break; \
1276 } else do {} while (0)
1277/** @def RTTESTI_CHECK_MSG_RET
1278 * Check whether a boolean expression holds true, returns on false.
1279 *
1280 * If the expression is false, call RTTestIFailed giving the line number and
1281 * expression.
1282 *
1283 * @param expr The expression to evaluate.
1284 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1285 * parenthesis.
1286 * @param rcRet What to return on failure.
1287 */
1288#define RTTESTI_CHECK_MSG_RET(expr, DetailsArgs, rcRet) \
1289 do { if (!(expr)) { \
1290 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1291 RTTestIFailureDetails DetailsArgs; \
1292 return (rcRet); \
1293 } \
1294 } while (0)
1295/** @def RTTESTI_CHECK_MSG_RETV
1296 * Check whether a boolean expression holds true, returns void on false.
1297 *
1298 * If the expression is false, call RTTestIFailed giving the line number and
1299 * expression.
1300 *
1301 * @param expr The expression to evaluate.
1302 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1303 * parenthesis.
1304 */
1305#define RTTESTI_CHECK_MSG_RETV(expr, DetailsArgs) \
1306 do { if (!(expr)) { \
1307 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1308 RTTestIFailureDetails DetailsArgs; \
1309 return; \
1310 } \
1311 } while (0)
1312
1313/** @def RTTESTI_CHECK_RC
1314 * Check whether an expression returns a specific IPRT style status code.
1315 *
1316 * If a different status code is return, call RTTestIFailed giving the line
1317 * number, expression, actual and expected status codes.
1318 *
1319 * @param rcExpr The expression resulting in an IPRT status code.
1320 * @param rcExpect The expected return code. This may be referenced
1321 * more than once by the macro.
1322 */
1323#define RTTESTI_CHECK_RC(rcExpr, rcExpect) \
1324 do { \
1325 int rcCheck = (rcExpr); \
1326 if (rcCheck != (rcExpect)) { \
1327 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1328 } \
1329 } while (0)
1330/** @def RTTESTI_CHECK_RC_RET
1331 * Check whether an expression returns a specific IPRT style status code.
1332 *
1333 * If a different status code is return, call RTTestIFailed giving the line
1334 * number, expression, actual and expected status codes, then return.
1335 *
1336 * @param rcExpr The expression resulting in an IPRT status code.
1337 * This will be assigned to a local rcCheck variable
1338 * that can be used as return value.
1339 * @param rcExpect The expected return code. This may be referenced
1340 * more than once by the macro.
1341 * @param rcRet The return code.
1342 */
1343#define RTTESTI_CHECK_RC_RET(rcExpr, rcExpect, rcRet) \
1344 do { \
1345 int rcCheck = (rcExpr); \
1346 if (rcCheck != (rcExpect)) { \
1347 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1348 return (rcRet); \
1349 } \
1350 } while (0)
1351/** @def RTTESTI_CHECK_RC_RETV
1352 * Check whether an expression returns a specific IPRT style status code.
1353 *
1354 * If a different status code is return, call RTTestIFailed giving the line
1355 * number, expression, actual and expected status codes, then return.
1356 *
1357 * @param rcExpr The expression resulting in an IPRT status code.
1358 * @param rcExpect The expected return code. This may be referenced
1359 * more than once by the macro.
1360 */
1361#define RTTESTI_CHECK_RC_RETV(rcExpr, rcExpect) \
1362 do { \
1363 int rcCheck = (rcExpr); \
1364 if (rcCheck != (rcExpect)) { \
1365 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1366 return; \
1367 } \
1368 } while (0)
1369/** @def RTTESTI_CHECK_RC_BREAK
1370 * Check whether an expression returns a specific IPRT style status code.
1371 *
1372 * If a different status code is return, call RTTestIFailed giving the line
1373 * number, expression, actual and expected status codes, then break.
1374 *
1375 * @param rcExpr The expression resulting in an IPRT status code.
1376 * @param rcExpect The expected return code. This may be referenced
1377 * more than once by the macro.
1378 */
1379#define RTTESTI_CHECK_RC_BREAK(rcExpr, rcExpect) \
1380 if (1) { \
1381 int rcCheck = (rcExpr); \
1382 if (rcCheck != (rcExpect)) { \
1383 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1384 break; \
1385 } \
1386 } else do {} while (0)
1387/** @def RTTESTI_CHECK_RC_OK
1388 * Check whether a IPRT style status code indicates success.
1389 *
1390 * If the status indicates failure, call RTTestIFailed giving the line number,
1391 * expression and status code.
1392 *
1393 * @param rcExpr The expression resulting in an IPRT status code.
1394 */
1395#define RTTESTI_CHECK_RC_OK(rcExpr) \
1396 do { \
1397 int rcCheck = (rcExpr); \
1398 if (RT_FAILURE(rcCheck)) { \
1399 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1400 } \
1401 } while (0)
1402/** @def RTTESTI_CHECK_RC_OK_BREAK
1403 * Check whether a IPRT style status code indicates success.
1404 *
1405 * If a different status code is return, call RTTestIFailed giving the line
1406 * number, expression, actual and expected status codes, then break.
1407 *
1408 * @param rcExpr The expression resulting in an IPRT status code.
1409 */
1410#define RTTESTI_CHECK_RC_OK_BREAK(rcExpr) \
1411 do { \
1412 int rcCheck = (rcExpr); \
1413 if (RT_FAILURE(rcCheck)) { \
1414 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1415 break; \
1416 } \
1417 } while (0)
1418/** @def RTTESTI_CHECK_RC_OK_RET
1419 * Check whether a IPRT style status code indicates success.
1420 *
1421 * If the status indicates failure, call RTTestIFailed giving the line number,
1422 * expression and status code, then return with the specified value.
1423 *
1424 * @param rcExpr The expression resulting in an IPRT status code.
1425 * This will be assigned to a local rcCheck variable
1426 * that can be used as return value.
1427 * @param rcRet The return code.
1428 */
1429#define RTTESTI_CHECK_RC_OK_RET(rcExpr, rcRet) \
1430 do { \
1431 int rcCheck = (rcExpr); \
1432 if (RT_FAILURE(rcCheck)) { \
1433 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1434 return (rcRet); \
1435 } \
1436 } while (0)
1437/** @def RTTESTI_CHECK_RC_OK_RETV
1438 * Check whether a IPRT style status code indicates success.
1439 *
1440 * If the status indicates failure, call RTTestIFailed giving the line number,
1441 * expression and status code, then return.
1442 *
1443 * @param rcExpr The expression resulting in an IPRT status code.
1444 */
1445#define RTTESTI_CHECK_RC_OK_RETV(rcExpr) \
1446 do { \
1447 int rcCheck = (rcExpr); \
1448 if (RT_FAILURE(rcCheck)) { \
1449 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1450 return; \
1451 } \
1452 } while (0)
1453
1454/** @} */
1455
1456
1457/** @} */
1458
1459RT_C_DECLS_END
1460
1461#endif /* !IPRT_INCLUDED_test_h */
1462
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