Changeset 93691 in vbox for trunk/src/VBox
- Timestamp:
- Feb 11, 2022 10:10:12 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp
r93684 r93691 37 37 #include <iprt/rand.h> 38 38 #include <iprt/stdarg.h> 39 #include <iprt/stream.h> 39 40 #include <iprt/string.h> 40 41 #include <iprt/test.h> … … 75 76 static PTRACKER TrackerCreate(uint32_t MaxKey) 76 77 { 77 uint32_t cbBitmap = (MaxKey + sizeof(uint32_t) * sizeof(uint8_t) - 1) / sizeof(uint8_t);78 uint32_t cbBitmap = RT_ALIGN_32(MaxKey, 64) / 8; 78 79 PTRACKER pTracker = (PTRACKER)RTMemAllocZ(RT_UOFFSETOF_DYN(TRACKER, abBitmap[cbBitmap])); 79 80 if (pTracker) … … 254 255 { 255 256 /* we're missing a ASMBitPrevSet function, so here's a quick replacement hack. */ 256 uint32_t *pu32Start = (uint32_t *)&pTracker->abBitmap[0]; 257 uint32_t *pu32Cur = (uint32_t *)&pTracker->abBitmap[Key >> 8]; 258 while (pu32Cur >= pu32Start) 259 { 260 if (*pu32Cur) 257 uint32_t const *pu32Bitmap = (uint32_t const *)&pTracker->abBitmap[0]; 258 Key >>= 5; 259 do 260 { 261 uint32_t u32; 262 if ((u32 = pu32Bitmap[Key]) != 0) 261 263 { 262 *pKey = ASMBitLastSetU32( *pu32Cur) - 1 + (uint32_t)((pu32Cur - pu32Start) * 32);264 *pKey = ASMBitLastSetU32(u32) - 1 + (Key << 5); 263 265 return true; 264 266 } 265 pu32Cur--;266 } 267 } while (Key-- > 0); 268 267 269 Key2 = ASMBitFirstSet(pTracker->abBitmap, pTracker->MaxKey); 268 270 if (Key2 == -1) … … 277 279 *pKey = Key; 278 280 return true; 281 } 282 283 284 /** 285 * Gets the number of keys in the tree. 286 */ 287 static uint32_t TrackerGetCount(PTRACKER pTracker) 288 { 289 return pTracker->cSetBits; 279 290 } 280 291 … … 538 549 539 550 540 int avlogcphysRand(unsigned cMax, unsigned cMax2) 551 static DECLCALLBACK(int) avlogcphysCallbackCounter(PAVLOGCPHYSNODECORE pNode, void *pvUser) 552 { 553 RT_NOREF(pNode); 554 *(uint32_t *)pvUser += 1; 555 return 0; 556 } 557 558 int avlogcphysRand(unsigned cMax, unsigned cMax2, uint32_t fCountMask) 541 559 { 542 560 PAVLOGCPHYSTREE pTree = (PAVLOGCPHYSTREE)RTMemAllocZ(sizeof(*pTree)); … … 581 599 } 582 600 TrackerInsert(pTracker, Key, Key); 601 602 if (!(i & fCountMask)) 603 { 604 uint32_t cCount = 0; 605 RTAvloGCPhysDoWithAll(pTree, i & 1, avlogcphysCallbackCounter, &cCount); 606 if (cCount != TrackerGetCount(pTracker)) 607 RTTestIFailed("wrong tree count after random insert i=%d: %u, expected %u", i, cCount, TrackerGetCount(pTracker)); 608 } 609 } 610 611 { 612 uint32_t cCount = 0; 613 RTAvloGCPhysDoWithAll(pTree, i & 1, avlogcphysCallbackCounter, &cCount); 614 if (cCount != TrackerGetCount(pTracker)) 615 RTTestIFailed("wrong tree count after random insert i=%d: %u, expected %u", i, cCount, TrackerGetCount(pTracker)); 583 616 } 584 617 … … 611 644 memset(pNode, 0xdd, sizeof(*pNode)); 612 645 RTMemFree(pNode); 646 647 if (!(i & fCountMask)) 648 { 649 uint32_t cCount = 0; 650 RTAvloGCPhysDoWithAll(pTree, i & 1, avlogcphysCallbackCounter, &cCount); 651 if (cCount != TrackerGetCount(pTracker)) 652 RTTestIFailed("wrong tree count after random remove i=%d: %u, expected %u", i, cCount, TrackerGetCount(pTracker)); 653 } 654 } 655 { 656 uint32_t cCount = 0; 657 RTAvloGCPhysDoWithAll(pTree, i & 1, avlogcphysCallbackCounter, &cCount); 658 if (cCount != TrackerGetCount(pTracker)) 659 RTTestIFailed("wrong tree count after random insert i=%d: %u, expected %u", i, cCount, TrackerGetCount(pTracker)); 613 660 } 614 661 if (*pTree) … … 937 984 */ 938 985 PAVLULNODECORE pTree = 0; 939 unsigned i; 986 unsigned cInserted = 0; 987 unsigned i; 988 940 989 /* insert */ 941 for (i = 0; i < 65536; i++ )990 for (i = 0; i < 65536; i++, cInserted++) 942 991 { 943 992 PAVLULNODECORE pNode = (PAVLULNODECORE)RTMemAlloc(sizeof(*pNode)); … … 948 997 return 1; 949 998 } 999 950 1000 /* negative. */ 951 1001 AVLULNODECORE Node = *pNode; … … 955 1005 return 1; 956 1006 } 957 } 958 959 for (i = 0; i < 65536; i++) 1007 1008 /* check height */ 1009 uint8_t const cHeight = pTree ? pTree->uchHeight : 0; 1010 uint32_t const cMax = cHeight > 0 ? RT_BIT_32(cHeight) : 1; 1011 if (cInserted > cMax || cInserted < (cMax >> 2)) 1012 RTTestIFailed("bad tree height after linear insert i=%d: cMax=%#x, cInserted=%#x\n", i, cMax, cInserted); 1013 } 1014 1015 for (i = 0; i < 65536; i++, cInserted--) 960 1016 { 961 1017 PAVLULNODECORE pNode = RTAvlULRemove(&pTree, i); … … 977 1033 return 1; 978 1034 } 1035 1036 /* check height */ 1037 uint8_t const cHeight = pTree ? pTree->uchHeight : 0; 1038 uint32_t const cMax = cHeight > 0 ? RT_BIT_32(cHeight) : 1; 1039 if (cInserted > cMax || cInserted < (cMax >> 2)) 1040 RTTestIFailed("bad tree height after linear removal i=%d: cMax=%#x, cInserted=%#x\n", i, cMax, cInserted); 979 1041 } 980 1042 … … 982 1044 * Make a sparsely populated tree. 983 1045 */ 984 for (i = 0; i < 65536; i += 8 )1046 for (i = 0; i < 65536; i += 8, cInserted++) 985 1047 { 986 1048 PAVLULNODECORE pNode = (PAVLULNODECORE)RTMemAlloc(sizeof(*pNode)); … … 991 1053 return 1; 992 1054 } 1055 993 1056 /* negative. */ 994 1057 AVLULNODECORE Node = *pNode; … … 998 1061 return 1; 999 1062 } 1063 1064 /* check height */ 1065 uint8_t const cHeight = pTree ? pTree->uchHeight : 0; 1066 uint32_t const cMax = cHeight > 0 ? RT_BIT_32(cHeight) : 1; 1067 if (cInserted > cMax || cInserted < (cMax >> 2)) 1068 RTTestIFailed("bad tree height after sparse insert i=%d: cMax=%#x, cInserted=%#x\n", i, cMax, cInserted); 1000 1069 } 1001 1070 … … 1006 1075 for (j = 0; j < 4; j++) 1007 1076 { 1008 for (i = 0; i < 65536; i += 8 * 4 )1077 for (i = 0; i < 65536; i += 8 * 4, cInserted--) 1009 1078 { 1010 1079 PAVLULNODECORE pNode = RTAvlULRemoveBestFit(&pTree, i, true); … … 1019 1088 pNode->uchHeight = 'E'; 1020 1089 RTMemFree(pNode); 1090 1091 /* check height */ 1092 uint8_t const cHeight = pTree ? pTree->uchHeight : 0; 1093 uint32_t const cMax = cHeight > 0 ? RT_BIT_32(cHeight) : 1; 1094 if (cInserted > cMax || cInserted < (cMax >> 2)) 1095 RTTestIFailed("bad tree height after sparse removal i=%d: cMax=%#x, cInserted=%#x\n", i, cMax, cInserted); 1021 1096 } 1022 1097 } … … 1445 1520 * Testing. 1446 1521 */ 1522 #if 0 1447 1523 unsigned i; 1448 1524 RTTestSub(hTest, "oGCPhys(32..2048)"); … … 1457 1533 RTTestISubF("oGCPhys(32..2048, *1K)"); 1458 1534 for (i = 32; i < 4096; i++) 1459 if (avlogcphysRand(i, i + _1K ))1535 if (avlogcphysRand(i, i + _1K, 0xff)) 1460 1536 break; 1461 1537 for (; i <= _4M; i *= 2) 1462 if (avlogcphysRand(i, i * 8 ))1538 if (avlogcphysRand(i, i * 8, i * 2 - 1)) 1463 1539 break; 1464 1540 1465 1541 avlrogcphys(); 1542 #endif 1466 1543 avlul(); 1467 1544
Note:
See TracChangeset
for help on using the changeset viewer.