VirtualBox

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

Last change on this file since 29567 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.1 KB
Line 
1/** @file
2 * IPRT - Testcase Framework.
3 */
4
5/*
6 * Copyright (C) 2009 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_test_h
27#define ___iprt_test_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_rt_test RTTest - Testcase Framework.
36 * @ingroup grp_rt
37 * @{
38 */
39
40/** A test handle. */
41typedef struct RTTESTINT *RTTEST;
42/** A pointer to a test handle. */
43typedef RTTEST *PRTTEST;
44/** A const pointer to a test handle. */
45typedef RTTEST const *PCRTTEST;
46
47/** A NIL Test handle. */
48#define NIL_RTTEST ((RTTEST)0)
49
50/**
51 * Test message importance level.
52 */
53typedef enum RTTESTLVL
54{
55 /** Invalid 0. */
56 RTTESTLVL_INVALID = 0,
57 /** Message should always be printed. */
58 RTTESTLVL_ALWAYS,
59 /** Failure message. */
60 RTTESTLVL_FAILURE,
61 /** Sub-test banner. */
62 RTTESTLVL_SUB_TEST,
63 /** Info message. */
64 RTTESTLVL_INFO,
65 /** Debug message. */
66 RTTESTLVL_DEBUG,
67 /** The last (invalid). */
68 RTTESTLVL_END
69} RTTESTLVL;
70
71
72/**
73 * Creates a test instance.
74 *
75 * @returns IPRT status code.
76 * @param pszTest The test name.
77 * @param phTest Where to store the test instance handle.
78 */
79RTR3DECL(int) RTTestCreate(const char *pszTest, PRTTEST phTest);
80
81/**
82 * Initializes IPRT and creates a test instance.
83 *
84 * Typical usage is:
85 * @code
86 int main(int argc, char **argv)
87 {
88 RTTEST hTest;
89 int rc = RTTestInitAndCreate("tstSomething", &hTest);
90 if (rc)
91 return rc;
92 ...
93 }
94 @endcode
95 *
96 * @returns RTEXITCODE_SUCCESS on success. On failure an error message is
97 * printed and a suitable exit code is return.
98 *
99 * @param pszTest The test name.
100 * @param phTest Where to store the test instance handle.
101 */
102RTR3DECL(RTEXITCODE) RTTestInitAndCreate(const char *pszTest, PRTTEST phTest);
103
104/**
105 * Destroys a test instance previously created by RTTestCreate.
106 *
107 * @returns IPRT status code.
108 * @param hTest The test handle. NIL_RTTEST is ignored.
109 */
110RTR3DECL(int) RTTestDestroy(RTTEST hTest);
111
112/**
113 * Changes the default test instance for the calling thread.
114 *
115 * @returns IPRT status code.
116 *
117 * @param hNewDefaultTest The new default test. NIL_RTTEST is fine.
118 * @param phOldTest Where to store the old test handle. Optional.
119 */
120RTR3DECL(int) RTTestSetDefault(RTTEST hNewDefaultTest, PRTTEST phOldTest);
121
122/**
123 * Allocate a block of guarded memory.
124 *
125 * @returns IPRT status code.
126 * @param hTest The test handle. If NIL_RTTEST we'll use the one
127 * associated with the calling thread.
128 * @param cb The amount of memory to allocate.
129 * @param cbAlign The alignment of the returned block.
130 * @param fHead Head or tail optimized guard.
131 * @param ppvUser Where to return the pointer to the block.
132 */
133RTR3DECL(int) RTTestGuardedAlloc(RTTEST hTest, size_t cb, uint32_t cbAlign, bool fHead, void **ppvUser);
134
135/**
136 * Allocates a block of guarded memory where the guarded is immediately after
137 * the user memory.
138 *
139 * @returns Pointer to the allocated memory. NULL on failure.
140 * @param hTest The test handle. If NIL_RTTEST we'll use the one
141 * associated with the calling thread.
142 * @param cb The amount of memory to allocate.
143 */
144RTR3DECL(void *) RTTestGuardedAllocTail(RTTEST hTest, size_t cb);
145
146/**
147 * Allocates a block of guarded memory where the guarded is right in front of
148 * the user memory.
149 *
150 * @returns Pointer to the allocated memory. NULL on failure.
151 * @param hTest The test handle. If NIL_RTTEST we'll use the one
152 * associated with the calling thread.
153 * @param cb The amount of memory to allocate.
154 */
155RTR3DECL(void *) RTTestGuardedAllocHead(RTTEST hTest, size_t cb);
156
157/**
158 * Frees a block of guarded memory.
159 *
160 * @returns IPRT status code.
161 * @param hTest The test handle. If NIL_RTTEST we'll use the one
162 * associated with the calling thread.
163 * @param pv The memory. NULL is ignored.
164 */
165RTR3DECL(int) RTTestGuardedFree(RTTEST hTest, void *pv);
166
167/**
168 * Test vprintf making sure the output starts on a new line.
169 *
170 * @returns Number of chars printed.
171 * @param hTest The test handle. If NIL_RTTEST we'll use the one
172 * associated with the calling thread.
173 * @param enmLevel Message importance level.
174 * @param pszFormat The message.
175 * @param va Arguments.
176 */
177RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
178
179/**
180 * Test printf making sure the output starts on a new line.
181 *
182 * @returns Number of chars printed.
183 * @param hTest The test handle. If NIL_RTTEST we'll use the one
184 * associated with the calling thread.
185 * @param enmLevel Message importance level.
186 * @param pszFormat The message.
187 * @param ... Arguments.
188 */
189RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
190
191/**
192 * Test vprintf, makes sure lines are prefixed and so forth.
193 *
194 * @returns Number of chars printed.
195 * @param hTest The test handle. If NIL_RTTEST we'll use the one
196 * associated with the calling thread.
197 * @param enmLevel Message importance level.
198 * @param pszFormat The message.
199 * @param va Arguments.
200 */
201RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
202
203/**
204 * Test printf, makes sure lines are prefixed and so forth.
205 *
206 * @returns Number of chars printed.
207 * @param hTest The test handle. If NIL_RTTEST we'll use the one
208 * associated with the calling thread.
209 * @param enmLevel Message importance level.
210 * @param pszFormat The message.
211 * @param ... Arguments.
212 */
213RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
214
215/**
216 * Prints the test banner.
217 *
218 * @returns Number of chars printed.
219 * @param hTest The test handle. If NIL_RTTEST we'll use the one
220 * associated with the calling thread.
221 */
222RTR3DECL(int) RTTestBanner(RTTEST hTest);
223
224/**
225 * Summaries the test, destroys the test instance and return an exit code.
226 *
227 * @returns Test program exit code.
228 * @param hTest The test handle. If NIL_RTTEST we'll use the one
229 * associated with the calling thread.
230 */
231RTR3DECL(RTEXITCODE) RTTestSummaryAndDestroy(RTTEST hTest);
232
233/**
234 * Skips the test, destroys the test instance and return an exit code.
235 *
236 * @returns Test program exit code.
237 * @param hTest The test handle. If NIL_RTTEST we'll use the one
238 * associated with the calling thread.
239 * @param pszReasonFmt Text explaining why, optional (NULL).
240 * @param va Arguments for the reason format string.
241 */
242RTR3DECL(RTEXITCODE) RTTestSkipAndDestroyV(RTTEST hTest, const char *pszReasonFmt, va_list va);
243
244/**
245 * Skips the test, destroys the test instance and return an exit code.
246 *
247 * @returns Test program exit code.
248 * @param hTest The test handle. If NIL_RTTEST we'll use the one
249 * associated with the calling thread.
250 * @param pszReasonFmt Text explaining why, optional (NULL).
251 * @param ... Arguments for the reason format string.
252 */
253RTR3DECL(RTEXITCODE) RTTestSkipAndDestroy(RTTEST hTest, const char *pszReasonFmt, ...);
254
255/**
256 * Starts a sub-test.
257 *
258 * This will perform an implicit RTTestSubDone() call if that has not been done
259 * since the last RTTestSub call.
260 *
261 * @returns Number of chars printed.
262 * @param hTest The test handle. If NIL_RTTEST we'll use the one
263 * associated with the calling thread.
264 * @param pszSubTest The sub-test name.
265 */
266RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest);
267
268/**
269 * Format string version of RTTestSub.
270 *
271 * See RTTestSub for details.
272 *
273 * @returns Number of chars printed.
274 * @param hTest The test handle. If NIL_RTTEST we'll use the one
275 * associated with the calling thread.
276 * @param pszSubTestFmt The sub-test name format string.
277 * @param ... Arguments.
278 */
279RTR3DECL(int) RTTestSubF(RTTEST hTest, const char *pszSubTestFmt, ...);
280
281/**
282 * Format string version of RTTestSub.
283 *
284 * See RTTestSub for details.
285 *
286 * @returns Number of chars printed.
287 * @param hTest The test handle. If NIL_RTTEST we'll use the one
288 * associated with the calling thread.
289 * @param pszSubTestFmt The sub-test name format string.
290 * @param va Arguments.
291 */
292RTR3DECL(int) RTTestSubV(RTTEST hTest, const char *pszSubTestFmt, va_list va);
293
294/**
295 * Completes a sub-test.
296 *
297 * @returns Number of chars printed.
298 * @param hTest The test handle. If NIL_RTTEST we'll use the one
299 * associated with the calling thread.
300 */
301RTR3DECL(int) RTTestSubDone(RTTEST hTest);
302
303/**
304 * Prints an extended PASSED message, optional.
305 *
306 * This does not conclude the sub-test, it could be used to report the passing
307 * of a sub-sub-to-the-power-of-N-test.
308 *
309 * @returns IPRT status code.
310 * @param hTest The test handle. If NIL_RTTEST we'll use the one
311 * associated with the calling thread.
312 * @param pszFormat The message. No trailing newline.
313 * @param va The arguments.
314 */
315RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va);
316
317/**
318 * Prints an extended PASSED message, optional.
319 *
320 * This does not conclude the sub-test, it could be used to report the passing
321 * of a sub-sub-to-the-power-of-N-test.
322 *
323 * @returns IPRT status code.
324 * @param hTest The test handle. If NIL_RTTEST we'll use the one
325 * associated with the calling thread.
326 * @param pszFormat The message. No trailing newline.
327 * @param ... The arguments.
328 */
329RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...);
330
331/**
332 * Value units.
333 */
334typedef enum RTTESTUNIT
335{
336 /** The usual invalid value. */
337 RTTESTUNIT_INVALID = 0,
338 /** Percentage. */
339 RTTESTUNIT_PCT,
340 /** Bytes. */
341 RTTESTUNIT_BYTES,
342 /** Bytes per second. */
343 RTTESTUNIT_BYTES_PER_SEC,
344 /** Kilobytes. */
345 RTTESTUNIT_KILOBYTES,
346 /** Kilobytes per second. */
347 RTTESTUNIT_KILOBYTES_PER_SEC,
348 /** Megabytes. */
349 RTTESTUNIT_MEGABYTES,
350 /** Megabytes per second. */
351 RTTESTUNIT_MEGABYTES_PER_SEC,
352 /** Packets. */
353 RTTESTUNIT_PACKETS,
354 /** Packets per second. */
355 RTTESTUNIT_PACKETS_PER_SEC,
356 /** Frames. */
357 RTTESTUNIT_FRAMES,
358 /** Frames per second. */
359 RTTESTUNIT_FRAMES_PER_SEC,
360 /** Occurrences. */
361 RTTESTUNIT_OCCURRENCES,
362 /** Occurrences per second. */
363 RTTESTUNIT_OCCURRENCES_PER_SEC,
364 /** Calls. */
365 RTTESTUNIT_CALLS,
366 /** Calls per second. */
367 RTTESTUNIT_CALLS_PER_SEC,
368 /** Round trips. */
369 RTTESTUNIT_ROUND_TRIP,
370 /** Seconds. */
371 RTTESTUNIT_SECS,
372 /** Milliseconds. */
373 RTTESTUNIT_MS,
374 /** Nanoseconds. */
375 RTTESTUNIT_NS,
376 /** Nanoseconds per call. */
377 RTTESTUNIT_NS_PER_CALL,
378 /** Nanoseconds per frame. */
379 RTTESTUNIT_NS_PER_FRAME,
380 /** Nanoseconds per occurrence. */
381 RTTESTUNIT_NS_PER_OCCURRENCE,
382 /** Nanoseconds per frame. */
383 RTTESTUNIT_NS_PER_PACKET,
384 /** Nanoseconds per round trip. */
385 RTTESTUNIT_NS_PER_ROUND_TRIP,
386 /** The end of valid units. */
387 RTTESTUNIT_END
388} RTTESTUNIT;
389
390/**
391 * Report a named test result value.
392 *
393 * This is typically used for benchmarking but can be used for other purposes
394 * like reporting limits of some implementation. The value gets associated with
395 * the current sub test, the name must be unique within the sub test.
396 *
397 * @returns IPRT status code.
398 *
399 * @param hTest The test handle. If NIL_RTTEST we'll use the one
400 * associated with the calling thread.
401 * @param pszName The value name.
402 * @param u64Value The value.
403 * @param enmUnit The value unit.
404 */
405RTR3DECL(int) RTTestValue(RTTEST hTest, const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
406
407/**
408 * Same as RTTestValue, except that the name is now a format string.
409 *
410 * @returns IPRT status code.
411 *
412 * @param hTest The test handle. If NIL_RTTEST we'll use the one
413 * associated with the calling thread.
414 * @param u64Value The value.
415 * @param enmUnit The value unit.
416 * @param pszNameFmt The value name format string.
417 * @param ... String arguments.
418 */
419RTR3DECL(int) RTTestValueF(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...);
420
421/**
422 * Same as RTTestValue, except that the name is now a format string.
423 *
424 * @returns IPRT status code.
425 *
426 * @param hTest The test handle. If NIL_RTTEST we'll use the one
427 * associated with the calling thread.
428 * @param u64Value The value.
429 * @param enmUnit The value unit.
430 * @param pszNameFmt The value name format string.
431 * @param va_list String arguments.
432 */
433RTR3DECL(int) RTTestValueV(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va);
434
435/**
436 * Increments the error counter.
437 *
438 * @returns IPRT status code.
439 * @param hTest The test handle. If NIL_RTTEST we'll use the one
440 * associated with the calling thread.
441 */
442RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
443
444/**
445 * Get the current error count.
446 *
447 * @returns The error counter, UINT32_MAX if no valid test handle.
448 * @param hTest The test handle. If NIL_RTTEST we'll use the one
449 * associated with the calling thread.
450 */
451RTR3DECL(uint32_t) RTTestErrorCount(RTTEST hTest);
452
453/**
454 * Increments the error counter and prints a failure message.
455 *
456 * @returns IPRT status code.
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.
460 * @param va The arguments.
461 */
462RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va);
463
464/**
465 * Increments the error counter and prints a failure message.
466 *
467 * @returns IPRT status code.
468 * @param hTest The test handle. If NIL_RTTEST we'll use the one
469 * associated with the calling thread.
470 * @param pszFormat The message. No trailing newline.
471 * @param ... The arguments.
472 */
473RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...);
474
475/**
476 * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
477 *
478 * @returns Number of chars printed.
479 * @param hTest The test handle. If NIL_RTTEST we'll use the one
480 * associated with the calling thread.
481 * @param pszFormat The message.
482 * @param va Arguments.
483 */
484RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va);
485
486/**
487 * Same as RTTestPrintf with RTTESTLVL_FAILURE.
488 *
489 * @returns Number of chars printed.
490 * @param hTest The test handle. If NIL_RTTEST we'll use the one
491 * associated with the calling thread.
492 * @param pszFormat The message.
493 * @param ... Arguments.
494 */
495RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...);
496
497
498/** @def RTTEST_CHECK
499 * Check whether a boolean expression holds true.
500 *
501 * If the expression is false, call RTTestFailed giving the line number and expression.
502 *
503 * @param hTest The test handle.
504 * @param expr The expression to evaluate.
505 */
506#define RTTEST_CHECK(hTest, expr) \
507 do { if (!(expr)) { \
508 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
509 } \
510 } while (0)
511/** @def RTTEST_CHECK_RET
512 * Check whether a boolean expression holds true, returns on false.
513 *
514 * If the expression is false, call RTTestFailed giving the line number and expression.
515 *
516 * @param hTest The test handle.
517 * @param expr The expression to evaluate.
518 * @param rcRet What to return on failure.
519 */
520#define RTTEST_CHECK_RET(hTest, expr, rcRet) \
521 do { if (!(expr)) { \
522 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
523 return (rcRet); \
524 } \
525 } while (0)
526/** @def RTTEST_CHECK_RETV
527 * Check whether a boolean expression holds true, returns void on false.
528 *
529 * If the expression is false, call RTTestFailed giving the line number and expression.
530 *
531 * @param hTest The test handle.
532 * @param expr The expression to evaluate.
533 */
534#define RTTEST_CHECK_RETV(hTest, expr) \
535 do { if (!(expr)) { \
536 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
537 return; \
538 } \
539 } while (0)
540
541
542/** @def RTTEST_CHECK_MSG
543 * Check whether a boolean expression holds true.
544 *
545 * If the expression is false, call RTTestFailed giving the line number and expression.
546 *
547 * @param hTest The test handle.
548 * @param expr The expression to evaluate.
549 * @param DetailsArgs Argument list for RTTestFailureDetails, including
550 * parenthesis.
551 */
552#define RTTEST_CHECK_MSG(hTest, expr, DetailsArgs) \
553 do { if (!(expr)) { \
554 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
555 RTTestFailureDetails DetailsArgs; \
556 } \
557 } while (0)
558/** @def RTTEST_CHECK_MSG_RET
559 * Check whether a boolean expression holds true, returns on false.
560 *
561 * If the expression is false, call RTTestFailed giving the line number and expression.
562 *
563 * @param hTest The test handle.
564 * @param expr The expression to evaluate.
565 * @param DetailsArgs Argument list for RTTestFailureDetails, including
566 * parenthesis.
567 * @param rcRet What to return on failure.
568 */
569#define RTTEST_CHECK_MSG_RET(hTest, expr, DetailsArgs, rcRet) \
570 do { if (!(expr)) { \
571 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
572 RTTestFailureDetails DetailsArgs; \
573 return (rcRet); \
574 } \
575 } while (0)
576/** @def RTTEST_CHECK_MSG_RET
577 * Check whether a boolean expression holds true, returns void on false.
578 *
579 * If the expression is false, call RTTestFailed giving the line number and expression.
580 *
581 * @param hTest The test handle.
582 * @param expr The expression to evaluate.
583 * @param DetailsArgs Argument list for RTTestFailureDetails, including
584 * parenthesis.
585 */
586#define RTTEST_CHECK_MSG_RETV(hTest, expr, DetailsArgs) \
587 do { if (!(expr)) { \
588 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
589 RTTestFailureDetails DetailsArgs; \
590 return; \
591 } \
592 } while (0)
593
594
595/** @def RTTEST_CHECK_RC
596 * Check whether an expression returns a specific IPRT style status code.
597 *
598 * If a different status code is return, call RTTestFailed giving the line
599 * number, expression, actual and expected status codes.
600 *
601 * @param hTest The test handle.
602 * @param rcExpr The expression resulting in an IPRT status code.
603 * @param rcExpect The expected return code. This may be referenced
604 * more than once by the macro.
605 */
606#define RTTEST_CHECK_RC(hTest, rcExpr, rcExpect) \
607 do { \
608 int rcCheck = (rcExpr); \
609 if (rcCheck != (rcExpect)) { \
610 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
611 } \
612 } while (0)
613/** @def RTTEST_CHECK_RC_RET
614 * Check whether an expression returns a specific IPRT style status code.
615 *
616 * If a different status code is return, call RTTestFailed giving the line
617 * number, expression, actual and expected status codes, then return.
618 *
619 * @param hTest The test handle.
620 * @param rcExpr The expression resulting in an IPRT status code.
621 * This will be assigned to a local rcCheck variable
622 * that can be used as return value.
623 * @param rcExpect The expected return code. This may be referenced
624 * more than once by the macro.
625 * @param rcRet The return code.
626 */
627#define RTTEST_CHECK_RC_RET(hTest, rcExpr, rcExpect, rcRet) \
628 do { \
629 int rcCheck = (rcExpr); \
630 if (rcCheck != (rcExpect)) { \
631 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
632 return (rcRet); \
633 } \
634 } while (0)
635/** @def RTTEST_CHECK_RC_RETV
636 * Check whether an expression returns a specific IPRT style status code.
637 *
638 * If a different status code is return, call RTTestFailed giving the line
639 * number, expression, actual and expected status codes, then return.
640 *
641 * @param hTest The test handle.
642 * @param rcExpr The expression resulting in an IPRT status code.
643 * @param rcExpect The expected return code. This may be referenced
644 * more than once by the macro.
645 */
646#define RTTEST_CHECK_RC_RETV(hTest, rcExpr, rcExpect) \
647 do { \
648 int rcCheck = (rcExpr); \
649 if (rcCheck != (rcExpect)) { \
650 RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
651 return; \
652 } \
653 } while (0)
654
655
656/** @def RTTEST_CHECK_RC_OK
657 * Check whether a IPRT style status code indicates success.
658 *
659 * If the status indicates failure, call RTTestFailed giving the line number,
660 * expression and status code.
661 *
662 * @param hTest The test handle.
663 * @param rcExpr The expression resulting in an IPRT status code.
664 */
665#define RTTEST_CHECK_RC_OK(hTest, rcExpr) \
666 do { \
667 int rcCheck = (rcExpr); \
668 if (RT_FAILURE(rcCheck)) { \
669 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
670 } \
671 } while (0)
672/** @def RTTEST_CHECK_RC_OK_RET
673 * Check whether a IPRT style status code indicates success.
674 *
675 * If the status indicates failure, call RTTestFailed giving the line number,
676 * expression and status code, then return with the specified value.
677 *
678 * @param hTest The test handle.
679 * @param rcExpr The expression resulting in an IPRT status code.
680 * This will be assigned to a local rcCheck variable
681 * that can be used as return value.
682 * @param rcRet The return code.
683 */
684#define RTTEST_CHECK_RC_OK_RET(hTest, rcExpr, rcRet) \
685 do { \
686 int rcCheck = (rcExpr); \
687 if (RT_FAILURE(rcCheck)) { \
688 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
689 return (rcRet); \
690 } \
691 } while (0)
692/** @def RTTEST_CHECK_RC_OK_RETV
693 * Check whether a IPRT style status code indicates success.
694 *
695 * If the status indicates failure, call RTTestFailed giving the line number,
696 * expression and status code, then return.
697 *
698 * @param hTest The test handle.
699 * @param rcExpr The expression resulting in an IPRT status code.
700 */
701#define RTTEST_CHECK_RC_OK_RETV(hTest, rcExpr) \
702 do { \
703 int rcCheck = (rcExpr); \
704 if (RT_FAILURE(rcCheck)) { \
705 RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
706 return; \
707 } \
708 } while (0)
709
710
711
712
713/** @name Implicit Test Handle API Variation
714 * The test handle is retrieved from the test TLS entry of the calling thread.
715 * @{
716 */
717
718/**
719 * Test vprintf, makes sure lines are prefixed and so forth.
720 *
721 * @returns Number of chars printed.
722 * @param enmLevel Message importance level.
723 * @param pszFormat The message.
724 * @param va Arguments.
725 */
726RTR3DECL(int) RTTestIPrintfV(RTTESTLVL enmLevel, const char *pszFormat, va_list va);
727
728/**
729 * Test printf, makes sure lines are prefixed and so forth.
730 *
731 * @returns Number of chars printed.
732 * @param enmLevel Message importance level.
733 * @param pszFormat The message.
734 * @param ... Arguments.
735 */
736RTR3DECL(int) RTTestIPrintf(RTTESTLVL enmLevel, const char *pszFormat, ...);
737
738/**
739 * Starts a sub-test.
740 *
741 * This will perform an implicit RTTestSubDone() call if that has not been done
742 * since the last RTTestSub call.
743 *
744 * @returns Number of chars printed.
745 * @param pszSubTest The sub-test name.
746 */
747RTR3DECL(int) RTTestISub(const char *pszSubTest);
748
749/**
750 * Format string version of RTTestSub.
751 *
752 * See RTTestSub for details.
753 *
754 * @returns Number of chars printed.
755 * @param pszSubTestFmt The sub-test name format string.
756 * @param ... Arguments.
757 */
758RTR3DECL(int) RTTestISubF(const char *pszSubTestFmt, ...);
759
760/**
761 * Format string version of RTTestSub.
762 *
763 * See RTTestSub for details.
764 *
765 * @returns Number of chars printed.
766 * @param pszSubTestFmt The sub-test name format string.
767 * @param va Arguments.
768 */
769RTR3DECL(int) RTTestISubV(const char *pszSubTestFmt, va_list va);
770
771/**
772 * Completes a sub-test.
773 *
774 * @returns Number of chars printed.
775 */
776RTR3DECL(int) RTTestISubDone(void);
777
778/**
779 * Prints an extended PASSED message, optional.
780 *
781 * This does not conclude the sub-test, it could be used to report the passing
782 * of a sub-sub-to-the-power-of-N-test.
783 *
784 * @returns IPRT status code.
785 * @param pszFormat The message. No trailing newline.
786 * @param va The arguments.
787 */
788RTR3DECL(int) RTTestIPassedV(const char *pszFormat, va_list va);
789
790/**
791 * Prints an extended PASSED message, optional.
792 *
793 * This does not conclude the sub-test, it could be used to report the passing
794 * of a sub-sub-to-the-power-of-N-test.
795 *
796 * @returns IPRT status code.
797 * @param pszFormat The message. No trailing newline.
798 * @param ... The arguments.
799 */
800RTR3DECL(int) RTTestIPassed(const char *pszFormat, ...);
801
802/**
803 * Report a named test result value.
804 *
805 * This is typically used for benchmarking but can be used for other purposes
806 * like reporting limits of some implementation. The value gets associated with
807 * the current sub test, the name must be unique within the sub test.
808 *
809 * @returns IPRT status code.
810 *
811 * @param pszName The value name.
812 * @param u64Value The value.
813 * @param enmUnit The value unit.
814 */
815RTR3DECL(int) RTTestIValue(const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
816
817/**
818 * Same as RTTestValue, except that the name is now a format string.
819 *
820 * @returns IPRT status code.
821 *
822 * @param u64Value The value.
823 * @param enmUnit The value unit.
824 * @param pszNameFmt The value name format string.
825 * @param ... String arguments.
826 */
827RTR3DECL(int) RTTestIValueF(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...);
828
829/**
830 * Same as RTTestValue, except that the name is now a format string.
831 *
832 * @returns IPRT status code.
833 *
834 * @param u64Value The value.
835 * @param enmUnit The value unit.
836 * @param pszNameFmt The value name format string.
837 * @param va_list String arguments.
838 */
839RTR3DECL(int) RTTestIValueV(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va);
840
841/**
842 * Increments the error counter.
843 *
844 * @returns IPRT status code.
845 */
846RTR3DECL(int) RTTestIErrorInc(void);
847
848/**
849 * Get the current error count.
850 *
851 * @returns The error counter, UINT32_MAX if no valid test handle.
852 */
853RTR3DECL(uint32_t) RTTestIErrorCount(void);
854
855/**
856 * Increments the error counter and prints a failure message.
857 *
858 * @returns IPRT status code.
859 * @param pszFormat The message. No trailing newline.
860 * @param va The arguments.
861 */
862RTR3DECL(int) RTTestIFailedV(const char *pszFormat, va_list va);
863
864/**
865 * Increments the error counter and prints a failure message.
866 *
867 * @returns IPRT status code.
868 * @param pszFormat The message. No trailing newline.
869 * @param ... The arguments.
870 */
871RTR3DECL(int) RTTestIFailed(const char *pszFormat, ...);
872
873/**
874 * Increments the error counter, prints a failure message and returns the
875 * specified status code.
876 *
877 * This is mainly a convenience method for saving vertical space in the source
878 * code.
879 *
880 * @returns @a rcRet
881 * @param rcRet The IPRT status code to return.
882 * @param pszFormat The message. No trailing newline.
883 * @param va The arguments.
884 */
885RTR3DECL(int) RTTestIFailedRcV(int rcRet, const char *pszFormat, va_list va);
886
887/**
888 * Increments the error counter, prints a failure message and returns the
889 * specified status code.
890 *
891 * This is mainly a convenience method for saving vertical space in the source
892 * code.
893 *
894 * @returns @a rcRet
895 * @param rcRet The IPRT status code to return.
896 * @param pszFormat The message. No trailing newline.
897 * @param ... The arguments.
898 */
899RTR3DECL(int) RTTestIFailedRc(int rcRet, const char *pszFormat, ...);
900
901/**
902 * Same as RTTestIPrintfV with RTTESTLVL_FAILURE.
903 *
904 * @returns Number of chars printed.
905 * @param pszFormat The message.
906 * @param va Arguments.
907 */
908RTR3DECL(int) RTTestIFailureDetailsV(const char *pszFormat, va_list va);
909
910/**
911 * Same as RTTestIPrintf with RTTESTLVL_FAILURE.
912 *
913 * @returns Number of chars printed.
914 * @param pszFormat The message.
915 * @param ... Arguments.
916 */
917RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...);
918
919
920/** @def RTTESTI_CHECK
921 * Check whether a boolean expression holds true.
922 *
923 * If the expression is false, call RTTestIFailed giving the line number and
924 * expression.
925 *
926 * @param expr The expression to evaluate.
927 */
928#define RTTESTI_CHECK(expr) \
929 do { if (!(expr)) { \
930 RTTestIFailed("line %u: %s", __LINE__, #expr); \
931 } \
932 } while (0)
933/** @def RTTESTI_CHECK_RET
934 * Check whether a boolean expression holds true, returns on false.
935 *
936 * If the expression is false, call RTTestIFailed giving the line number and
937 * expression.
938 *
939 * @param expr The expression to evaluate.
940 * @param rcRet What to return on failure.
941 */
942#define RTTESTI_CHECK_RET(expr, rcRet) \
943 do { if (!(expr)) { \
944 RTTestIFailed("line %u: %s", __LINE__, #expr); \
945 return (rcRet); \
946 } \
947 } while (0)
948/** @def RTTESTI_CHECK_RETV
949 * Check whether a boolean expression holds true, returns void on false.
950 *
951 * If the expression is false, call RTTestIFailed giving the line number and
952 * expression.
953 *
954 * @param expr The expression to evaluate.
955 */
956#define RTTESTI_CHECK_RETV(expr) \
957 do { if (!(expr)) { \
958 RTTestIFailed("line %u: %s", __LINE__, #expr); \
959 return; \
960 } \
961 } while (0)
962
963
964/** @def RTTESTI_CHECK_MSG
965 * Check whether a boolean expression holds true.
966 *
967 * If the expression is false, call RTTestIFailed giving the line number and
968 * expression.
969 *
970 * @param expr The expression to evaluate.
971 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
972 * parenthesis.
973 */
974#define RTTESTI_CHECK_MSG(expr, DetailsArgs) \
975 do { if (!(expr)) { \
976 RTTestIFailed("line %u: %s", __LINE__, #expr); \
977 RTTestIFailureDetails DetailsArgs; \
978 } \
979 } while (0)
980/** @def RTTESTI_CHECK_MSG_RET
981 * Check whether a boolean expression holds true, returns on false.
982 *
983 * If the expression is false, call RTTestIFailed giving the line number and
984 * expression.
985 *
986 * @param expr The expression to evaluate.
987 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
988 * parenthesis.
989 * @param rcRet What to return on failure.
990 */
991#define RTTESTI_CHECK_MSG_RET(expr, DetailsArgs, rcRet) \
992 do { if (!(expr)) { \
993 RTTestIFailed("line %u: %s", __LINE__, #expr); \
994 RTTestIFailureDetails DetailsArgs; \
995 return (rcRet); \
996 } \
997 } while (0)
998/** @def RTTESTI_CHECK_MSG_RET
999 * Check whether a boolean expression holds true, returns void on false.
1000 *
1001 * If the expression is false, call RTTestIFailed giving the line number and
1002 * expression.
1003 *
1004 * @param expr The expression to evaluate.
1005 * @param DetailsArgs Argument list for RTTestIFailureDetails, including
1006 * parenthesis.
1007 */
1008#define RTTESTI_CHECK_MSG_RETV(expr, DetailsArgs) \
1009 do { if (!(expr)) { \
1010 RTTestIFailed("line %u: %s", __LINE__, #expr); \
1011 RTTestIFailureDetails DetailsArgs; \
1012 return; \
1013 } \
1014 } while (0)
1015
1016
1017/** @def RTTESTI_CHECK_RC
1018 * Check whether an expression returns a specific IPRT style status code.
1019 *
1020 * If a different status code is return, call RTTestIFailed giving the line
1021 * number, expression, actual and expected status codes.
1022 *
1023 * @param rcExpr The expression resulting in an IPRT status code.
1024 * @param rcExpect The expected return code. This may be referenced
1025 * more than once by the macro.
1026 */
1027#define RTTESTI_CHECK_RC(rcExpr, rcExpect) \
1028 do { \
1029 int rcCheck = (rcExpr); \
1030 if (rcCheck != (rcExpect)) { \
1031 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1032 } \
1033 } while (0)
1034/** @def RTTESTI_CHECK_RC_RET
1035 * Check whether an expression returns a specific IPRT style status code.
1036 *
1037 * If a different status code is return, call RTTestIFailed giving the line
1038 * number, expression, actual and expected status codes, then return.
1039 *
1040 * @param rcExpr The expression resulting in an IPRT status code.
1041 * This will be assigned to a local rcCheck variable
1042 * that can be used as return value.
1043 * @param rcExpect The expected return code. This may be referenced
1044 * more than once by the macro.
1045 * @param rcRet The return code.
1046 */
1047#define RTTESTI_CHECK_RC_RET(rcExpr, rcExpect, rcRet) \
1048 do { \
1049 int rcCheck = (rcExpr); \
1050 if (rcCheck != (rcExpect)) { \
1051 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1052 return (rcRet); \
1053 } \
1054 } while (0)
1055/** @def RTTESTI_CHECK_RC_RETV
1056 * Check whether an expression returns a specific IPRT style status code.
1057 *
1058 * If a different status code is return, call RTTestIFailed giving the line
1059 * number, expression, actual and expected status codes, then return.
1060 *
1061 * @param rcExpr The expression resulting in an IPRT status code.
1062 * @param rcExpect The expected return code. This may be referenced
1063 * more than once by the macro.
1064 */
1065#define RTTESTI_CHECK_RC_RETV(rcExpr, rcExpect) \
1066 do { \
1067 int rcCheck = (rcExpr); \
1068 if (rcCheck != (rcExpect)) { \
1069 RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
1070 return; \
1071 } \
1072 } while (0)
1073
1074
1075/** @def RTTESTI_CHECK_RC_OK
1076 * Check whether a IPRT style status code indicates success.
1077 *
1078 * If the status indicates failure, call RTTestIFailed giving the line number,
1079 * expression and status code.
1080 *
1081 * @param rcExpr The expression resulting in an IPRT status code.
1082 */
1083#define RTTESTI_CHECK_RC_OK(rcExpr) \
1084 do { \
1085 int rcCheck = (rcExpr); \
1086 if (RT_FAILURE(rcCheck)) { \
1087 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1088 } \
1089 } while (0)
1090/** @def RTTESTI_CHECK_RC_OK_RET
1091 * Check whether a IPRT style status code indicates success.
1092 *
1093 * If the status indicates failure, call RTTestIFailed giving the line number,
1094 * expression and status code, then return with the specified value.
1095 *
1096 * @param rcExpr The expression resulting in an IPRT status code.
1097 * This will be assigned to a local rcCheck variable
1098 * that can be used as return value.
1099 * @param rcRet The return code.
1100 */
1101#define RTTESTI_CHECK_RC_OK_RET(rcExpr, rcRet) \
1102 do { \
1103 int rcCheck = (rcExpr); \
1104 if (RT_FAILURE(rcCheck)) { \
1105 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1106 return (rcRet); \
1107 } \
1108 } while (0)
1109/** @def RTTESTI_CHECK_RC_OK_RETV
1110 * Check whether a IPRT style status code indicates success.
1111 *
1112 * If the status indicates failure, call RTTestIFailed giving the line number,
1113 * expression and status code, then return.
1114 *
1115 * @param rcExpr The expression resulting in an IPRT status code.
1116 */
1117#define RTTESTI_CHECK_RC_OK_RETV(rcExpr) \
1118 do { \
1119 int rcCheck = (rcExpr); \
1120 if (RT_FAILURE(rcCheck)) { \
1121 RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
1122 return; \
1123 } \
1124 } while (0)
1125
1126/** @} */
1127
1128
1129/** @} */
1130
1131RT_C_DECLS_END
1132
1133#endif
1134
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