Changeset 25320 in vbox
- Timestamp:
- Dec 11, 2009 11:03:44 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 55899
- 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 46 46 tstGIP-2 \ 47 47 tstGetPagingMode \ 48 tstSupLoadModule \ 48 49 tstSupSem \ 49 50 tstSupSem-Zombie … … 87 88 tstGetPagingMode_SOURCES = tstGetPagingMode.cpp 88 89 90 tstSupLoadModule_TEMPLATE = VBOXR3TSTEXE 91 tstSupLoadModule_SOURCES = tstSupLoadModule.cpp 92 89 93 tstSupSem_TEMPLATE = VBOXR3TSTEXE 90 94 tstSupSem_SOURCES = tstSupSem.cpp -
trunk/src/VBox/HostDrivers/Support/testcase/tstSupLoadModule.cpp
r25307 r25320 1 1 /* $Id$ */ 2 2 /** @file 3 * SUP Testcase - Test the interrupt gate feature of the support library.3 * SUP Testcase - Test SUPR3LoadModule. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 *******************************************************************************/ 35 35 #include <VBox/sup.h> 36 #include <VBox/vm.h>37 #include <VBox/vmm.h>38 36 #include <VBox/err.h> 39 #include <VBox/param.h> 37 38 #include <iprt/getopt.h> 40 39 #include <iprt/initterm.h> 40 #include <iprt/mem.h> 41 #include <iprt/message.h> 42 #include <iprt/path.h> 41 43 #include <iprt/stream.h> 42 44 #include <iprt/string.h> 43 #include <iprt/alloc.h>44 #include <iprt/time.h>45 45 46 46 … … 71 71 int main(int argc, char **argv) 72 72 { 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 80 73 /* 81 74 * Init. 82 75 */ 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)) 89 78 { 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) 96 98 { 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: 109 100 { 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); 116 109 117 rc = SUPR3 SetVMForFastIOCtl(pVMR0);118 if ( !rc)110 rc = SUPR3FreeModule(pvImageBase); 111 if (RT_FAILURE(rc)) 119 112 { 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; 194 115 } 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; 205 117 } 206 118 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); 216 125 } 217 else218 {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);229 126 } 230 127 231 return !!rc;128 return 0; 232 129 } 233 130
Note:
See TracChangeset
for help on using the changeset viewer.