VirtualBox

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

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

iprt/test.h: Added another place to update when adding new test units.

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