VirtualBox

Changeset 86626 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 19, 2020 10:42:10 AM (4 years ago)
Author:
vboxsync
Message:

tstIprtList.cpp: Fixes to MtTestSafeRandomIndex. Use event semaphore to kick off all threads at once to increase contention. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstIprtList.cpp

    r86619 r86626  
    490490#define MTTEST_ITEMS_NOT_REMOVED    100
    491491
     492static RTSEMEVENTMULTI g_hEvtMtTest = NIL_RTSEMEVENTMULTI;
     493
    492494/**
    493495 * Thread for prepending items to a shared list.
     
    500502    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    501503    RT_NOREF_PV(hSelf);
     504    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    502505
    503506    /* Prepend new items at the start of the list. */
     
    518521    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    519522    RT_NOREF_PV(hSelf);
     523    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    520524
    521525    /* Append new items at the end of the list. */
     
    531535    uint32_t cItems = (uint32_t)pTestList->size();
    532536    if (cItems > MTTEST_ITEMS)
     537    {
    533538        cItems -= MTTEST_ITEMS;
    534     if (cItems < MTTEST_ITEMS_NOT_REMOVED)
     539        if (cItems < MTTEST_ITEMS_NOT_REMOVED)
     540            cItems = MTTEST_ITEMS_NOT_REMOVED;
     541    }
     542    else if (cItems > MTTEST_ITEMS_NOT_REMOVED)
    535543        cItems = MTTEST_ITEMS_NOT_REMOVED;
     544    else if (cItems <= 1)
     545        return 0;
    536546    return RTRandU32Ex(0, cItems - 1);
    537547}
     
    547557    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    548558    RT_NOREF_PV(hSelf);
     559    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    549560
    550561    /* Insert new items in the middle of the list. */
     
    565576    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    566577    RT_NOREF_PV(hSelf);
     578    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    567579
    568580    MTTEST_TYPE a;
     
    589601    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    590602    RT_NOREF_PV(hSelf);
     603    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    591604
    592605    /* Try to replace C items from random places. */
     
    612625    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    613626    RT_NOREF_PV(hSelf);
     627    RTSemEventMultiWait(g_hEvtMtTest, RT_MS_1MIN);
    614628
    615629    /* Try to delete items from random places. */
     
    641655    };
    642656
     657    RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&g_hEvtMtTest), VINF_SUCCESS);
     658
    643659    for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
    644660    {
     
    647663    }
    648664
    649     uint64_t tsMsDeadline = RTTimeMilliTS() + 60000;
     665    RTTESTI_CHECK_RC(RTSemEventMultiSignal(g_hEvtMtTest), VINF_SUCCESS);
     666    uint64_t tsMsDeadline = RTTimeMilliTS() + RT_MS_1MIN;
    650667    for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
    651668    {
     
    654671        RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], cWait, NULL), VINF_SUCCESS);
    655672    }
     673    RTTESTI_CHECK_RC(RTSemEventMultiDestroy(g_hEvtMtTest), VINF_SUCCESS);
     674    g_hEvtMtTest = NIL_RTSEMEVENTMULTI;
    656675
    657676    RTTESTI_CHECK_RETV(testList.size() == MTTEST_ITEMS * 2);
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