VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstInt.cpp@ 1249

Last change on this file since 1249 was 914, checked in by vboxsync, 18 years ago

PVMR0 changes for darwin.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - Testcases:
4 * Test the interrupt gate feature of the support library
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/sup.h>
28#include <VBox/vm.h>
29#include <VBox/vmm.h>
30#include <VBox/param.h>
31#include <iprt/runtime.h>
32#include <iprt/stream.h>
33#include <iprt/string.h>
34
35
36/**
37 * Makes a path to a file in the executable directory.
38 */
39static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
40{
41 char *psz;
42 char *psz2;
43
44 strcpy(pszFile, pszArgv0);
45 psz = strrchr(pszFile, '/');
46 psz2 = strrchr(pszFile, '\\');
47 if (psz < psz2)
48 psz = psz2;
49 if (!psz)
50 psz = strrchr(pszFile, ':');
51 if (!psz)
52 {
53 strcpy(pszFile, "./");
54 psz = &pszFile[1];
55 }
56 strcpy(psz + 1, "VMMR0.r0");
57 return pszFile;
58}
59
60int main(int argc, char **argv)
61{
62 int rcRet = 0;
63 int i;
64 int rc;
65 int cIterations = argc > 1 ? RTStrToUInt32(argv[1]) : 32;
66 if (cIterations == 0)
67 cIterations = 64;
68
69 /*
70 * Init.
71 */
72 RTR3Init();
73 PSUPDRVSESSION pSession;
74 rc = SUPInit(&pSession);
75 rcRet += rc != 0;
76 RTPrintf("tstInt: SUPInit -> rc=%Vrc\n", rc);
77 if (!rc)
78 {
79 /*
80 * Load VMM code.
81 */
82 char szFile[RTPATH_MAX];
83 rc = SUPLoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
84 if (!rc)
85 {
86 /*
87 * Create a fake 'VM'.
88 */
89 PVMR0 pVMR0;
90 RTHCPHYS HCPhysVM;
91 PVM pVM = (PVM)SUPContAlloc2(sizeof(*pVM), &pVMR0, &HCPhysVM);
92 if (pVM)
93 {
94 pVM->pVMGC = 0;
95 pVM->pVMR3 = pVM;
96 pVM->pVMR0 = pVMR0;
97 pVM->HCPhysVM = HCPhysVM;
98 pVM->pSession = pSession;
99
100#ifdef VBOX_WITHOUT_IDT_PATCHING
101 rc = SUPSetVMForFastIOCtl(pVMR0);
102#endif
103 if (!rc)
104 {
105
106 /*
107 * Call VMM code with invalid function.
108 */
109 for (i = cIterations; i > 0; i--)
110 {
111 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_NOP, NULL);
112 if (rc != VINF_SUCCESS)
113 {
114 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Vrc i=%d Expected VINF_SUCCESS!\n", rc, i);
115 rcRet++;
116 break;
117 }
118 }
119 RTPrintf("tstInt: Performed SUPCallVMMR0 %d times (rc=%Vrc)\n", cIterations, rc);
120
121 /*
122 * Profile it.
123 */
124 if (!rc)
125 {
126 RTTimeNanoTS();
127 uint64_t StartTS = RTTimeNanoTS();
128 uint64_t StartTick = ASMReadTSC();
129 uint64_t MinTicks = UINT64_MAX;
130 for (i = 0; i < 1000000; i++)
131 {
132 uint64_t OneStartTick = ASMReadTSC();
133 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_NOP, NULL);
134 uint64_t Ticks = ASMReadTSC() - OneStartTick;
135 if (Ticks < MinTicks)
136 MinTicks = Ticks;
137
138 if (RT_UNLIKELY(rc != VINF_SUCCESS))
139 {
140 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Vrc i=%d Expected VINF_SUCCESS!\n", rc, i);
141 rcRet++;
142 break;
143 }
144 }
145 uint64_t Ticks = ASMReadTSC() - StartTick;
146 uint64_t NanoSecs = RTTimeNanoTS() - StartTS;
147
148 RTPrintf("tstInt: %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
149 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
150 }
151 }
152 else
153 {
154 RTPrintf("tstInt: SUPSetVMForFastIOCtl failed: %Vrc\n", rc);
155 rcRet++;
156 }
157 }
158 else
159 {
160 RTPrintf("tstInt: SUPContAlloc2(%#zx,,) failed\n", sizeof(*pVM));
161 rcRet++;
162 }
163
164 /*
165 * Unload VMM.
166 */
167 rc = SUPUnloadVMM();
168 if (rc)
169 {
170 RTPrintf("tstInt: SUPUnloadVMM failed with rc=%Vrc\n", rc);
171 rcRet++;
172 }
173 }
174 else
175 {
176 RTPrintf("tstInt: SUPLoadVMM failed with rc=%Vrc\n", rc);
177 rcRet++;
178 }
179
180 /*
181 * Terminate.
182 */
183 rc = SUPTerm();
184 rcRet += rc != 0;
185 RTPrintf("tstInt: SUPTerm -> rc=%Vrc\n", rc);
186 }
187
188 return !!rc;
189}
190
Note: See TracBrowser for help on using the repository browser.

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