VirtualBox

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

Last change on this file since 19255 was 19255, checked in by vboxsync, 16 years ago

Backed out 46655-57 for now

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/** $Id: tstInt.cpp 19255 2009-04-29 10:14:59Z vboxsync $ */
2/** @file
3 * Testcase: Test the interrupt gate feature of the support library.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <VBox/sup.h>
36#include <VBox/vm.h>
37#include <VBox/vmm.h>
38#include <VBox/err.h>
39#include <VBox/param.h>
40#include <iprt/initterm.h>
41#include <iprt/stream.h>
42#include <iprt/string.h>
43#include <iprt/alloc.h>
44#include <iprt/time.h>
45
46
47/**
48 * Makes a path to a file in the executable directory.
49 */
50static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
51{
52 char *psz;
53 char *psz2;
54
55 strcpy(pszFile, pszArgv0);
56 psz = strrchr(pszFile, '/');
57 psz2 = strrchr(pszFile, '\\');
58 if (psz < psz2)
59 psz = psz2;
60 if (!psz)
61 psz = strrchr(pszFile, ':');
62 if (!psz)
63 {
64 strcpy(pszFile, "./");
65 psz = &pszFile[1];
66 }
67 strcpy(psz + 1, "VMMR0.r0");
68 return pszFile;
69}
70
71int main(int argc, char **argv)
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 /*
81 * Init.
82 */
83 RTR3Init();
84 PSUPDRVSESSION pSession;
85 rc = SUPR3Init(&pSession);
86 rcRet += rc != 0;
87 RTPrintf("tstInt: SUPR3Init -> rc=%Rrc\n", rc);
88 if (!rc)
89 {
90 /*
91 * Load VMM code.
92 */
93 char szFile[RTPATH_MAX];
94 rc = SUPLoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
95 if (!rc)
96 {
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 = SUPLowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
106 else
107 rc = VERR_NO_MEMORY;
108 if (RT_SUCCESS(rc))
109 {
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;
116
117 rc = SUPSetVMForFastIOCtl(pVMR0);
118 if (!rc)
119 {
120
121 /*
122 * Call VMM code with invalid function.
123 */
124 for (i = cIterations; i > 0; i--)
125 {
126 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_SLOW_NOP, NULL);
127 if (rc != VINF_SUCCESS)
128 {
129 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Rrc i=%d Expected VINF_SUCCESS!\n", rc, i);
130 rcRet++;
131 break;
132 }
133 }
134 RTPrintf("tstInt: Performed SUPCallVMMR0 %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 = SUPCallVMMR0Fast(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: SUPCallVMMR0Fast -> 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: SUPCallVMMR0Fast - %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 = SUPCallVMMR0Ex(pVMR0, VMMR0_DO_SLOW_NOP, 0, NULL);
177 uint64_t Ticks = ASMReadTSC() - OneStartTick;
178 if (Ticks < MinTicks)
179 MinTicks = Ticks;
180
181 if (RT_UNLIKELY(rc != VINF_SUCCESS))
182 {
183 RTPrintf("tstInt: SUPCallVMMR0Ex -> 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: SUPCallVMMR0Ex - %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 }
194 }
195 else
196 {
197 RTPrintf("tstInt: SUPSetVMForFastIOCtl failed: %Rrc\n", rc);
198 rcRet++;
199 }
200 }
201 else
202 {
203 RTPrintf("tstInt: SUPContAlloc2(%#zx,,) failed\n", sizeof(*pVM));
204 rcRet++;
205 }
206
207 /*
208 * Unload VMM.
209 */
210 rc = SUPUnloadVMM();
211 if (rc)
212 {
213 RTPrintf("tstInt: SUPUnloadVMM failed with rc=%Rrc\n", rc);
214 rcRet++;
215 }
216 }
217 else
218 {
219 RTPrintf("tstInt: SUPLoadVMM failed with rc=%Rrc\n", rc);
220 rcRet++;
221 }
222
223 /*
224 * Terminate.
225 */
226 rc = SUPTerm();
227 rcRet += rc != 0;
228 RTPrintf("tstInt: SUPTerm -> rc=%Rrc\n", rc);
229 }
230
231 return !!rc;
232}
233
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