Changeset 86618 in vbox for trunk/src/VBox
- Timestamp:
- Oct 16, 2020 11:09:41 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstIprtList.cpp
r85166 r86618 485 485 /* define RTCList here to see what happens without MT support ;) 486 486 * (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 490 491 491 492 /** … … 497 498 static DECLCALLBACK(int) MtTest1ThreadProc(RTTHREAD hSelf, void *pvUser) 498 499 { 499 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;500 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 500 501 RT_NOREF_PV(hSelf); 501 502 502 503 /* Prepend new items at the start of the list. */ 503 for (size_t i = 0; i < MTTEST ITEMS; ++i)504 for (size_t i = 0; i < MTTEST_ITEMS; ++i) 504 505 pTestList->prepend(0x0); 505 506 … … 515 516 static DECLCALLBACK(int) MtTest2ThreadProc(RTTHREAD hSelf, void *pvUser) 516 517 { 517 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;518 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 518 519 RT_NOREF_PV(hSelf); 519 520 520 521 /* Append new items at the end of the list. */ 521 for (size_t i = 0; i < MTTEST ITEMS; ++i)522 for (size_t i = 0; i < MTTEST_ITEMS; ++i) 522 523 pTestList->append(0xFFFFFFFF); 523 524 … … 533 534 static DECLCALLBACK(int) MtTest3ThreadProc(RTTHREAD hSelf, void *pvUser) 534 535 { 535 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;536 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 536 537 RT_NOREF_PV(hSelf); 537 538 538 539 /* Insert new items in the middle of the list. */ 539 for (size_t i = 0; i < MTTEST ITEMS; ++i)540 for (size_t i = 0; i < MTTEST_ITEMS; ++i) 540 541 pTestList->insert(pTestList->size() / 2, 0xF0F0F0F0); 541 542 … … 551 552 static DECLCALLBACK(int) MtTest4ThreadProc(RTTHREAD hSelf, void *pvUser) 552 553 { 553 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;554 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 554 555 RT_NOREF_PV(hSelf); 555 556 556 MTTEST TYPE a;557 MTTEST_TYPE a; 557 558 /* Try to read C items from random places. */ 558 for (size_t i = 0; i < MTTEST ITEMS; ++i)559 for (size_t i = 0; i < MTTEST_ITEMS; ++i) 559 560 { 560 561 /* Make sure there is at least one item in the list. */ 561 562 while (pTestList->isEmpty()) 562 563 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); 564 566 } 565 567 … … 575 577 static DECLCALLBACK(int) MtTest5ThreadProc(RTTHREAD hSelf, void *pvUser) 576 578 { 577 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;579 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 578 580 RT_NOREF_PV(hSelf); 579 581 580 582 /* Try to replace C items from random places. */ 581 for (size_t i = 0; i < MTTEST ITEMS; ++i)583 for (size_t i = 0; i < MTTEST_ITEMS; ++i) 582 584 { 583 585 /* Make sure there is at least one item in the list. */ 584 586 while (pTestList->isEmpty()) 585 587 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); 587 590 } 588 591 … … 598 601 static DECLCALLBACK(int) MtTest6ThreadProc(RTTHREAD hSelf, void *pvUser) 599 602 { 600 MTTEST LISTTYPE<MTTESTTYPE> *pTestList = (MTTESTLISTTYPE<MTTESTTYPE> *)pvUser;603 MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList = (MTTEST_LIST_TYPE<MTTEST_TYPE> *)pvUser; 601 604 RT_NOREF_PV(hSelf); 602 605 603 606 /* Try to delete items from random places. */ 604 for (size_t i = 0; i < MTTEST ITEMS; ++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) 608 611 RTThreadYield(); 609 612 pTestList->removeAt(RTRandU32Ex(0, (uint32_t)pTestList->size() - 1)); … … 620 623 static void test2() 621 624 { 622 RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTEST ITEMS);623 624 MTTEST LISTTYPE<MTTESTTYPE> testList;625 RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTEST_ITEMS); 626 627 MTTEST_LIST_TYPE<MTTEST_TYPE> testList; 625 628 RTTHREAD ahThreads[6]; 626 629 static struct CLANG11WEIRDNESS { PFNRTTHREAD pfn; } aThreads[6] = … … 643 646 } 644 647 645 RTTESTI_CHECK_RETV(testList.size() == MTTEST ITEMS * 2);648 RTTESTI_CHECK_RETV(testList.size() == MTTEST_ITEMS * 2); 646 649 for (size_t i = 0; i < testList.size(); ++i) 647 650 {
Note:
See TracChangeset
for help on using the changeset viewer.