VirtualBox

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

Last change on this file since 96574 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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