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