VirtualBox

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

Last change on this file since 2471 was 1486, checked in by vboxsync, 18 years ago

build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 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/err.h>
31#include <VBox/param.h>
32#include <iprt/runtime.h>
33#include <iprt/stream.h>
34#include <iprt/string.h>
35
36
37/**
38 * Makes a path to a file in the executable directory.
39 */
40static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
41{
42 char *psz;
43 char *psz2;
44
45 strcpy(pszFile, pszArgv0);
46 psz = strrchr(pszFile, '/');
47 psz2 = strrchr(pszFile, '\\');
48 if (psz < psz2)
49 psz = psz2;
50 if (!psz)
51 psz = strrchr(pszFile, ':');
52 if (!psz)
53 {
54 strcpy(pszFile, "./");
55 psz = &pszFile[1];
56 }
57 strcpy(psz + 1, "VMMR0.r0");
58 return pszFile;
59}
60
61int main(int argc, char **argv)
62{
63 int rcRet = 0;
64 int i;
65 int rc;
66 int cIterations = argc > 1 ? RTStrToUInt32(argv[1]) : 32;
67 if (cIterations == 0)
68 cIterations = 64;
69
70 /*
71 * Init.
72 */
73 RTR3Init();
74 PSUPDRVSESSION pSession;
75 rc = SUPInit(&pSession);
76 rcRet += rc != 0;
77 RTPrintf("tstInt: SUPInit -> rc=%Vrc\n", rc);
78 if (!rc)
79 {
80 /*
81 * Load VMM code.
82 */
83 char szFile[RTPATH_MAX];
84 rc = SUPLoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
85 if (!rc)
86 {
87 /*
88 * Create a fake 'VM'.
89 */
90 PVMR0 pVMR0 = NIL_RTR0PTR;
91 PVM pVM = NULL;
92 const unsigned cPages = RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT;
93 PSUPPAGE paPages = (PSUPPAGE)RTMemAllocZ(cPages * sizeof(SUPPAGE));
94 if (paPages)
95 rc = SUPLowAlloc(cPages, (void **)&pVM, &pVMR0, &paPages[0]);
96 else
97 rc = VERR_NO_MEMORY;
98 if (VBOX_SUCCESS(rc))
99 {
100 pVM->pVMGC = 0;
101 pVM->pVMR3 = pVM;
102 pVM->pVMR0 = pVMR0;
103 pVM->paVMPagesR3 = paPages;
104 pVM->pSession = pSession;
105
106#ifdef VBOX_WITHOUT_IDT_PATCHING
107 rc = SUPSetVMForFastIOCtl(pVMR0);
108#endif
109 if (!rc)
110 {
111
112 /*
113 * Call VMM code with invalid function.
114 */
115 for (i = cIterations; i > 0; i--)
116 {
117 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_NOP, NULL);
118 if (rc != VINF_SUCCESS)
119 {
120 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Vrc i=%d Expected VINF_SUCCESS!\n", rc, i);
121 rcRet++;
122 break;
123 }
124 }
125 RTPrintf("tstInt: Performed SUPCallVMMR0 %d times (rc=%Vrc)\n", cIterations, rc);
126
127 /*
128 * Profile it.
129 */
130 if (!rc)
131 {
132 RTTimeNanoTS();
133 uint64_t StartTS = RTTimeNanoTS();
134 uint64_t StartTick = ASMReadTSC();
135 uint64_t MinTicks = UINT64_MAX;
136 for (i = 0; i < 1000000; i++)
137 {
138 uint64_t OneStartTick = ASMReadTSC();
139 rc = SUPCallVMMR0(pVMR0, VMMR0_DO_NOP, NULL);
140 uint64_t Ticks = ASMReadTSC() - OneStartTick;
141 if (Ticks < MinTicks)
142 MinTicks = Ticks;
143
144 if (RT_UNLIKELY(rc != VINF_SUCCESS))
145 {
146 RTPrintf("tstInt: SUPCallVMMR0 -> rc=%Vrc i=%d Expected VINF_SUCCESS!\n", rc, i);
147 rcRet++;
148 break;
149 }
150 }
151 uint64_t Ticks = ASMReadTSC() - StartTick;
152 uint64_t NanoSecs = RTTimeNanoTS() - StartTS;
153
154 RTPrintf("tstInt: %d iterations in %llu ns / %llu ticks. %llu ns / %#llu ticks per iteration. Min %llu ticks.\n",
155 i, NanoSecs, Ticks, NanoSecs / i, Ticks / i, MinTicks);
156 }
157 }
158 else
159 {
160 RTPrintf("tstInt: SUPSetVMForFastIOCtl failed: %Vrc\n", rc);
161 rcRet++;
162 }
163 }
164 else
165 {
166 RTPrintf("tstInt: SUPContAlloc2(%#zx,,) failed\n", sizeof(*pVM));
167 rcRet++;
168 }
169
170 /*
171 * Unload VMM.
172 */
173 rc = SUPUnloadVMM();
174 if (rc)
175 {
176 RTPrintf("tstInt: SUPUnloadVMM failed with rc=%Vrc\n", rc);
177 rcRet++;
178 }
179 }
180 else
181 {
182 RTPrintf("tstInt: SUPLoadVMM failed with rc=%Vrc\n", rc);
183 rcRet++;
184 }
185
186 /*
187 * Terminate.
188 */
189 rc = SUPTerm();
190 rcRet += rc != 0;
191 RTPrintf("tstInt: SUPTerm -> rc=%Vrc\n", rc);
192 }
193
194 return !!rc;
195}
196
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