儲存庫 vbox 的更動 18569
圖例:
- 未更動
- 新增
- 刪除
-
trunk/include/iprt/test.h
r18366 r18569 52 52 #define NIL_RTTEST ((RTTEST)0) 53 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 54 75 55 76 /** … … 121 142 * @param hTest The test handle. If NIL_RTTEST we'll use the one 122 143 * associated with the calling thread. 144 * @param enmLevel Message importance level. 123 145 * @param pszFormat The message. 124 146 * @param va Arguments. 125 147 */ 126 RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, const char *pszFormat, va_list va);148 RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va); 127 149 128 150 /** … … 132 154 * @param hTest The test handle. If NIL_RTTEST we'll use the one 133 155 * associated with the calling thread. 156 * @param enmLevel Message importance level. 134 157 * @param pszFormat The message. 135 158 * @param ... Arguments. 136 159 */ 137 RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, const char *pszFormat, ...);160 RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...); 138 161 139 162 /** … … 143 166 * @param hTest The test handle. If NIL_RTTEST we'll use the one 144 167 * associated with the calling thread. 168 * @param enmLevel Message importance level. 145 169 * @param pszFormat The message. 146 170 * @param va Arguments. 147 171 */ 148 RTR3DECL(int) RTTestPrintfV(RTTEST hTest, const char *pszFormat, va_list va);172 RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va); 149 173 150 174 /** … … 154 178 * @param hTest The test handle. If NIL_RTTEST we'll use the one 155 179 * associated with the calling thread. 180 * @param enmLevel Message importance level. 156 181 * @param pszFormat The message. 157 182 * @param ... Arguments. 158 183 */ 159 RTR3DECL(int) RTTestPrintf(RTTEST hTest, const char *pszFormat, ...);184 RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...); 160 185 161 186 /** … … 176 201 */ 177 202 RTR3DECL(int) RTTestSummaryAndDestroy(RTTEST hTest); 203 204 /** 205 * Starts a sub-test. 206 * 207 * This will perform an implicit RTTestSubDone() call if that has not been done 208 * since the last RTTestSub call. 209 * 210 * @returns Number of chars printed. 211 * @param hTest The test handle. If NIL_RTTEST we'll use the one 212 * associated with the calling thread. 213 * @param pszSubTest The sub-test name 214 */ 215 RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest); 216 217 /** 218 * Completes a sub-test. 219 * 220 * @returns Number of chars printed. 221 * @param hTest The test handle. If NIL_RTTEST we'll use the one 222 * associated with the calling thread. 223 */ 224 RTR3DECL(int) RTTestSubDone(RTTEST hTest); 178 225 179 226 /** … … 220 267 do { if (!(expr)) { RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); } } while (0) 221 268 269 /** @def RTTEST_CHECK_MSG 270 * Check whether a boolean expression holds true. 271 * 272 * If the expression is false, call RTTestFailed giving the line number and expression. 273 * 274 * @param hTest The test handle. 275 * @param expr The expression to evaluate. 276 * @param TestPrintfArgs Argument list for RTTestPrintf, including 277 * parenthesis. 278 */ 279 #define RTTEST_CHECK_MSG(hTest, expr, TestPrintfArgs) \ 280 do { if (!(expr)) { \ 281 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \ 282 RTTestPrintf TestPrintfArgs; \ 283 } \ 284 } while (0) 285 286 287 /** 288 * Prints an extended PASSED message, optional. 289 * 290 * This does not conclude the sub-test, it could be used to report the passing 291 * of a sub-sub-to-the-power-of-N-test. 292 * 293 * @returns IPRT status code. 294 * @param hTest The test handle. If NIL_RTTEST we'll use the one 295 * associated with the calling thread. 296 * @param pszFormat The message. No trailing newline. 297 * @param va The arguments. 298 */ 299 RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va); 300 301 /** 302 * Prints an extended PASSED message, optional. 303 * 304 * This does not conclude the sub-test, it could be used to report the passing 305 * of a sub-sub-to-the-power-of-N-test. 306 * 307 * @returns IPRT status code. 308 * @param hTest The test handle. If NIL_RTTEST we'll use the one 309 * associated with the calling thread. 310 * @param pszFormat The message. No trailing newline. 311 * @param ... The arguments. 312 */ 313 RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...); 314 222 315 223 316 /** @} */ -
trunk/src/VBox/Runtime/r3/test.cpp
r18427 r18569 86 86 const char *pszTest; 87 87 /** The length of the test name. */ 88 unsignedcchTest;88 size_t cchTest; 89 89 /** The size of a guard. Multiple of PAGE_SIZE. */ 90 90 uint32_t cbGuard; 91 92 /** Critical section seralizing access to the members following it. */ 93 RTCRITSECT Lock; 94 /** The list of guarded memory allocations. */ 95 PRTTESTGUARDEDMEM pGuardedMem; 91 /** The verbosity level. */ 92 RTTESTLVL enmMaxLevel; 93 96 94 97 95 /** Critical section seralizing output. */ … … 101 99 /** Whether we're currently at a newline. */ 102 100 bool fNewLine; 101 102 103 /** Critical section seralizing access to the members following it. */ 104 RTCRITSECT Lock; 105 106 /** The list of guarded memory allocations. */ 107 PRTTESTGUARDEDMEM pGuardedMem; 108 109 /** The current sub-test. */ 110 const char *pszSubTest; 111 /** The lenght of the sub-test name. */ 112 size_t cchSubTest; 113 /** Whether we've reported the sub-test result or not. */ 114 bool fSubTestReported; 115 /** The start error count of the current subtest. */ 116 uint32_t cSubTestAtErrors; 117 118 /** The number of sub tests. */ 119 uint32_t cSubTests; 120 /** The number of sub tests that failed. */ 121 uint32_t cSubTestsFailed; 103 122 104 123 } RTTESTINT; … … 195 214 if (!pTest) 196 215 return VERR_NO_MEMORY; 197 pTest->u32Magic = RTTESTINT_MAGIC; 198 pTest->cbGuard = PAGE_SIZE * 7; 199 pTest->pszTest = RTStrDup(pszTest); 200 pTest->cchTest = (unsigned)strlen(pszTest); 201 pTest->pOutStrm = g_pStdOut; 202 pTest->fNewLine = true; 216 pTest->u32Magic = RTTESTINT_MAGIC; 217 pTest->pszTest = RTStrDup(pszTest); 218 pTest->cchTest = strlen(pszTest); 219 pTest->cbGuard = PAGE_SIZE * 7; 220 pTest->enmMaxLevel = RTTESTLVL_SUB_TEST; 221 222 pTest->pOutStrm = g_pStdOut; 223 pTest->fNewLine = true; 224 225 pTest->pGuardedMem = NULL; 226 227 pTest->pszSubTest = NULL; 228 pTest->cchSubTest = 0; 229 pTest->fSubTestReported = true; 230 pTest->cSubTestAtErrors = 0; 231 pTest->cSubTests = 0; 232 pTest->cSubTestsFailed = 0; 203 233 204 234 rc = RTCritSectInit(&pTest->Lock); … … 269 299 } 270 300 301 RTStrFree((char *)pTest->pszSubTest); 302 pTest->pszSubTest = NULL; 271 303 RTStrFree((char *)pTest->pszTest); 272 304 pTest->pszTest = NULL; … … 544 576 * @param hTest The test handle. If NIL_RTTEST we'll use the one 545 577 * associated with the calling thread. 578 * @param enmLevel Message importance level. 546 579 * @param pszFormat The message. 547 580 * @param va Arguments. 548 581 */ 549 RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, const char *pszFormat, va_list va)582 RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va) 550 583 { 551 584 PRTTESTINT pTest = hTest; … … 555 588 556 589 int cch = 0; 557 if (!pTest->fNewLine) 558 cch += rtTestPrintf(pTest, "\n"); 559 cch += rtTestPrintfV(pTest, pszFormat, va); 590 if (enmLevel <= pTest->enmMaxLevel) 591 { 592 if (!pTest->fNewLine) 593 cch += rtTestPrintf(pTest, "\n"); 594 cch += rtTestPrintfV(pTest, pszFormat, va); 595 } 560 596 561 597 RTCritSectLeave(&pTest->OutputLock); … … 571 607 * @param hTest The test handle. If NIL_RTTEST we'll use the one 572 608 * associated with the calling thread. 609 * @param enmLevel Message importance level. 573 610 * @param pszFormat The message. 574 611 * @param ... Arguments. 575 612 */ 576 RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, const char *pszFormat, ...)613 RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...) 577 614 { 578 615 va_list va; 579 616 580 617 va_start(va, pszFormat); 581 int cch = RTTestPrintfNlV(hTest, pszFormat, va);618 int cch = RTTestPrintfNlV(hTest, enmLevel, pszFormat, va); 582 619 va_end(va); 583 620 … … 592 629 * @param hTest The test handle. If NIL_RTTEST we'll use the one 593 630 * associated with the calling thread. 631 * @param enmLevel Message importance level. 594 632 * @param pszFormat The message. 595 633 * @param va Arguments. 596 634 */ 597 RTR3DECL(int) RTTestPrintfV(RTTEST hTest, const char *pszFormat, va_list va)635 RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va) 598 636 { 599 637 PRTTESTINT pTest = hTest; … … 601 639 602 640 RTCritSectEnter(&pTest->OutputLock); 603 int cch = rtTestPrintfV(pTest, pszFormat, va); 641 int cch = 0; 642 if (enmLevel <= pTest->enmMaxLevel) 643 cch += rtTestPrintfV(pTest, pszFormat, va); 604 644 RTCritSectLeave(&pTest->OutputLock); 605 645 … … 614 654 * @param hTest The test handle. If NIL_RTTEST we'll use the one 615 655 * associated with the calling thread. 656 * @param enmLevel Message importance level. 616 657 * @param pszFormat The message. 617 658 * @param ... Arguments. 618 659 */ 619 RTR3DECL(int) RTTestPrintf(RTTEST hTest, const char *pszFormat, ...)660 RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...) 620 661 { 621 662 va_list va; 622 663 623 664 va_start(va, pszFormat); 624 int cch = RTTestPrintfV(hTest, pszFormat, va);665 int cch = RTTestPrintfV(hTest, enmLevel, pszFormat, va); 625 666 va_end(va); 626 667 … … 638 679 RTR3DECL(int) RTTestBanner(RTTEST hTest) 639 680 { 640 return RTTestPrintfNl(hTest, "TESTING...\n"); 681 return RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "TESTING...\n"); 682 } 683 684 685 /** 686 * Prints the result of a sub-test if necessary. 687 * 688 * @returns Number of chars printed. 689 * @param pTest The test instance. 690 * @remarks Caller own the test Lock. 691 */ 692 static int rtTestSubTestReport(PRTTESTINT pTest) 693 { 694 int cch = 0; 695 if ( !pTest->fSubTestReported 696 && pTest->pszSubTest) 697 { 698 pTest->fSubTestReported = true; 699 uint32_t cErrors = ASMAtomicUoReadU32(&pTest->cErrors) - pTest->cSubTestAtErrors; 700 if (!cErrors) 701 cch += RTTestPrintf(pTest, RTTESTLVL_SUB_TEST, "%-50s: PASSED\n", pTest->pszSubTest); 702 else 703 { 704 pTest->cSubTestsFailed++; 705 cch += RTTestPrintf(pTest, RTTESTLVL_SUB_TEST, "%-50s: FAILED (%u errors)\n", 706 pTest->pszSubTest, cErrors); 707 } 708 } 709 return cch; 710 } 711 712 713 /** 714 * RTTestSub and RTTestSubDone worker that cleans up the current (if any) 715 * sub test. 716 * 717 * @returns Number of chars printed. 718 * @param pTest The test instance. 719 * @remarks Caller own the test Lock. 720 */ 721 static int rtTestSubCleanup(PRTTESTINT pTest) 722 { 723 int cch = 0; 724 if (pTest->pszSubTest) 725 { 726 cch += rtTestSubTestReport(pTest); 727 728 RTStrFree((char *)pTest->pszSubTest); 729 pTest->pszSubTest = NULL; 730 pTest->fSubTestReported = true; 731 } 732 return cch; 641 733 } 642 734 … … 654 746 RTTEST_GET_VALID_RETURN_RC(pTest, 2); 655 747 748 RTCritSectEnter(&pTest->Lock); 749 rtTestSubTestReport(pTest); 750 RTCritSectLeave(&pTest->Lock); 751 656 752 int rc; 657 753 if (!pTest->cErrors) 658 754 { 659 RTTestPrintfNl(hTest, "SUCCESS\n", pTest->cErrors);755 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "SUCCESS\n", pTest->cErrors); 660 756 rc = 0; 661 757 } 662 758 else 663 759 { 664 RTTestPrintfNl(hTest, "FAILURE - %u errors\n", pTest->cErrors);760 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "FAILURE - %u errors\n", pTest->cErrors); 665 761 rc = 1; 666 762 } 763 667 764 668 765 RTTestDestroy(pTest); … … 672 769 673 770 /** 771 * Starts a sub-test. 772 * 773 * This will perform an implicit RTTestSubDone() call if that has not been done 774 * since the last RTTestSub call. 775 * 776 * @returns Number of chars printed. 777 * @param hTest The test handle. If NIL_RTTEST we'll use the one 778 * associated with the calling thread. 779 * @param pszSubTest The sub-test name 780 */ 781 RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest) 782 { 783 PRTTESTINT pTest = hTest; 784 RTTEST_GET_VALID_RETURN_RC(pTest, -1); 785 786 RTCritSectEnter(&pTest->Lock); 787 788 /* Cleanup, reporting if necessary previous sub test. */ 789 rtTestSubCleanup(pTest); 790 791 /* Start new sub test. */ 792 pTest->cSubTests++; 793 pTest->cSubTestAtErrors = ASMAtomicUoReadU32(&pTest->cErrors); 794 pTest->pszSubTest = RTStrDup(pszSubTest); 795 pTest->cchSubTest = strlen(pszSubTest); 796 pTest->fSubTestReported = false; 797 798 int cch = 0; 799 if (pTest->enmMaxLevel >= RTTESTLVL_DEBUG) 800 cch = RTTestPrintfNl(hTest, RTTESTLVL_DEBUG, "debug: Starting sub-test '%s'\n", pszSubTest); 801 802 RTCritSectLeave(&pTest->Lock); 803 804 return cch; 805 } 806 807 808 /** 809 * Completes a sub-test. 810 * 811 * @returns Number of chars printed. 812 * @param hTest The test handle. If NIL_RTTEST we'll use the one 813 * associated with the calling thread. 814 */ 815 RTR3DECL(int) RTTestSubDone(RTTEST hTest) 816 { 817 PRTTESTINT pTest = hTest; 818 RTTEST_GET_VALID_RETURN_RC(pTest, -1); 819 820 RTCritSectEnter(&pTest->Lock); 821 int cch = rtTestSubCleanup(pTest); 822 RTCritSectLeave(&pTest->Lock); 823 824 return cch; 825 } 826 827 828 /** 674 829 * Increments the error counter. 675 830 * … … 682 837 PRTTESTINT pTest = hTest; 683 838 RTTEST_GET_VALID_RETURN(pTest); 839 684 840 ASMAtomicIncU32(&pTest->cErrors); 841 685 842 return VINF_SUCCESS; 686 843 } … … 701 858 RTTEST_GET_VALID_RETURN_RC(pTest, -1); 702 859 703 va_list va2; 704 va_copy(va2, va); 705 706 RTCritSectEnter(&pTest->OutputLock); 707 ASMAtomicIncU32(&pTest->cErrors); 708 709 int cch = rtTestPrintf(pTest, "FAILED - %N\n", pszFormat, &va2); 710 711 RTCritSectLeave(&pTest->OutputLock); 712 713 va_end(va2); 860 RTTestErrorInc(pTest); 861 862 int cch = 0; 863 if (pTest->enmMaxLevel >= RTTESTLVL_FAILURE) 864 { 865 va_list va2; 866 va_copy(va2, va); 867 868 RTCritSectEnter(&pTest->OutputLock); 869 cch += rtTestPrintf(pTest, "%N\n", pszFormat, &va2); 870 RTCritSectLeave(&pTest->OutputLock); 871 872 va_end(va2); 873 } 714 874 715 875 return cch; … … 737 897 } 738 898 899 900 /** 901 * Prints an extended PASSED message, optional. 902 * 903 * This does not conclude the sub-test, it could be used to report the passing 904 * of a sub-sub-to-the-power-of-N-test. 905 * 906 * @returns IPRT status code. 907 * @param hTest The test handle. If NIL_RTTEST we'll use the one 908 * associated with the calling thread. 909 * @param pszFormat The message. No trailing newline. 910 * @param va The arguments. 911 */ 912 RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va) 913 { 914 PRTTESTINT pTest = hTest; 915 RTTEST_GET_VALID_RETURN_RC(pTest, -1); 916 917 int cch = 0; 918 if (pTest->enmMaxLevel >= RTTESTLVL_INFO) 919 { 920 va_list va2; 921 va_copy(va2, va); 922 923 RTCritSectEnter(&pTest->OutputLock); 924 cch += rtTestPrintf(pTest, "%N\n", pszFormat, &va2); 925 RTCritSectLeave(&pTest->OutputLock); 926 927 va_end(va2); 928 } 929 930 return cch; 931 } 932 933 934 /** 935 * Prints an extended PASSED message, optional. 936 * 937 * This does not conclude the sub-test, it could be used to report the passing 938 * of a sub-sub-to-the-power-of-N-test. 939 * 940 * @returns IPRT status code. 941 * @param hTest The test handle. If NIL_RTTEST we'll use the one 942 * associated with the calling thread. 943 * @param pszFormat The message. No trailing newline. 944 * @param ... The arguments. 945 */ 946 RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...) 947 { 948 va_list va; 949 950 va_start(va, pszFormat); 951 int cch = RTTestPassedV(hTest, pszFormat, va); 952 va_end(va); 953 954 return cch; 955 } 956 -
trunk/src/VBox/Runtime/testcase/tstBitOperations.cpp
r18425 r18569 157 157 struct TestMap *p = (struct TestMap *)RTTestGuardedAllocTail(hTest, sizeof(*p)); 158 158 #endif 159 #define DUMP() RTTestPrintf(hTest, "au32={%08x,%08x,%08x,%08x}", p->au32[0], p->au32[1], p->au32[2], p->au32[3])159 #define DUMP() RTTestPrintf(hTest, RTTESTLVL_INFO, "au32={%08x,%08x,%08x,%08x}", p->au32[0], p->au32[1], p->au32[2], p->au32[3]) 160 160 #define CHECK(expr) do { if (!(expr)) { RTTestFailed(hTest, "line %d: %s", __LINE__, #expr); DUMP(); } CHECK_GUARD(s); } while (0) 161 161 #define CHECK_BIT(expr, b1) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d: %s", __LINE__, b1, #expr); } CHECK_GUARD(s); } while (0)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器