Changeset 93672 in vbox
- Timestamp:
- Feb 10, 2022 1:22:11 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/hardavlrange.h
r93671 r93672 292 292 AVLStack.apidxEntries[RT_ELEMENTS(AVLStack.apidxEntries) - 5], *AVLStack.apidxEntries[RT_ELEMENTS(AVLStack.apidxEntries) - 5]), 293 293 m_cErrors++, VERR_HARDAVL_STACK_OVERFLOW); 294 AVLStack.apidxEntries[cEntries] = pidx DeleteNode;294 AVLStack.apidxEntries[cEntries] = pidxLeftLeast; 295 295 AVLStack.cEntries = cEntries + 1; 296 296 … … 437 437 if (pLeftNode) 438 438 { 439 #if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */ 439 440 AssertCompile(kMaxStack > 6); 441 #endif 440 442 AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries), 441 443 ("%p[%#x] %p %p %p %p %p %p\n", pLeftNode, pNode->idxLeft, apEntries[kMaxStack - 1], … … 469 471 if (pRightNode) 470 472 { 473 #if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */ 471 474 AssertCompile(kMaxStack > 6); 475 #endif 472 476 AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries), 473 477 ("%p[%#x] %p %p %p %p %p %p\n", pRightNode, pNode->idxRight, apEntries[kMaxStack - 1], … … 554 558 if (pLeftNode) 555 559 { 560 #if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */ 556 561 AssertCompile(kMaxStack > 6); 562 #endif 557 563 AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries), 558 564 ("%p[%#x] %p %p %p %p %p %p\n", pLeftNode, pNode->idxLeft, apEntries[kMaxStack - 1], … … 582 588 if (pRightNode) 583 589 { 590 #if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */ 584 591 AssertCompile(kMaxStack > 6); 592 #endif 585 593 AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries), 586 594 ("%p[%#x] %p %p %p %p %p %p\n", pRightNode, pNode->idxRight, apEntries[kMaxStack - 1], -
trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp
r93671 r93672 1045 1045 } 1046 1046 1047 1048 static uint32_t PickClearBit(uint64_t *pbm, uint32_t cItems) 1049 { 1050 uint32_t idx = RTRandU32Ex(0, cItems - 1); 1051 if (ASMBitTest(pbm, idx) == 0) 1052 return idx; 1053 1054 /* Scan forward as we've got code for that already: */ 1055 uint32_t const idxOrg = idx; 1056 idx = ASMBitNextClear(pbm, cItems, idx); 1057 if ((int32_t)idx >= 0) 1058 return idx; 1059 1060 /* Scan backwards bit-by-bit because we don't have code for this: */ 1061 for (idx = idxOrg - 1; idx < cItems; idx--) 1062 if (ASMBitTest(pbm, idx) == 0) 1063 return idx; 1064 1065 AssertFailed(); 1066 RTTestIFailed("no clear bit in bitmap!\n"); 1067 return 0; 1068 } 1069 1070 1071 static uint32_t PickClearBitAndSetIt(uint64_t *pbm, uint32_t cItems) 1072 { 1073 uint32_t idx = PickClearBit(pbm, cItems); 1074 RTTESTI_CHECK(ASMBitTestAndSet(pbm, idx) == false); 1075 return idx; 1076 } 1077 1078 1079 static uint32_t PickSetBit(uint64_t *pbm, uint32_t cItems) 1080 { 1081 uint32_t idx = RTRandU32Ex(0, cItems - 1); 1082 if (ASMBitTest(pbm, idx) == 1) 1083 return idx; 1084 1085 /* Scan forward as we've got code for that already: */ 1086 uint32_t const idxOrg = idx; 1087 idx = ASMBitNextSet(pbm, cItems, idx); 1088 if ((int32_t)idx >= 0) 1089 return idx; 1090 1091 /* Scan backwards bit-by-bit because we don't have code for this: */ 1092 for (idx = idxOrg - 1; idx < cItems; idx--) 1093 if (ASMBitTest(pbm, idx) == 1) 1094 return idx; 1095 1096 AssertFailed(); 1097 RTTestIFailed("no set bit in bitmap!\n"); 1098 return 0; 1099 } 1100 1101 1102 static uint32_t PickSetBitAndClearIt(uint64_t *pbm, uint32_t cItems) 1103 { 1104 uint32_t idx = PickSetBit(pbm, cItems); 1105 RTTESTI_CHECK(ASMBitTestAndSet(pbm, idx) == true); 1106 return idx; 1107 } 1108 1109 1047 1110 /** @return meaningless, just for return RTTestIFailed(); */ 1048 1111 int hardAvlRangeTreeGCPhys(RTTEST hTest) … … 1184 1247 * Randomized stuff. 1185 1248 */ 1186 /** @todo add randomized testing step. Split the address space up into equal 1187 * portition and pick what to insert/remove/lookup using a random 1188 * function against a insertion status bitmap. */ 1249 uint64_t uSeed = RTRandU64(); 1250 RTRandAdvSeed(g_hRand, uSeed); 1251 RTTestIPrintf(RTTESTLVL_ALWAYS, "Random seed: %#RX64\n", uSeed); 1252 1253 RTGCPHYS const cbStep = RTGCPHYS_MAX / cItems + 1; 1254 uint64_t * const pbmPresent = (uint64_t *)RTMemAllocZ(RT_ALIGN_32(cItems, 64) / 64 * 8); 1255 RTTESTI_CHECK_RET(pbmPresent, 1); 1256 1257 /* insert all in random order */ 1258 for (unsigned i = 0; i < cItems; i++) 1259 { 1260 MYTESTNODE *pNode = Allocator.allocateNode(); 1261 if (!pNode) 1262 return RTTestIFailed("out of nodes: i=%#x #3", i); 1263 1264 uint32_t const idx = PickClearBitAndSetIt(pbmPresent, cItems); 1265 pNode->Key = idx * cbStep; 1266 pNode->KeyLast = pNode->Key + cbStep - 1; 1267 int rc = Tree.insert(&Allocator, pNode); 1268 if (rc != VINF_SUCCESS) 1269 RTTestIFailed("random insert failed: %Rrc, i=%#x, idx=%#x (%RGp ... %RGp)", rc, i, idx, pNode->Key, pNode->KeyLast); 1270 1271 MYTESTNODE *pNode2 = (MYTESTNODE *)(intptr_t)i; 1272 rc = Tree.lookup(&Allocator, pNode->Key, &pNode2); 1273 if (rc != VINF_SUCCESS || pNode2 != pNode) 1274 return RTTestIFailed("lookup after random insert %#x: %Rrc pNode=%p pNode2=%p idx=%#x", i, rc, pNode, pNode2, idx); 1275 } 1276 1277 #if 0 /** @todo this doesn't work quit right yet */ 1278 /* remove all in random order. */ 1279 for (unsigned i = 0; i < cItems; i++) 1280 { 1281 uint32_t const idx = PickSetBitAndClearIt(pbmPresent, cItems); 1282 1283 MYTESTNODE *pNode = (MYTESTNODE *)(intptr_t)i; 1284 int rc = Tree.remove(&Allocator, idx * cbStep, &pNode); 1285 if (rc != VINF_SUCCESS) 1286 RTTestIFailed("random remove failed: %Rrc, i=%#x, idx=%#x (%RGp ... %RGp)", 1287 rc, idx, idx * cbStep, idx * cbStep + cbStep - 1); 1288 else if ( pNode->Key != idx * cbStep 1289 || pNode->KeyLast != idx * cbStep + cbStep - 1) 1290 RTTestIFailed("random remove returned wrong node: %RGp ... %RGp, expected %RGp ... %RGp (i=%#x, idx=%#x)", 1291 pNode->Key, pNode->KeyLast, idx * cbStep, idx * cbStep + cbStep - 1, i, idx); 1292 else 1293 { 1294 MYTESTNODE *pNode2 = (MYTESTNODE *)(intptr_t)i; 1295 rc = Tree.lookup(&Allocator, idx * cbStep, &pNode2); 1296 if (rc != VERR_NOT_FOUND) 1297 RTTestIFailed("lookup after random removal %#x: %Rrc pNode=%p pNode2=%p idx=%#x", i, rc, pNode, pNode2, idx); 1298 1299 rc = Allocator.freeNode(pNode); 1300 if (rc != VINF_SUCCESS) 1301 RTTestIFailed("free after random removal %#x failed: %Rrc pNode=%p idx=%#x", i, rc, pNode, idx); 1302 } 1303 } 1304 #endif 1305 1306 /** @todo Add more random stuff here where we pick the operation to perform 1307 * using random as well and just do large number of these iterations. */ 1189 1308 1190 1309 return 0; … … 1214 1333 * Testing. 1215 1334 */ 1335 #if 0 1216 1336 unsigned i; 1217 1337 RTTestSub(hTest, "oGCPhys(32..2048)"); … … 1234 1354 avlrogcphys(); 1235 1355 avlul(); 1356 #endif 1357 1236 1358 hardAvlRangeTreeGCPhys(hTest); 1237 1359
Note:
See TracChangeset
for help on using the changeset viewer.