VirtualBox

Changeset 25694 in vbox


Ignore:
Timestamp:
Jan 8, 2010 4:43:29 PM (15 years ago)
Author:
vboxsync
Message:

working on lock order testcase...

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25692 r25694  
    382382static void rtLockValComplainAboutClass(const char *pszPrefix, RTLOCKVALCLASSINT *pClass, uint32_t uSubClass, bool fVerbose)
    383383{
    384 
     384    if (   VALID_PTR(pClass)
     385        && pClass->u32Magic == RTLOCKVALCLASS_MAGIC)
     386    {
     387
     388    }
    385389}
    386390
  • trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp

    r25690 r25694  
    6868static uint32_t             g_iDeadlockThread;
    6969static RTTHREAD             g_ahThreads[32];
     70static RTLOCKVALCLASS       g_ahClasses[32];
    7071static RTCRITSECT           g_aCritSects[32];
    7172static RTSEMRW              g_ahSemRWs[32];
     
    340341    for (uint32_t i = 0; i < cThreads; i++)
    341342    {
    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);
    343345        RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreate(&g_ahSemRWs[i]), VINF_SUCCESS);
    344346        RTTEST_CHECK_RC_RETV(g_hTest, RTSemMutexCreate(&g_ahSemMtxes[i]), VINF_SUCCESS);
     
    418420
    419421
    420 static DECLCALLBACK(int) test1Thread(RTTHREAD ThreadSelf, void *pvUser)
     422static DECLCALLBACK(int) testDd1Thread(RTTHREAD ThreadSelf, void *pvUser)
    421423{
    422424    uintptr_t       i     = (uintptr_t)pvUser;
     
    452454
    453455
    454 static void test1(uint32_t cThreads, uint32_t cSecs)
    455 {
    456     testIt(cThreads, cSecs, false, test1Thread, "critsect");
    457 }
    458 
    459 
    460 static DECLCALLBACK(int) test2Thread(RTTHREAD ThreadSelf, void *pvUser)
     456static void testDd1(uint32_t cThreads, uint32_t cSecs)
     457{
     458    testIt(cThreads, cSecs, false, testDd1Thread, "critsect");
     459}
     460
     461
     462static DECLCALLBACK(int) testDd2Thread(RTTHREAD ThreadSelf, void *pvUser)
    461463{
    462464    uintptr_t       i     = (uintptr_t)pvUser;
     
    508510
    509511
    510 static void test2(uint32_t cThreads, uint32_t cSecs)
    511 {
    512     testIt(cThreads, cSecs, false, test2Thread, "read-write");
    513 }
    514 
    515 
    516 static DECLCALLBACK(int) test3Thread(RTTHREAD ThreadSelf, void *pvUser)
     512static void testDd2(uint32_t cThreads, uint32_t cSecs)
     513{
     514    testIt(cThreads, cSecs, false, testDd2Thread, "read-write");
     515}
     516
     517
     518static DECLCALLBACK(int) testDd3Thread(RTTHREAD ThreadSelf, void *pvUser)
    517519{
    518520    uintptr_t       i     = (uintptr_t)pvUser;
     
    555557
    556558
    557 static void test3(uint32_t cThreads, uint32_t cSecs)
    558 {
    559     testIt(cThreads, cSecs, true, test3Thread, "read-write race");
    560 }
    561 
    562 
    563 static DECLCALLBACK(int) test4Thread(RTTHREAD ThreadSelf, void *pvUser)
     559static void testDd3(uint32_t cThreads, uint32_t cSecs)
     560{
     561    testIt(cThreads, cSecs, true, testDd3Thread, "read-write race");
     562}
     563
     564
     565static DECLCALLBACK(int) testDd4Thread(RTTHREAD ThreadSelf, void *pvUser)
    564566{
    565567    uintptr_t       i     = (uintptr_t)pvUser;
     
    611613
    612614
    613 static void test4(uint32_t cThreads, uint32_t cSecs)
    614 {
    615     testIt(cThreads, cSecs, true, test4Thread, "read-write race v2");
    616 }
    617 
    618 
    619 static DECLCALLBACK(int) test5Thread(RTTHREAD ThreadSelf, void *pvUser)
     615static void testDd4(uint32_t cThreads, uint32_t cSecs)
     616{
     617    testIt(cThreads, cSecs, true, testDd4Thread, "read-write race v2");
     618}
     619
     620
     621static DECLCALLBACK(int) testDd5Thread(RTTHREAD ThreadSelf, void *pvUser)
    620622{
    621623    uintptr_t       i     = (uintptr_t)pvUser;
     
    651653
    652654
    653 static void test5(uint32_t cThreads, uint32_t cSecs)
    654 {
    655     testIt(cThreads, cSecs, false, test5Thread, "mutex");
    656 }
    657 
    658 
    659 static DECLCALLBACK(int) test6Thread(RTTHREAD ThreadSelf, void *pvUser)
     655static void testDd5(uint32_t cThreads, uint32_t cSecs)
     656{
     657    testIt(cThreads, cSecs, false, testDd5Thread, "mutex");
     658}
     659
     660
     661static DECLCALLBACK(int) testDd6Thread(RTTHREAD ThreadSelf, void *pvUser)
    660662{
    661663    uintptr_t       i     = (uintptr_t)pvUser;
     
    704706
    705707
    706 static void test6(uint32_t cThreads, uint32_t cSecs)
    707 {
    708     testIt(cThreads, cSecs, false, test6Thread, "event");
    709 }
    710 
    711 
    712 static DECLCALLBACK(int) test7Thread(RTTHREAD ThreadSelf, void *pvUser)
     708static void testDd6(uint32_t cThreads, uint32_t cSecs)
     709{
     710    testIt(cThreads, cSecs, false, testDd6Thread, "event");
     711}
     712
     713
     714static DECLCALLBACK(int) testDd7Thread(RTTHREAD ThreadSelf, void *pvUser)
    713715{
    714716    uintptr_t       i     = (uintptr_t)pvUser;
     
    758760
    759761
    760 static void test7(uint32_t cThreads, uint32_t cSecs)
    761 {
    762     testIt(cThreads, cSecs, false, test7Thread, "event multi");
    763 }
    764 
     762static void testDd7(uint32_t cThreads, uint32_t cSecs)
     763{
     764    testIt(cThreads, cSecs, false, testDd7Thread, "event multi");
     765}
     766
     767
     768static 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}
    765823
    766824static bool testIsLockValidationCompiledIn(void)
     
    837895    RTLockValidatorSetQuiet(false);
    838896
     897    bool fTestDd = false;//true;
     898    bool fTestLo = true;
     899
    839900    /*
    840901     * Some initial tests with verbose output (all single pass).
    841902     */
    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
    848917
    849918    /*
     
    854923        RTLockValidatorSetQuiet(true);
    855924
    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        }
    899971    }
    900972
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette