VirtualBox

Changeset 25320 in vbox


Ignore:
Timestamp:
Dec 11, 2009 11:03:44 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55899
Message:

tstSupLoadModule: new suplib testcase.

Location:
trunk/src/VBox/HostDrivers/Support/testcase
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk

    r22077 r25320  
    4646        tstGIP-2 \
    4747        tstGetPagingMode \
     48        tstSupLoadModule \
    4849        tstSupSem \
    4950        tstSupSem-Zombie
     
    8788tstGetPagingMode_SOURCES = tstGetPagingMode.cpp
    8889
     90tstSupLoadModule_TEMPLATE = VBOXR3TSTEXE
     91tstSupLoadModule_SOURCES  = tstSupLoadModule.cpp
     92
    8993tstSupSem_TEMPLATE    = VBOXR3TSTEXE
    9094tstSupSem_SOURCES     = tstSupSem.cpp
  • trunk/src/VBox/HostDrivers/Support/testcase/tstSupLoadModule.cpp

    r25307 r25320  
    11/* $Id$ */
    22/** @file
    3  * SUP Testcase - Test the interrupt gate feature of the support library.
     3 * SUP Testcase - Test SUPR3LoadModule.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3434*******************************************************************************/
    3535#include <VBox/sup.h>
    36 #include <VBox/vm.h>
    37 #include <VBox/vmm.h>
    3836#include <VBox/err.h>
    39 #include <VBox/param.h>
     37
     38#include <iprt/getopt.h>
    4039#include <iprt/initterm.h>
     40#include <iprt/mem.h>
     41#include <iprt/message.h>
     42#include <iprt/path.h>
    4143#include <iprt/stream.h>
    4244#include <iprt/string.h>
    43 #include <iprt/alloc.h>
    44 #include <iprt/time.h>
    4545
    4646
     
    7171int main(int argc, char **argv)
    7272{
    73     int rcRet = 0;
    74     int i;
    75     int rc;
    76     int cIterations = argc > 1 ? RTStrToUInt32(argv[1]) : 32;
    77     if (cIterations == 0)
    78         cIterations = 64;
    79 
    8073    /*
    8174     * Init.
    8275     */
    83     RTR3Init();
    84     PSUPDRVSESSION pSession;
    85     rc = SUPR3Init(&pSession);
    86     rcRet += rc != 0;
    87     RTPrintf("tstInt: SUPR3Init -> rc=%Rrc\n", rc);
    88     if (!rc)
     76    int rc = RTR3InitAndSUPLib();
     77    if (RT_FAILURE(rc))
    8978    {
    90         /*
    91          * Load VMM code.
    92          */
    93         char    szFile[RTPATH_MAX];
    94         rc = SUPR3LoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
    95         if (!rc)
     79        RTMsgError("RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
     80        return 1;
     81    }
     82
     83    /*
     84     * Process arguments.
     85     */
     86    static const RTGETOPTDEF s_aOptions[] =
     87    {
     88        { "--help",             'h', 0 }
     89    };
     90
     91    int ch;
     92    RTGETOPTUNION ValueUnion;
     93    RTGETOPTSTATE GetState;
     94    RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
     95    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
     96    {
     97        switch (ch)
    9698        {
    97             /*
    98              * Create a fake 'VM'.
    99              */
    100             PVMR0 pVMR0 = NIL_RTR0PTR;
    101             PVM pVM = NULL;
    102             const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
    103             PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
    104             if (paPages)
    105                 rc = SUPR3LowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
    106             else
    107                 rc = VERR_NO_MEMORY;
    108             if (RT_SUCCESS(rc))
     99            case VINF_GETOPT_NOT_OPTION:
    109100            {
    110                 pVM->pVMRC = 0;
    111                 pVM->pVMR3 = pVM;
    112                 pVM->pVMR0 = pVMR0;
    113                 pVM->paVMPagesR3 = paPages;
    114                 pVM->pSession = pSession;
    115                 pVM->enmVMState = VMSTATE_CREATED;
     101                void *pvImageBase;
     102                rc = SUPR3LoadModule(ValueUnion.psz, RTPathFilename(ValueUnion.psz), &pvImageBase);
     103                if (RT_FAILURE(rc))
     104                {
     105                    RTMsgError("%Rrc when attempting to load '%s'\n", rc, ValueUnion.psz);
     106                    return 1;
     107                }
     108                RTPrintf("Loaded '%s' at %p\n", ValueUnion.psz, pvImageBase);
    116109
    117                 rc = SUPR3SetVMForFastIOCtl(pVMR0);
    118                 if (!rc)
     110                rc = SUPR3FreeModule(pvImageBase);
     111                if (RT_FAILURE(rc))
    119112                {
    120 
    121                     /*
    122                      * Call VMM code with invalid function.
    123                      */
    124                     for (i = cIterations; i > 0; i--)
    125                     {
    126                         rc = SUPR3CallVMMR0(pVMR0, NIL_VMCPUID, VMMR0_DO_SLOW_NOP, NULL);
    127                         if (rc != VINF_SUCCESS)
    128                         {
    129                             RTPrintf("tstInt: SUPR3CallVMMR0 -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
    130                             rcRet++;
    131                             break;
    132                         }
    133                     }
    134                     RTPrintf("tstInt: Performed SUPR3CallVMMR0 %d times (rc=%Rrc)\n", cIterations, rc);
    135 
    136                     /*
    137                      * The fast path.
    138                      */
    139                     if (rc == VINF_SUCCESS)
    140                     {
    141                         RTTimeNanoTS();
    142                         uint64_t StartTS = RTTimeNanoTS();
    143                         uint64_t StartTick = ASMReadTSC();
    144                         uint64_t MinTicks = UINT64_MAX;
    145                         for (i = 0; i < 1000000; i++)
    146                         {
    147                             uint64_t OneStartTick = ASMReadTSC();
    148                             rc = SUPR3CallVMMR0Fast(pVMR0, VMMR0_DO_NOP, 0);
    149                             uint64_t Ticks = ASMReadTSC() - OneStartTick;
    150                             if (Ticks < MinTicks)
    151                                 MinTicks = Ticks;
    152 
    153                             if (RT_UNLIKELY(rc != VINF_SUCCESS))
    154                             {
    155                                 RTPrintf("tstInt: SUPR3CallVMMR0Fast -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
    156                                 rcRet++;
    157                                 break;
    158                             }
    159                         }
    160                         uint64_t Ticks = ASMReadTSC() - StartTick;
    161                         uint64_t NanoSecs = RTTimeNanoTS() - StartTS;
    162 
    163                         RTPrintf("tstInt: SUPR3CallVMMR0Fast - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
    164                                  i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
    165 
    166                         /*
    167                          * The ordinary path.
    168                          */
    169                         RTTimeNanoTS();
    170                         StartTS = RTTimeNanoTS();
    171                         StartTick = ASMReadTSC();
    172                         MinTicks = UINT64_MAX;
    173                         for (i = 0; i < 1000000; i++)
    174                         {
    175                             uint64_t OneStartTick = ASMReadTSC();
    176                             rc = SUPR3CallVMMR0Ex(pVMR0, NIL_VMCPUID, VMMR0_DO_SLOW_NOP, 0, NULL);
    177                             uint64_t OneTicks = ASMReadTSC() - OneStartTick;
    178                             if (OneTicks < MinTicks)
    179                                 MinTicks = OneTicks;
    180 
    181                             if (RT_UNLIKELY(rc != VINF_SUCCESS))
    182                             {
    183                                 RTPrintf("tstInt: SUPR3CallVMMR0Ex -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
    184                                 rcRet++;
    185                                 break;
    186                             }
    187                         }
    188                         Ticks = ASMReadTSC() - StartTick;
    189                         NanoSecs = RTTimeNanoTS() - StartTS;
    190 
    191                         RTPrintf("tstInt: SUPR3CallVMMR0Ex   - %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
    192                                  i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
    193                     }
     113                    RTMsgError("%Rrc when attempting to load '%s'\n", rc, ValueUnion.psz);
     114                    return 1;
    194115                }
    195                 else
    196                 {
    197                     RTPrintf("tstInt: SUPR3SetVMForFastIOCtl failed: %Rrc\n", rc);
    198                     rcRet++;
    199                 }
    200             }
    201             else
    202             {
    203                 RTPrintf("tstInt: SUPR3ContAlloc(%#zx,,) failed\n", sizeof(*pVM));
    204                 rcRet++;
     116                break;
    205117            }
    206118
    207             /*
    208              * Unload VMM.
    209              */
    210             rc = SUPR3UnloadVMM();
    211             if (rc)
    212             {
    213                 RTPrintf("tstInt: SUPR3UnloadVMM failed with rc=%Rrc\n", rc);
    214                 rcRet++;
    215             }
     119            case 'h':
     120                RTPrintf("%s [mod1 [mod2...]]\n");
     121                return 1;
     122
     123            default:
     124                return RTGetOptPrintError(ch, &ValueUnion);
    216125        }
    217         else
    218         {
    219             RTPrintf("tstInt: SUPR3LoadVMM failed with rc=%Rrc\n", rc);
    220             rcRet++;
    221         }
    222 
    223         /*
    224          * Terminate.
    225          */
    226         rc = SUPR3Term(false /*fForced*/);
    227         rcRet += rc != 0;
    228         RTPrintf("tstInt: SUPR3Term -> rc=%Rrc\n", rc);
    229126    }
    230127
    231     return !!rc;
     128    return 0;
    232129}
    233130
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette