VirtualBox

Changeset 41714 in vbox


Ignore:
Timestamp:
Jun 14, 2012 4:12:57 PM (12 years ago)
Author:
vboxsync
Message:

Better testcase...

Location:
trunk/src/VBox/Disassembler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Disassembler/DisasmTest.cpp

    r41690 r41714  
    2020*******************************************************************************/
    2121#include <VBox/dis.h>
     22#include <iprt/test.h>
     23#include <iprt/asm.h>
     24#include <iprt/string.h>
    2225#include <VBox/err.h>
    23 #include <stdio.h>
    24 #include <iprt/string.h>
    25 #include <iprt/asm.h>
    2626
    27 DECLASM(int) TestProc();
     27
     28DECLASM(int) TestProc32(void);
     29char TestProc32_End;
    2830#ifndef RT_OS_OS2
    29 DECLASM(int) TestProc64();
     31DECLASM(int) TestProc64(void);
     32char TestProc64_End;
    3033#endif
    3134//uint8_t aCode16[] = { 0x66, 0x67, 0x89, 0x07 };
    3235
     36static void testDisas(uint8_t const *pabInstrs, size_t cbInstrs, DISCPUMODE enmDisCpuMode)
     37{
     38    for (size_t off = 0; off < cbInstrs; off++)
     39    {
     40        uint32_t const  cErrBefore = RTTestIErrorCount();
     41        uint32_t        cb = 1;
     42        DISCPUSTATE     Cpu;
     43        char            szOutput[256] = {0};
     44        int rc = DISInstrToStr(&pabInstrs[off], enmDisCpuMode, &Cpu, &cb, szOutput, sizeof(szOutput));
     45
     46
     47        RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
     48        RTTESTI_CHECK(cb == Cpu.opsize);
     49        RTTESTI_CHECK(cb > 0);
     50        RTTESTI_CHECK(cb <= 16);
     51        if (cErrBefore != RTTestIErrorCount())
     52            RTTestIFailureDetails("rc=%Rrc, off=%#x (%u) cbInstr=%u enmDisCpuMode=%d",
     53                                  rc, off, Cpu.opsize, enmDisCpuMode);
     54        RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", szOutput);
     55        off += cb;
     56    }
     57
     58}
     59
     60
    3361int main(int argc, char **argv)
    3462{
    35     printf("VBox Disassembler Test\n");
    36     if (argc != 1)
    37     {
    38         //printf("DisasmBlock on printf:\n");
    39         //DisasmBlock((uint8_t *)printf, 256);
    40     }
    41     else
    42     {
    43         uint8_t const *pbInstr = (uint8_t const *)(uintptr_t)TestProc;
     63    RTTEST hTest;
     64    RTEXITCODE rcExit = RTTestInitAndCreate("tstDisasm", &hTest);
     65    if (rcExit)
     66        return rcExit;
     67    RTTestBanner(hTest);
    4468
    45         for (int i=0;i<50;i++)
    46         {
    47             unsigned    cb;
    48             DISCPUSTATE cpu;
    49             char        szOutput[256];
    5069
    51             if (RT_SUCCESS(DISInstrToStr(pbInstr, DISCPUMODE_32BIT, &cpu, &cb, szOutput, sizeof(szOutput))))
    52             {
    53                 printf("%s", szOutput);
    54             }
    55             else
    56             {
    57                 printf("DISOne failed!\n");
    58                 return 1;
    59             }
    60             pbInstr += cb;
    61         }
     70    testDisas((uint8_t const *)(uintptr_t)TestProc32, (uintptr_t)&TestProc32_End - (uintptr_t)TestProc32, DISCPUMODE_32BIT);
     71#ifndef RT_OS_OS2
     72    testDisas((uint8_t const *)(uintptr_t)TestProc64, (uintptr_t)&TestProc64_End - (uintptr_t)TestProc64, DISCPUMODE_64BIT);
     73#endif
    6274
    63 #ifndef RT_OS_OS2
    64         printf("\n64 bits disassembly\n");
    65         pbInstr = (uint8_t const *)(uintptr_t)TestProc64;
    66 
    67 ////__debugbreak();
    68         for (int i=0;i<50;i++)
    69         {
    70             unsigned    cb;
    71             DISCPUSTATE cpu;
    72             char        szOutput[256];
    73 
    74             if (RT_SUCCESS(DISInstrToStr(pbInstr, DISCPUMODE_64BIT, &cpu, &cb, szOutput, sizeof(szOutput))))
    75                 printf("%s", szOutput);
    76             else
    77             {
    78                 printf("DISOne failed!\n");
    79                 return 1;
    80             }
    81             pbInstr += cb;
    82         }
    83 #endif
    84     }
    85     return 0;
     75    return RTTestSummaryAndDestroy(hTest);
    8676}
    8777
  • trunk/src/VBox/Disassembler/DisasmTestA.asm

    r37955 r41714  
    3030
    3131align 16
    32 BEGINPROC   TestProc
     32BEGINPROC   TestProc32
    3333    xor eax, eax
    3434    mov al, 4
     
    8282      pause
    8383
    84 ENDPROC   TestProc
     84ENDPROC   TestProc32
    8585
    8686%ifndef RT_OS_OS2
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