VirtualBox

Changeset 93672 in vbox


Ignore:
Timestamp:
Feb 10, 2022 1:22:11 AM (3 years ago)
Author:
vboxsync
Message:

IPRT/hardavl: A fix, a few build fixes and some more tests. bugref:10093

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/hardavlrange.h

    r93671 r93672  
    292292                                     AVLStack.apidxEntries[RT_ELEMENTS(AVLStack.apidxEntries) - 5], *AVLStack.apidxEntries[RT_ELEMENTS(AVLStack.apidxEntries) - 5]),
    293293                                    m_cErrors++, VERR_HARDAVL_STACK_OVERFLOW);
    294                 AVLStack.apidxEntries[cEntries] = pidxDeleteNode;
     294                AVLStack.apidxEntries[cEntries] = pidxLeftLeast;
    295295                AVLStack.cEntries = cEntries + 1;
    296296
     
    437437                    if (pLeftNode)
    438438                    {
     439#if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */
    439440                        AssertCompile(kMaxStack > 6);
     441#endif
    440442                        AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries),
    441443                                            ("%p[%#x] %p %p %p %p %p %p\n", pLeftNode, pNode->idxLeft, apEntries[kMaxStack - 1],
     
    469471                    if (pRightNode)
    470472                    {
     473#if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */
    471474                        AssertCompile(kMaxStack > 6);
     475#endif
    472476                        AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries),
    473477                                            ("%p[%#x] %p %p %p %p %p %p\n", pRightNode, pNode->idxRight, apEntries[kMaxStack - 1],
     
    554558                    if (pLeftNode)
    555559                    {
     560#if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */
    556561                        AssertCompile(kMaxStack > 6);
     562#endif
    557563                        AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries),
    558564                                            ("%p[%#x] %p %p %p %p %p %p\n", pLeftNode, pNode->idxLeft, apEntries[kMaxStack - 1],
     
    582588                    if (pRightNode)
    583589                    {
     590#if RT_GNUC_PREREQ_EX(4,7, 1) /* 32-bit 4.4.7 has trouble, dunno when it started working exactly */
    584591                        AssertCompile(kMaxStack > 6);
     592#endif
    585593                        AssertMsgReturnStmt(cEntries < RT_ELEMENTS(apEntries),
    586594                                            ("%p[%#x] %p %p %p %p %p %p\n", pRightNode, pNode->idxRight, apEntries[kMaxStack - 1],
  • trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp

    r93671 r93672  
    10451045}
    10461046
     1047
     1048static 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
     1071static 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
     1079static 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
     1102static 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
    10471110/** @return meaningless, just for return RTTestIFailed(); */
    10481111int hardAvlRangeTreeGCPhys(RTTEST hTest)
     
    11841247     * Randomized stuff.
    11851248     */
    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. */
    11891308
    11901309    return 0;
     
    12141333     * Testing.
    12151334     */
     1335#if 0
    12161336    unsigned i;
    12171337    RTTestSub(hTest, "oGCPhys(32..2048)");
     
    12341354    avlrogcphys();
    12351355    avlul();
     1356#endif
     1357
    12361358    hardAvlRangeTreeGCPhys(hTest);
    12371359
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