VirtualBox

Changeset 86618 in vbox for trunk


Ignore:
Timestamp:
Oct 16, 2020 11:09:41 PM (4 years ago)
Author:
vboxsync
Message:

tstIprtList.cpp: Try not trigger assertions in at() and replace() because of races with the removal thread. bugref:9841

File:
1 edited

Legend:

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

    r85166 r86618  
    485485/* define RTCList here to see what happens without MT support ;)
    486486 * (valgrind is the preferred tool to check). */
    487 #define MTTESTLISTTYPE  RTCMTList
    488 #define MTTESTTYPE      uint32_t
    489 #define MTTESTITEMS     1000
     487#define MTTEST_LIST_TYPE            RTCMTList
     488#define MTTEST_TYPE                 uint32_t
     489#define MTTEST_ITEMS                1000
     490#define MTTEST_ITEMS_NOT_REMOVED    100
    490491
    491492/**
     
    497498static DECLCALLBACK(int) MtTest1ThreadProc(RTTHREAD hSelf, void *pvUser)
    498499{
    499     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     500    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    500501    RT_NOREF_PV(hSelf);
    501502
    502503    /* Prepend new items at the start of the list. */
    503     for (size_t i = 0; i < MTTESTITEMS; ++i)
     504    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    504505        pTestList->prepend(0x0);
    505506
     
    515516static DECLCALLBACK(int) MtTest2ThreadProc(RTTHREAD hSelf, void *pvUser)
    516517{
    517     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     518    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    518519    RT_NOREF_PV(hSelf);
    519520
    520521    /* Append new items at the end of the list. */
    521     for (size_t i = 0; i < MTTESTITEMS; ++i)
     522    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    522523        pTestList->append(0xFFFFFFFF);
    523524
     
    533534static DECLCALLBACK(int) MtTest3ThreadProc(RTTHREAD hSelf, void *pvUser)
    534535{
    535     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     536    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    536537    RT_NOREF_PV(hSelf);
    537538
    538539    /* Insert new items in the middle of the list. */
    539     for (size_t i = 0; i < MTTESTITEMS; ++i)
     540    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    540541        pTestList->insert(pTestList->size() / 2, 0xF0F0F0F0);
    541542
     
    551552static DECLCALLBACK(int) MtTest4ThreadProc(RTTHREAD hSelf, void *pvUser)
    552553{
    553     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     554    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    554555    RT_NOREF_PV(hSelf);
    555556
    556     MTTESTTYPE a;
     557    MTTEST_TYPE a;
    557558    /* Try to read C items from random places. */
    558     for (size_t i = 0; i < MTTESTITEMS; ++i)
     559    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    559560    {
    560561        /* Make sure there is at least one item in the list. */
    561562        while (pTestList->isEmpty())
    562563            RTThreadYield();
    563         a = pTestList->at(RTRandU32Ex(0, (uint32_t)pTestList->size() - 1));
     564        uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
     565        a = pTestList->at(idx);
    564566    }
    565567
     
    575577static DECLCALLBACK(int) MtTest5ThreadProc(RTTHREAD hSelf, void *pvUser)
    576578{
    577     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     579    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    578580    RT_NOREF_PV(hSelf);
    579581
    580582    /* Try to replace C items from random places. */
    581     for (size_t i = 0; i < MTTESTITEMS; ++i)
     583    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    582584    {
    583585        /* Make sure there is at least one item in the list. */
    584586        while (pTestList->isEmpty())
    585587            RTThreadYield();
    586         pTestList->replace(RTRandU32Ex(0, (uint32_t)pTestList->size() - 1), 0xFF00FF00);
     588        uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
     589        pTestList->replace(idx, 0xFF00FF00);
    587590    }
    588591
     
    598601static DECLCALLBACK(int) MtTest6ThreadProc(RTTHREAD hSelf, void *pvUser)
    599602{
    600     MTTESTLISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;
     603    MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser;
    601604    RT_NOREF_PV(hSelf);
    602605
    603606    /* Try to delete items from random places. */
    604     for (size_t i = 0; i < MTTESTITEMS; ++i)
    605     {
    606         /* Make sure there is at least one item in the list. */
    607         while (pTestList->isEmpty())
     607    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
     608    {
     609        /* Removal is racing thread 4 and 5, so, make sure we don't */
     610        while (pTestList->size() <= MTTEST_ITEMS_NOT_REMOVED)
    608611            RTThreadYield();
    609612        pTestList->removeAt(RTRandU32Ex(0, (uint32_t)pTestList->size() - 1));
     
    620623static void test2()
    621624{
    622     RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTESTITEMS);
    623 
    624     MTTESTLISTTYPE<MTTESTTYPE>  testList;
     625    RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTEST_ITEMS);
     626
     627    MTTEST_LIST_TYPE<MTTEST_TYPE>  testList;
    625628    RTTHREAD                    ahThreads[6];
    626629    static struct CLANG11WEIRDNESS { PFNRTTHREAD pfn; } aThreads[6] =
     
    643646    }
    644647
    645     RTTESTI_CHECK_RETV(testList.size() == MTTESTITEMS * 2);
     648    RTTESTI_CHECK_RETV(testList.size() == MTTEST_ITEMS * 2);
    646649    for (size_t i = 0; i < testList.size(); ++i)
    647650    {
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