VirtualBox

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

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

IPRT,ValKit,VMMDevTesting.h: Added picoseconds to the test units. bugref:9898

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