Changeset 93693 in vbox for trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp
- Timestamp:
- Feb 11, 2022 11:06:35 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp
r93692 r93693 1217 1217 Allocator.initSlabAllocator(cItems, (TESTNODE *)pvItems, (uint64_t *)pbmBitmap); 1218 1218 1219 uint32_t cInserted = 0; 1220 1219 1221 /* 1220 1222 * Simple linear insert, get and remove. 1221 1223 */ 1222 1224 /* insert */ 1223 for (unsigned i = 0; i < cItems * 4; i += 4 )1225 for (unsigned i = 0; i < cItems * 4; i += 4, cInserted++) 1224 1226 { 1225 1227 MYTESTNODE *pNode = Allocator.allocateNode(); … … 1269 1271 return RTTestIFailed("freeNode(pNode2=%p) failed: %Rrc (i=%#x)", pNode2, rc, i); 1270 1272 } 1273 1274 /* check the height */ 1275 uint8_t const cHeight = Tree.getHeight(&Allocator); 1276 uint32_t const cMax = RT_BIT_32(cHeight); 1277 if (cInserted > cMax || cInserted < (cMax >> 4)) 1278 RTTestIFailed("wrong tree height after linear insert i=%#x: cMax=%#x, cInserted=%#x, cHeight=%u\n", 1279 i, cMax, cInserted, cHeight); 1271 1280 } 1272 1281 … … 1308 1317 1309 1318 /* remove */ 1310 for (unsigned i = 0, j = 0; i < cItems * 4; i += 4, j += 3 )1319 for (unsigned i = 0, j = 0; i < cItems * 4; i += 4, j += 3, cInserted--) 1311 1320 { 1312 1321 MYTESTNODE *pNode; … … 1328 1337 return RTTestIFailed("linear negative remove(%#x): %Rrc pNode=%p", k, rc, pNode); 1329 1338 } 1339 1340 /* check the height */ 1341 uint8_t const cHeight = Tree.getHeight(&Allocator); 1342 uint32_t const cMax = RT_BIT_32(cHeight); 1343 if (cInserted > cMax || cInserted < (cMax >> 4)) 1344 RTTestIFailed("wrong tree height after linear remove i=%#x: cMax=%#x, cInserted=%#x cHeight=%d\n", 1345 i, cMax, cInserted, cHeight); 1330 1346 } 1331 1347 … … 1342 1358 1343 1359 /* insert all in random order */ 1360 cInserted = 0; 1344 1361 for (unsigned i = 0; i < cItems; i++) 1345 1362 { … … 1352 1369 pNode->KeyLast = pNode->Key + cbStep - 1; 1353 1370 int rc = Tree.insert(&Allocator, pNode); 1354 if (rc != VINF_SUCCESS) 1371 if (rc == VINF_SUCCESS) 1372 cInserted++; 1373 else 1355 1374 RTTestIFailed("random insert failed: %Rrc, i=%#x, idx=%#x (%RGp ... %RGp)", rc, i, idx, pNode->Key, pNode->KeyLast); 1356 1375 … … 1364 1383 if (rc != VINF_SUCCESS) 1365 1384 RTTestIFailed("enum after random insert %#x: %Rrc idx=%#x", i, rc, idx); 1366 else if (cCount != i + 1) 1367 RTTestIFailed("wrong count after random removal %#x: %#x, expected %#x", i, cCount, i + 1); 1385 else if (cCount != cInserted) 1386 RTTestIFailed("wrong count after random removal %#x: %#x, expected %#x", i, cCount, cInserted); 1387 1388 /* check the height */ 1389 uint8_t const cHeight = Tree.getHeight(&Allocator); 1390 uint32_t const cMax = RT_BIT_32(cHeight); 1391 if (cInserted > cMax || cInserted < (cMax >> 4)) 1392 RTTestIFailed("wrong tree height after random insert %#x: cMax=%#x, cInserted=%#x, cHeight=%u\n", 1393 i, cMax, cInserted, cHeight); 1368 1394 } 1369 1395 … … 1380 1406 else 1381 1407 { 1382 if ( pNode->Key != idx * cbStep 1408 cInserted--; 1409 if ( pNode->Key != idx * cbStep 1383 1410 || pNode->KeyLast != idx * cbStep + cbStep - 1) 1384 1411 RTTestIFailed("random remove returned wrong node: %RGp ... %RGp, expected %RGp ... %RGp (i=%#x, idx=%#x)", … … 1395 1422 if (rc != VINF_SUCCESS) 1396 1423 RTTestIFailed("enum after random removal %#x: %Rrc idx=%#x", i, rc, idx); 1397 else if (cCount != cI tems - i - 1)1398 RTTestIFailed("wrong count after random removal %#x: %#x, expected %#x", i, cCount, cI tems - i - 1);1424 else if (cCount != cInserted) 1425 RTTestIFailed("wrong count after random removal %#x: %#x, expected %#x", i, cCount, cInserted); 1399 1426 } 1400 1427 … … 1403 1430 RTTestIFailed("free after random removal %#x failed: %Rrc pNode=%p idx=%#x", i, rc, pNode, idx); 1404 1431 } 1432 1433 /* check the height */ 1434 uint8_t const cHeight = Tree.getHeight(&Allocator); 1435 uint32_t const cMax = RT_BIT_32(cHeight); 1436 if (cInserted > cMax || cInserted < (cMax >> 4)) 1437 RTTestIFailed("wrong tree height after random removal %#x: cMax=%#x, cInserted=%#x, cHeight=%u\n", 1438 i, cMax, cInserted, cHeight); 1405 1439 } 1406 1440 … … 1411 1445 RTRandAdvSeed(g_hRand, uSeed); 1412 1446 RTTestIPrintf(RTTESTLVL_ALWAYS, "Random seed #2: %#RX64\n", uSeed); 1413 uint32_t cInserted = 0;1414 1447 uint64_t cItemsEnumed = 0; 1415 1448 bool fAdding = true; 1416 1449 uint64_t const nsStart = RTTimeNanoTS(); 1417 1450 unsigned i; 1418 for (i = 0 ; i < _64M; i++)1451 for (i = 0, cInserted = 0; i < _64M; i++) 1419 1452 { 1420 1453 /* The operation. */ … … 1483 1516 else if (cCount != cInserted) 1484 1517 RTTestIFailed("wrong count after random %s: %#x, expected %#x - i=%#x", 1485 cCount, cInserted, fDelete ? "removal" : "insert", i);1518 fDelete ? "removal" : "insert", cCount, cInserted, i); 1486 1519 cItemsEnumed += cCount; 1520 1521 /* check the height */ 1522 uint8_t const cHeight = Tree.getHeight(&Allocator); 1523 uint32_t const cMax = RT_BIT_32(cHeight); 1524 if (cInserted > cMax || cInserted < (cMax >> 4)) 1525 RTTestIFailed("wrong tree height after random %s: cMax=%#x, cInserted=%#x, cHeight=%u - i=%#x\n", 1526 fDelete ? "removal" : "insert", cMax, cInserted, cHeight, i); 1487 1527 1488 1528 /* Check for timeout. */
Note:
See TracChangeset
for help on using the changeset viewer.