VirtualBox

Ignore:
Timestamp:
Jan 12, 2021 1:56:20 PM (4 years ago)
Author:
vboxsync
Message:

tstRTInlineAsm: Extending testcase. bugref:9898

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTInlineAsm.cpp

    r87221 r87228  
    9999    } while (0)
    100100
     101/**
     102 * Calls a worker function with different worker variable storage types.
     103 */
     104#define DO_SIMPLE_TEST_NO_SUB_NO_STACK(a_WorkerFunction, type) \
     105    do \
     106    { \
     107        type *pVar = (type *)RTTestGuardedAllocHead(g_hTest, sizeof(type)); \
     108        RTTEST_CHECK_BREAK(g_hTest, pVar); \
     109        a_WorkerFunction(pVar); \
     110        RTTestGuardedFree(g_hTest, pVar); \
     111        \
     112        pVar = (type *)RTTestGuardedAllocTail(g_hTest, sizeof(type)); \
     113        RTTEST_CHECK_BREAK(g_hTest, pVar); \
     114        a_WorkerFunction(pVar); \
     115        RTTestGuardedFree(g_hTest, pVar); \
     116    } while (0)
     117
     118
     119/**
     120 * Calls a worker function with different worker variable storage types.
     121 */
     122#define DO_SIMPLE_TEST_NO_SUB(a_WorkerFunction, type) \
     123    do \
     124    { \
     125        type StackVar; \
     126        a_WorkerFunction(&StackVar); \
     127        DO_SIMPLE_TEST_NO_SUB_NO_STACK(a_WorkerFunction, type); \
     128    } while (0)
    101129
    102130/**
     
    107135    { \
    108136        RTTestISub(#name); \
    109         type StackVar; \
    110         tst ## name ## Worker(&StackVar); \
    111         \
    112         type *pVar = (type *)RTTestGuardedAllocHead(g_hTest, sizeof(type)); \
    113         RTTEST_CHECK_BREAK(g_hTest, pVar); \
    114         tst ## name ## Worker(pVar); \
    115         RTTestGuardedFree(g_hTest, pVar); \
    116         \
    117         pVar = (type *)RTTestGuardedAllocTail(g_hTest, sizeof(type)); \
    118         RTTEST_CHECK_BREAK(g_hTest, pVar); \
    119         tst ## name ## Worker(pVar); \
    120         RTTestGuardedFree(g_hTest, pVar); \
     137        DO_SIMPLE_TEST_NO_SUB(tst ## name ## Worker, type); \
    121138    } while (0)
    122139
     
    21262143            if (pPage->ab[i])
    21272144                RTTestFailed(g_hTest, "ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
     2145        if (ASMMemIsZeroPage(pPage) != true)
     2146            RTTestFailed(g_hTest, "ASMMemIsZeroPage returns false after ASMMemZeroPage!\n");
     2147        if (ASMMemFirstMismatchingU32(pPage, sizeof(pPage), 0) != NULL)
     2148            RTTestFailed(g_hTest, "ASMMemFirstMismatchingU32(,,0) returns non-NULL after ASMMemZeroPage!\n");
    21282149    }
    21292150}
     
    21322153static void tstASMMemZeroPage(void)
    21332154{
    2134     DO_SIMPLE_TEST(ASMMemZeroPage, TSTPAGE);
     2155    RTTestISub("ASMMemZeroPage");
     2156    DO_SIMPLE_TEST_NO_SUB_NO_STACK(tstASMMemZeroPageWorker, TSTPAGE);
    21352157}
    21362158
     
    22932315
    22942316
     2317typedef struct TSTBUF32 { uint32_t au32[384]; } TSTBUF32;
     2318
     2319DECLINLINE(void) tstASMMemZero32Worker(TSTBUF32 *pBuf)
     2320{
     2321    ASMMemZero32(pBuf, sizeof(*pBuf));
     2322    for (unsigned i = 0; i < RT_ELEMENTS(pBuf->au32); i++)
     2323        if (pBuf->au32[i])
     2324            RTTestFailed(g_hTest, "ASMMemZero32 didn't clear dword at index %#x!\n", i);
     2325    if (ASMMemFirstNonZero(pBuf, sizeof(*pBuf)) != NULL)
     2326        RTTestFailed(g_hTest, "ASMMemFirstNonZero return non-NULL after ASMMemZero32\n");
     2327    if (!ASMMemIsZero(pBuf, sizeof(*pBuf)))
     2328        RTTestFailed(g_hTest, "ASMMemIsZero return false after ASMMemZero32\n");
     2329
     2330    memset(pBuf, 0xfe, sizeof(*pBuf));
     2331    ASMMemZero32(pBuf, sizeof(*pBuf));
     2332    for (unsigned i = 0; i < RT_ELEMENTS(pBuf->au32); i++)
     2333        if (pBuf->au32[i])
     2334            RTTestFailed(g_hTest, "ASMMemZero32 didn't clear dword at index %#x!\n", i);
     2335    if (ASMMemFirstNonZero(pBuf, sizeof(*pBuf)) != NULL)
     2336        RTTestFailed(g_hTest, "ASMMemFirstNonZero return non-NULL after ASMMemZero32\n");
     2337    if (!ASMMemIsZero(pBuf, sizeof(*pBuf)))
     2338        RTTestFailed(g_hTest, "ASMMemIsZero return false after ASMMemZero32\n");
     2339}
     2340
     2341
    22952342void tstASMMemZero32(void)
    22962343{
    2297     RTTestSub(g_hTest, "ASMMemFill32");
     2344    RTTestSub(g_hTest, "ASMMemZero32");
    22982345
    22992346    struct
     
    23342381        if (Buf3.abPage[i])
    23352382            RTTestFailed(g_hTest, "ASMMemZero32 didn't clear byte at offset %#x!\n", i);
    2336 }
    2337 
     2383
     2384    DO_SIMPLE_TEST_NO_SUB(tstASMMemZero32Worker, TSTBUF32);
     2385}
     2386
     2387
     2388DECLINLINE(void) tstASMMemFill32Worker(TSTBUF32 *pBuf)
     2389{
     2390    ASMMemFill32(pBuf, sizeof(*pBuf), UINT32_C(0xf629bce1));
     2391    for (unsigned i = 0; i < RT_ELEMENTS(pBuf->au32); i++)
     2392        if (pBuf->au32[i] != UINT32_C(0xf629bce1))
     2393            RTTestFailed(g_hTest, "ASMMemFill32 didn't set dword at index %#x correctly!\n", i);
     2394    if (ASMMemFirstMismatchingU32(pBuf, sizeof(*pBuf), UINT32_C(0xf629bce1)) != NULL)
     2395        RTTestFailed(g_hTest, "ASMMemFirstMismatchingU32(,,UINT32_C(0xf629bce1)) returns non-NULL after ASMMemFill32!\n");
     2396
     2397    memset(pBuf, 0xfe, sizeof(*pBuf));
     2398    ASMMemFill32(pBuf, sizeof(*pBuf), UINT32_C(0x12345678));
     2399    for (unsigned i = 0; i < RT_ELEMENTS(pBuf->au32); i++)
     2400        if (pBuf->au32[i] != UINT32_C(0x12345678))
     2401            RTTestFailed(g_hTest, "ASMMemFill32 didn't set dword at index %#x correctly!\n", i);
     2402    if (ASMMemFirstMismatchingU32(pBuf, sizeof(*pBuf), UINT32_C(0x12345678)) != NULL)
     2403        RTTestFailed(g_hTest, "ASMMemFirstMismatchingU32(,,UINT32_C(0x12345678)) returns non-NULL after ASMMemFill32!\n");
     2404}
    23382405
    23392406void tstASMMemFill32(void)
     
    23882455        if (Buf3.au32Page[i] != 0xf00dd00f)
    23892456            RTTestFailed(g_hTest, "ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf3.au32Page[i], 0xf00dd00f);
     2457
     2458    DO_SIMPLE_TEST_NO_SUB(tstASMMemFill32Worker, TSTBUF32);
     2459}
     2460
     2461
     2462void tstASMProbe(RTTEST hTest)
     2463{
     2464    RTTestSub(hTest, "ASMProbeReadByte/Buffer");
     2465
     2466    uint8_t b = 42;
     2467    RTTESTI_CHECK(ASMProbeReadByte(&b) == 42);
     2468    ASMProbeReadBuffer(&b, sizeof(b));
     2469
     2470    for (uint32_t cPages = 1; cPages < 16; cPages++)
     2471    {
     2472        uint8_t *pbBuf1 = (uint8_t *)RTTestGuardedAllocHead(hTest, cPages * PAGE_SIZE);
     2473        uint8_t *pbBuf2 = (uint8_t *)RTTestGuardedAllocTail(hTest, cPages * PAGE_SIZE);
     2474        RTTESTI_CHECK_RETV(pbBuf1 && pbBuf2);
     2475
     2476        memset(pbBuf1, 0xf6, cPages * PAGE_SIZE);
     2477        memset(pbBuf2, 0x42, cPages * PAGE_SIZE);
     2478
     2479        RTTESTI_CHECK(ASMProbeReadByte(&pbBuf1[cPages * PAGE_SIZE - 1]) == 0xf6);
     2480        RTTESTI_CHECK(ASMProbeReadByte(&pbBuf2[cPages * PAGE_SIZE - 1]) == 0x42);
     2481        RTTESTI_CHECK(ASMProbeReadByte(&pbBuf1[0]) == 0xf6);
     2482        RTTESTI_CHECK(ASMProbeReadByte(&pbBuf2[0]) == 0x42);
     2483
     2484        ASMProbeReadBuffer(pbBuf1, cPages * PAGE_SIZE);
     2485        ASMProbeReadBuffer(pbBuf2, cPages * PAGE_SIZE);
     2486    }
    23902487}
    23912488
     
    25742671    static int64_t  volatile s_i64;
    25752672    unsigned i;
    2576     const unsigned cRounds = _2M;       /* Must be multiple of 8 */
     2673    const unsigned cRounds = _16M;       /* Must be multiple of 8 */
    25772674    uint64_t u64Elapsed;
    25782675
     
    27692866    tstASMMemZero32();
    27702867    tstASMMemFill32();
     2868    tstASMProbe(g_hTest);
    27712869
    27722870    tstASMMisc();
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