VirtualBox

Changeset 22004 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 5, 2009 6:26:53 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50739
Message:

iprt/asm.h: Added ASMMemIsZeroPage.

File:
1 edited

Legend:

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

    r21451 r22004  
    3838#include <iprt/param.h>
    3939#include <iprt/thread.h>
    40 
    41 
    42 /*******************************************************************************
    43 *   Global Variables                                                           *
    44 *******************************************************************************/
    45 /** Global error count. */
    46 static unsigned g_cErrors;
     40#include <iprt/test.h>
     41
    4742
    4843
     
    5550        if ((val) != (expect)) \
    5651        { \
    57             g_cErrors++; \
     52            RTTestIErrorInc(); \
    5853            RTPrintf("%s, %d: " #val ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (expect), (val)); \
    5954        } \
     
    6661        if (val != (type)(expect)) \
    6762        { \
    68             g_cErrors++; \
     63            RTTestIErrorInc(); \
    6964            RTPrintf("%s, %d: " #op ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (type)(expect), val); \
    7065        } \
     
    693688        { \
    694689            RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \
    695             g_cErrors++; \
     690            RTTestIErrorInc(); \
    696691        } \
    697692        if (i32 != (val)) \
    698693        { \
    699694            RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, val); \
    700             g_cErrors++; \
     695            RTTestIErrorInc(); \
    701696        } \
    702697    } while (0)
     
    722717        { \
    723718            RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \
    724             g_cErrors++; \
     719            RTTestIErrorInc(); \
    725720        } \
    726721        if (i32 != (rc)) \
    727722        { \
    728723            RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, rc); \
    729             g_cErrors++; \
     724            RTTestIErrorInc(); \
    730725        } \
    731726    } while (0)
     
    817812    {
    818813        RTPrintf("tstInlineAsm: ASMMemZeroPage violated one/both magic(s)!\n");
    819         g_cErrors++;
     814        RTTestIErrorInc();
    820815    }
    821816    for (unsigned i = 0; i < sizeof(Buf1.abPage); i++)
     
    823818        {
    824819            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
    825             g_cErrors++;
     820            RTTestIErrorInc();
    826821        }
    827822    for (unsigned i = 0; i < sizeof(Buf2.abPage); i++)
     
    829824        {
    830825            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
    831             g_cErrors++;
     826            RTTestIErrorInc();
    832827        }
    833828    for (unsigned i = 0; i < sizeof(Buf3.abPage); i++)
     
    835830        {
    836831            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
    837             g_cErrors++;
     832            RTTestIErrorInc();
    838833        }
     834}
     835
     836
     837void tstASMMemIsZeroPage(RTTEST hTest)
     838{
     839    RTTestSub(hTest, "ASMMemIsZeroPage");
     840
     841    void *pvPage1 = RTTestGuardedAllocHead(hTest, PAGE_SIZE);
     842    void *pvPage2 = RTTestGuardedAllocTail(hTest, PAGE_SIZE);
     843    RTTESTI_CHECK_RETV(pvPage1 && pvPage2);
     844
     845    memset(pvPage1, 0, PAGE_SIZE);
     846    memset(pvPage2, 0, PAGE_SIZE);
     847    RTTESTI_CHECK(ASMMemIsZeroPage(pvPage1));
     848    RTTESTI_CHECK(ASMMemIsZeroPage(pvPage2));
     849
     850    memset(pvPage1, 0xff, PAGE_SIZE);
     851    memset(pvPage2, 0xff, PAGE_SIZE);
     852    RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1));
     853    RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2));
     854
     855    memset(pvPage1, 0, PAGE_SIZE);
     856    memset(pvPage2, 0, PAGE_SIZE);
     857    for (unsigned off = 0; off < PAGE_SIZE; off++)
     858    {
     859        ((uint8_t *)pvPage1)[off] = 1;
     860        RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1));
     861        ((uint8_t *)pvPage1)[off] = 0;
     862
     863        ((uint8_t *)pvPage2)[off] = 0x80;
     864        RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2));
     865        ((uint8_t *)pvPage2)[off] = 0;
     866    }
     867
     868    RTTestSubDone(hTest);
    839869}
    840870
     
    869899    {
    870900        RTPrintf("tstInlineAsm: ASMMemZero32 violated one/both magic(s)!\n");
    871         g_cErrors++;
     901        RTTestIErrorInc();
    872902    }
    873903    for (unsigned i = 0; i < RT_ELEMENTS(Buf1.abPage); i++)
     
    875905        {
    876906            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
    877             g_cErrors++;
     907            RTTestIErrorInc();
    878908        }
    879909    for (unsigned i = 0; i < RT_ELEMENTS(Buf2.abPage); i++)
     
    881911        {
    882912            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
    883             g_cErrors++;
     913            RTTestIErrorInc();
    884914        }
    885915    for (unsigned i = 0; i < RT_ELEMENTS(Buf3.abPage); i++)
     
    887917        {
    888918            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
    889             g_cErrors++;
     919            RTTestIErrorInc();
    890920        }
    891921}
     
    933963    {
    934964        RTPrintf("tstInlineAsm: ASMMemFill32 violated one/both magic(s)!\n");
    935         g_cErrors++;
     965        RTTestIErrorInc();
    936966    }
    937967    for (unsigned i = 0; i < RT_ELEMENTS(Buf1.au32Page); i++)
     
    939969        {
    940970            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf1.au32Page[i], 0xdeadbeef);
    941             g_cErrors++;
     971            RTTestIErrorInc();
    942972        }
    943973    for (unsigned i = 0; i < RT_ELEMENTS(Buf2.au32Page); i++)
     
    945975        {
    946976            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf2.au32Page[i], 0xcafeff01);
    947             g_cErrors++;
     977            RTTestIErrorInc();
    948978        }
    949979    for (unsigned i = 0; i < RT_ELEMENTS(Buf3.au32Page); i++)
     
    951981        {
    952982            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf3.au32Page[i], 0xf00dd00f);
    953             g_cErrors++;
     983            RTTestIErrorInc();
    954984        }
    955985}
     
    11681198int main(int argc, char *argv[])
    11691199{
    1170     RTR3Init();
    1171     RTPrintf("tstInlineAsm: TESTING\n");
     1200    RTTEST hTest;
     1201    int rc = RTTestInitAndCreate("tstInlineAsm", &hTest);
     1202    if (rc)
     1203        return rc;
     1204    RTTestBanner(hTest);
    11721205
    11731206    /*
     
    11911224    tstASMAtomicAndOrU32();
    11921225    tstASMMemZeroPage();
     1226    tstASMMemIsZeroPage(hTest);
    11931227    tstASMMemZero32();
    11941228    tstASMMemFill32();
    11951229    tstASMMath();
    11961230    tstASMByteSwap();
    1197 
    11981231    tstASMBench();
    11991232
     
    12011234     * Show the result.
    12021235     */
    1203     if (!g_cErrors)
    1204         RTPrintf("tstInlineAsm: SUCCESS\n", g_cErrors);
    1205     else
    1206         RTPrintf("tstInlineAsm: FAILURE - %d errors\n", g_cErrors);
    1207     return !!g_cErrors;
    1208 }
    1209 
     1236    return RTTestSummaryAndDestroy(hTest);
     1237}
     1238
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