Changeset 25694 in vbox
- Timestamp:
- Jan 8, 2010 4:43:29 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
-
common/misc/lockvalidator.cpp (modified) (1 diff)
-
testcase/tstRTLockValidator.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25692 r25694 382 382 static void rtLockValComplainAboutClass(const char *pszPrefix, RTLOCKVALCLASSINT *pClass, uint32_t uSubClass, bool fVerbose) 383 383 { 384 384 if ( VALID_PTR(pClass) 385 && pClass->u32Magic == RTLOCKVALCLASS_MAGIC) 386 { 387 388 } 385 389 } 386 390 -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25690 r25694 68 68 static uint32_t g_iDeadlockThread; 69 69 static RTTHREAD g_ahThreads[32]; 70 static RTLOCKVALCLASS g_ahClasses[32]; 70 71 static RTCRITSECT g_aCritSects[32]; 71 72 static RTSEMRW g_ahSemRWs[32]; … … 340 341 for (uint32_t i = 0; i < cThreads; i++) 341 342 { 342 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInit(&g_aCritSects[i]), VINF_SUCCESS); 343 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInitEx(&g_aCritSects[i], 0 /*fFlags*/, NIL_RTLOCKVALCLASS, 344 RTLOCKVAL_SUB_CLASS_ANY, "RTCritSect"), VINF_SUCCESS); 343 345 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreate(&g_ahSemRWs[i]), VINF_SUCCESS); 344 346 RTTEST_CHECK_RC_RETV(g_hTest, RTSemMutexCreate(&g_ahSemMtxes[i]), VINF_SUCCESS); … … 418 420 419 421 420 static DECLCALLBACK(int) test 1Thread(RTTHREAD ThreadSelf, void *pvUser)422 static DECLCALLBACK(int) testDd1Thread(RTTHREAD ThreadSelf, void *pvUser) 421 423 { 422 424 uintptr_t i = (uintptr_t)pvUser; … … 452 454 453 455 454 static void test 1(uint32_t cThreads, uint32_t cSecs)455 { 456 testIt(cThreads, cSecs, false, test 1Thread, "critsect");457 } 458 459 460 static DECLCALLBACK(int) test 2Thread(RTTHREAD ThreadSelf, void *pvUser)456 static void testDd1(uint32_t cThreads, uint32_t cSecs) 457 { 458 testIt(cThreads, cSecs, false, testDd1Thread, "critsect"); 459 } 460 461 462 static DECLCALLBACK(int) testDd2Thread(RTTHREAD ThreadSelf, void *pvUser) 461 463 { 462 464 uintptr_t i = (uintptr_t)pvUser; … … 508 510 509 511 510 static void test 2(uint32_t cThreads, uint32_t cSecs)511 { 512 testIt(cThreads, cSecs, false, test 2Thread, "read-write");513 } 514 515 516 static DECLCALLBACK(int) test 3Thread(RTTHREAD ThreadSelf, void *pvUser)512 static void testDd2(uint32_t cThreads, uint32_t cSecs) 513 { 514 testIt(cThreads, cSecs, false, testDd2Thread, "read-write"); 515 } 516 517 518 static DECLCALLBACK(int) testDd3Thread(RTTHREAD ThreadSelf, void *pvUser) 517 519 { 518 520 uintptr_t i = (uintptr_t)pvUser; … … 555 557 556 558 557 static void test 3(uint32_t cThreads, uint32_t cSecs)558 { 559 testIt(cThreads, cSecs, true, test 3Thread, "read-write race");560 } 561 562 563 static DECLCALLBACK(int) test 4Thread(RTTHREAD ThreadSelf, void *pvUser)559 static void testDd3(uint32_t cThreads, uint32_t cSecs) 560 { 561 testIt(cThreads, cSecs, true, testDd3Thread, "read-write race"); 562 } 563 564 565 static DECLCALLBACK(int) testDd4Thread(RTTHREAD ThreadSelf, void *pvUser) 564 566 { 565 567 uintptr_t i = (uintptr_t)pvUser; … … 611 613 612 614 613 static void test 4(uint32_t cThreads, uint32_t cSecs)614 { 615 testIt(cThreads, cSecs, true, test 4Thread, "read-write race v2");616 } 617 618 619 static DECLCALLBACK(int) test 5Thread(RTTHREAD ThreadSelf, void *pvUser)615 static void testDd4(uint32_t cThreads, uint32_t cSecs) 616 { 617 testIt(cThreads, cSecs, true, testDd4Thread, "read-write race v2"); 618 } 619 620 621 static DECLCALLBACK(int) testDd5Thread(RTTHREAD ThreadSelf, void *pvUser) 620 622 { 621 623 uintptr_t i = (uintptr_t)pvUser; … … 651 653 652 654 653 static void test 5(uint32_t cThreads, uint32_t cSecs)654 { 655 testIt(cThreads, cSecs, false, test 5Thread, "mutex");656 } 657 658 659 static DECLCALLBACK(int) test 6Thread(RTTHREAD ThreadSelf, void *pvUser)655 static void testDd5(uint32_t cThreads, uint32_t cSecs) 656 { 657 testIt(cThreads, cSecs, false, testDd5Thread, "mutex"); 658 } 659 660 661 static DECLCALLBACK(int) testDd6Thread(RTTHREAD ThreadSelf, void *pvUser) 660 662 { 661 663 uintptr_t i = (uintptr_t)pvUser; … … 704 706 705 707 706 static void test 6(uint32_t cThreads, uint32_t cSecs)707 { 708 testIt(cThreads, cSecs, false, test 6Thread, "event");709 } 710 711 712 static DECLCALLBACK(int) test 7Thread(RTTHREAD ThreadSelf, void *pvUser)708 static void testDd6(uint32_t cThreads, uint32_t cSecs) 709 { 710 testIt(cThreads, cSecs, false, testDd6Thread, "event"); 711 } 712 713 714 static DECLCALLBACK(int) testDd7Thread(RTTHREAD ThreadSelf, void *pvUser) 713 715 { 714 716 uintptr_t i = (uintptr_t)pvUser; … … 758 760 759 761 760 static void test7(uint32_t cThreads, uint32_t cSecs) 761 { 762 testIt(cThreads, cSecs, false, test7Thread, "event multi"); 763 } 764 762 static void testDd7(uint32_t cThreads, uint32_t cSecs) 763 { 764 testIt(cThreads, cSecs, false, testDd7Thread, "event multi"); 765 } 766 767 768 static void testLo1(void) 769 { 770 RTTestSub(g_hTest, "locking order, automatic"); 771 772 /* init, each critsect has its own class now. */ 773 for (unsigned i = 0; i < RT_ELEMENTS(g_ahClasses); i++) 774 { 775 RTTEST_CHECK_RC_RETV(g_hTest, RTLockValidatorClassCreate(&g_ahClasses[i], true /*fAutodidact*/, RT_SRC_POS), VINF_SUCCESS); 776 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInitEx(&g_aCritSects[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectLO"), VINF_SUCCESS); 777 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 3); 778 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 2); 779 } 780 781 /* Enter the first 4 critsects in ascending order and thereby definining 782 this as a valid lock order. */ 783 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[0]), VINF_SUCCESS); 784 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[1]), VINF_SUCCESS); 785 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[2]), VINF_SUCCESS); 786 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[3]), VINF_SUCCESS); 787 788 /* Now, leave and re-enter the critsects in a way that should break the 789 order and check that we get the appropriate response. */ 790 int rc; 791 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 792 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[0]), VERR_SEM_LV_WRONG_ORDER); 793 if (RT_SUCCESS(rc)) 794 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 795 796 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 797 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[1]), VERR_SEM_LV_WRONG_ORDER); 798 if (RT_SUCCESS(rc)) 799 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 800 801 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); 802 RTTEST_CHECK_RC(g_hTest, rc= RTCritSectEnter(&g_aCritSects[2]), VERR_SEM_LV_WRONG_ORDER); 803 if (RT_SUCCESS(rc)) 804 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); 805 806 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[3]), VINF_SUCCESS); 807 808 /* Check that recursion isn't subject to order checks. */ 809 810 811 /* Enable strict release order for class 2 and check that violations 812 are caught. */ 813 814 815 /* clean up */ 816 for (unsigned i = 0; i < RT_ELEMENTS(g_ahClasses); i++) 817 { 818 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); 819 g_ahClasses[i] = NIL_RTLOCKVALCLASS; 820 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectDelete(&g_aCritSects[i]), VINF_SUCCESS); 821 } 822 } 765 823 766 824 static bool testIsLockValidationCompiledIn(void) … … 837 895 RTLockValidatorSetQuiet(false); 838 896 897 bool fTestDd = false;//true; 898 bool fTestLo = true; 899 839 900 /* 840 901 * Some initial tests with verbose output (all single pass). 841 902 */ 842 test1(3, 0); 843 test2(1, 0); 844 test2(3, 0); 845 test5(3, 0); 846 test6(3, 0); 847 test7(3, 0); 903 if (fTestDd) 904 { 905 testDd1(3, 0); 906 testDd2(1, 0); 907 testDd2(3, 0); 908 testDd5(3, 0); 909 testDd6(3, 0); 910 testDd7(3, 0); 911 } 912 if (fTestLo) 913 { 914 testLo1(); 915 } 916 848 917 849 918 /* … … 854 923 RTLockValidatorSetQuiet(true); 855 924 856 test1( 2, SECS_SIMPLE_TEST); 857 test1( 3, SECS_SIMPLE_TEST); 858 test1( 7, SECS_SIMPLE_TEST); 859 test1(10, SECS_SIMPLE_TEST); 860 test1(15, SECS_SIMPLE_TEST); 861 test1(30, SECS_SIMPLE_TEST); 862 863 test2( 1, SECS_SIMPLE_TEST); 864 test2( 2, SECS_SIMPLE_TEST); 865 test2( 3, SECS_SIMPLE_TEST); 866 test2( 7, SECS_SIMPLE_TEST); 867 test2(10, SECS_SIMPLE_TEST); 868 test2(15, SECS_SIMPLE_TEST); 869 test2(30, SECS_SIMPLE_TEST); 870 871 test3( 2, SECS_SIMPLE_TEST); 872 test3(10, SECS_SIMPLE_TEST); 873 874 test4( 2, SECS_RACE_TEST); 875 test4( 6, SECS_RACE_TEST); 876 test4(10, SECS_RACE_TEST); 877 test4(30, SECS_RACE_TEST); 878 879 test5( 2, SECS_RACE_TEST); 880 test5( 3, SECS_RACE_TEST); 881 test5( 7, SECS_RACE_TEST); 882 test5(10, SECS_RACE_TEST); 883 test5(15, SECS_RACE_TEST); 884 test5(30, SECS_RACE_TEST); 885 886 test6( 2, SECS_SIMPLE_TEST); 887 test6( 3, SECS_SIMPLE_TEST); 888 test6( 7, SECS_SIMPLE_TEST); 889 test6(10, SECS_SIMPLE_TEST); 890 test6(15, SECS_SIMPLE_TEST); 891 test6(30, SECS_SIMPLE_TEST); 892 893 test7( 2, SECS_SIMPLE_TEST); 894 test7( 3, SECS_SIMPLE_TEST); 895 test7( 7, SECS_SIMPLE_TEST); 896 test7(10, SECS_SIMPLE_TEST); 897 test7(15, SECS_SIMPLE_TEST); 898 test7(30, SECS_SIMPLE_TEST); 925 if (fTestDd) 926 { 927 testDd1( 2, SECS_SIMPLE_TEST); 928 testDd1( 3, SECS_SIMPLE_TEST); 929 testDd1( 7, SECS_SIMPLE_TEST); 930 testDd1(10, SECS_SIMPLE_TEST); 931 testDd1(15, SECS_SIMPLE_TEST); 932 testDd1(30, SECS_SIMPLE_TEST); 933 934 testDd2( 1, SECS_SIMPLE_TEST); 935 testDd2( 2, SECS_SIMPLE_TEST); 936 testDd2( 3, SECS_SIMPLE_TEST); 937 testDd2( 7, SECS_SIMPLE_TEST); 938 testDd2(10, SECS_SIMPLE_TEST); 939 testDd2(15, SECS_SIMPLE_TEST); 940 testDd2(30, SECS_SIMPLE_TEST); 941 942 testDd3( 2, SECS_SIMPLE_TEST); 943 testDd3(10, SECS_SIMPLE_TEST); 944 945 testDd4( 2, SECS_RACE_TEST); 946 testDd4( 6, SECS_RACE_TEST); 947 testDd4(10, SECS_RACE_TEST); 948 testDd4(30, SECS_RACE_TEST); 949 950 testDd5( 2, SECS_RACE_TEST); 951 testDd5( 3, SECS_RACE_TEST); 952 testDd5( 7, SECS_RACE_TEST); 953 testDd5(10, SECS_RACE_TEST); 954 testDd5(15, SECS_RACE_TEST); 955 testDd5(30, SECS_RACE_TEST); 956 957 testDd6( 2, SECS_SIMPLE_TEST); 958 testDd6( 3, SECS_SIMPLE_TEST); 959 testDd6( 7, SECS_SIMPLE_TEST); 960 testDd6(10, SECS_SIMPLE_TEST); 961 testDd6(15, SECS_SIMPLE_TEST); 962 testDd6(30, SECS_SIMPLE_TEST); 963 964 testDd7( 2, SECS_SIMPLE_TEST); 965 testDd7( 3, SECS_SIMPLE_TEST); 966 testDd7( 7, SECS_SIMPLE_TEST); 967 testDd7(10, SECS_SIMPLE_TEST); 968 testDd7(15, SECS_SIMPLE_TEST); 969 testDd7(30, SECS_SIMPLE_TEST); 970 } 899 971 } 900 972
Note:
See TracChangeset
for help on using the changeset viewer.

