VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstVMM.cpp@ 26152

Last change on this file since 26152 was 26152, checked in by vboxsync, 15 years ago

VMM: pdm.h and @copydoc cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1/* $Id: tstVMM.cpp 26152 2010-02-02 16:00:35Z vboxsync $ */
2/** @file
3 * VMM Testcase.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/vm.h>
27#include <VBox/vmm.h>
28#include <VBox/cpum.h>
29#include <VBox/tm.h>
30#include <VBox/pdmapi.h>
31#include <VBox/err.h>
32#include <VBox/log.h>
33#include <iprt/assert.h>
34#include <iprt/initterm.h>
35#include <iprt/semaphore.h>
36#include <iprt/stream.h>
37#include <iprt/test.h>
38#include <iprt/getopt.h>
39#include <iprt/ctype.h>
40#include <iprt/string.h>
41
42
43/*******************************************************************************
44* Defined Constants And Macros *
45*******************************************************************************/
46#define TESTCASE "tstVMM"
47
48
49
50/*******************************************************************************
51* Global Variables *
52*******************************************************************************/
53static uint32_t g_cCpus = 1;
54
55
56/*******************************************************************************
57* Internal Functions *
58*******************************************************************************/
59VMMR3DECL(int) VMMDoTest(PVM pVM); /* Linked into VMM, see ../VMMTests.cpp. */
60
61
62/** Dummy timer callback. */
63static DECLCALLBACK(void) tstTMDummyCallback(PVM pVM, PTMTIMER pTimer, void *pvUser)
64{
65 NOREF(pVM);
66 NOREF(pTimer);
67 NOREF(pvUser);
68}
69
70
71/**
72 * This is called on each EMT and will beat TM.
73 *
74 * @returns VINF_SUCCESS, test failure is reported via RTTEST.
75 * @param pVM The VM handle.
76 * @param hTest The test handle.
77 */
78DECLCALLBACK(int) tstTMWorker(PVM pVM, RTTEST hTest)
79{
80 VMCPUID idCpu = VMMGetCpuId(pVM);
81 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "idCpu=%d STARTING\n", idCpu);
82
83 /*
84 * Create the test set.
85 */
86 int rc;
87 PTMTIMER apTimers[5];
88 for (size_t i = 0; i < RT_ELEMENTS(apTimers); i++)
89 {
90 rc = TMR3TimerCreateInternal(pVM, i & 1 ? TMCLOCK_VIRTUAL : TMCLOCK_VIRTUAL_SYNC,
91 tstTMDummyCallback, NULL, "test timer", &apTimers[i]);
92 RTTEST_CHECK_RET(hTest, RT_SUCCESS(rc), rc);
93 }
94
95 /*
96 * The run loop.
97 */
98 unsigned uPrevPct = 0;
99 uint32_t const cLoops = 100000;
100 for (uint32_t iLoop = 0; iLoop < cLoops; iLoop++)
101 {
102 size_t cLeft = RT_ELEMENTS(apTimers);
103 unsigned i = iLoop % RT_ELEMENTS(apTimers);
104 while (cLeft-- > 0)
105 {
106 PTMTIMER pTimer = apTimers[i];
107
108 if ( cLeft == RT_ELEMENTS(apTimers) / 2
109 && TMTimerIsActive(pTimer))
110 {
111 rc = TMTimerStop(pTimer);
112 RTTEST_CHECK_MSG(hTest, RT_SUCCESS(rc), (hTest, "TMTimerStop: %Rrc\n", rc));
113 }
114 else
115 {
116 rc = TMTimerSetMicro(pTimer, 50 + cLeft);
117 RTTEST_CHECK_MSG(hTest, RT_SUCCESS(rc), (hTest, "TMTimerSetMicro: %Rrc\n", rc));
118 }
119
120 /* next */
121 i = (i + 1) % RT_ELEMENTS(apTimers);
122 }
123
124 if (i % 3)
125 TMR3TimerQueuesDo(pVM);
126
127 /* Progress report. */
128 unsigned uPct = (unsigned)(100.0 * iLoop / cLoops);
129 if (uPct != uPrevPct)
130 {
131 uPrevPct = uPct;
132 if (!(uPct % 10))
133 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "idCpu=%d - %3u%%\n", idCpu, uPct);
134 }
135 }
136
137 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "idCpu=%d DONE\n", idCpu);
138 return 0;
139}
140
141
142/** PDMR3LdrEnumModules callback, see FNPDMR3ENUM. */
143static DECLCALLBACK(int)
144tstVMMLdrEnum(PVM pVM, const char *pszFilename, const char *pszName, RTUINTPTR ImageBase, size_t cbImage, bool fGC, void *pvUser)
145{
146 NOREF(pVM); NOREF(pszFilename); NOREF(fGC); NOREF(pvUser);
147 RTPrintf("tstVMM: %RTptr %s\n", ImageBase, pszName);
148 return VINF_SUCCESS;
149}
150
151static DECLCALLBACK(int)
152tstVMMConfigConstructor(PVM pVM, void *pvUser)
153{
154 int rc = CFGMR3ConstructDefaultTree(pVM);
155 if ( RT_SUCCESS(rc)
156 && g_cCpus > 1)
157 {
158 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
159 CFGMR3RemoveValue(pRoot, "NumCPUs");
160 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", g_cCpus);
161 RTTESTI_CHECK_MSG_RET(RT_SUCCESS(rc), ("CFGMR3InsertInteger(pRoot,\"NumCPUs\",) -> %Rrc\n", rc), rc);
162
163 CFGMR3RemoveValue(pRoot, "HwVirtExtForced");
164 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", true);
165 RTTESTI_CHECK_MSG_RET(RT_SUCCESS(rc), ("CFGMR3InsertInteger(pRoot,\"HwVirtExtForced\",) -> %Rrc\n", rc), rc);
166
167 PCFGMNODE pHwVirtExt = CFGMR3GetChild(pRoot, "HWVirtExt");
168 CFGMR3RemoveNode(pHwVirtExt);
169 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHwVirtExt);
170 RTTESTI_CHECK_MSG_RET(RT_SUCCESS(rc), ("CFGMR3InsertNode(pRoot,\"HWVirtExt\",) -> %Rrc\n", rc), rc);
171 rc = CFGMR3InsertInteger(pHwVirtExt, "Enabled", true);
172 RTTESTI_CHECK_MSG_RET(RT_SUCCESS(rc), ("CFGMR3InsertInteger(pHwVirtExt,\"Enabled\",) -> %Rrc\n", rc), rc);
173 rc = CFGMR3InsertInteger(pHwVirtExt, "64bitEnabled", false);
174 RTTESTI_CHECK_MSG_RET(RT_SUCCESS(rc), ("CFGMR3InsertInteger(pHwVirtExt,\"64bitEnabled\",) -> %Rrc\n", rc), rc);
175 }
176 return rc;
177}
178
179
180int main(int argc, char **argv)
181{
182 /*
183 * Init runtime and the test environment.
184 */
185 int rc = RTR3InitAndSUPLib();
186 if (RT_FAILURE(rc))
187 {
188 RTPrintf("tstVMM: RTR3InitAndSUPLib failed: %Rrc\n", rc);
189 return 1;
190 }
191 RTTEST hTest;
192 rc = RTTestCreate("tstVMM", &hTest);
193 if (RT_FAILURE(rc))
194 {
195 RTPrintf("tstVMM: RTTestCreate failed: %Rrc\n", rc);
196 return 1;
197 }
198
199 /*
200 * Parse arguments.
201 */
202 static const RTGETOPTDEF s_aOptions[] =
203 {
204 { "--cpus", 'c', RTGETOPT_REQ_UINT8 },
205 { "--test", 't', RTGETOPT_REQ_STRING },
206 { "--help", 'h', 0 },
207 };
208 enum
209 {
210 kTstVMMTest_VMM, kTstVMMTest_TM
211 } enmTestOpt = kTstVMMTest_VMM;
212
213 int ch;
214 int i = 1;
215 RTGETOPTUNION ValueUnion;
216 RTGETOPTSTATE GetState;
217 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
218 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
219 {
220 switch (ch)
221 {
222 case 'c':
223 g_cCpus = ValueUnion.u8;
224 break;
225
226 case 't':
227 if (!strcmp("vmm", ValueUnion.psz))
228 enmTestOpt = kTstVMMTest_VMM;
229 else if (!strcmp("tm", ValueUnion.psz))
230 enmTestOpt = kTstVMMTest_TM;
231 else
232 {
233 RTPrintf("tstVMM: unknown test: '%s'\n", ValueUnion.psz);
234 return 1;
235 }
236 break;
237
238 case 'h':
239 RTPrintf("usage: tstVMM [--cpus|-c cpus] [--test <vmm|tm>]\n");
240 return 1;
241
242 case VINF_GETOPT_NOT_OPTION:
243 RTPrintf("tstVMM: syntax error: non option '%s'\n", ValueUnion.psz);
244 break;
245
246 default:
247 if (ch > 0)
248 {
249 if (RT_C_IS_GRAPH(ch))
250 RTPrintf("tstVMM: unhandled option: -%c\n", ch);
251 else
252 RTPrintf("tstVMM: unhandled option: %i\n", ch);
253 }
254 else if (ch == VERR_GETOPT_UNKNOWN_OPTION)
255 RTPrintf("tstVMM: unknown option: %s\n", ValueUnion.psz);
256 else if (ValueUnion.pDef)
257 RTPrintf("tstVMM: %s: %Rrs\n", ValueUnion.pDef->pszLong, ch);
258 else
259 RTPrintf("tstVMM: %Rrs\n", ch);
260 return 1;
261 }
262 }
263
264 /*
265 * Create the test VM.
266 */
267 RTPrintf(TESTCASE ": Initializing...\n");
268 PVM pVM;
269 rc = VMR3Create(g_cCpus, NULL, NULL, tstVMMConfigConstructor, NULL, &pVM);
270 if (RT_SUCCESS(rc))
271 {
272 PDMR3LdrEnumModules(pVM, tstVMMLdrEnum, NULL);
273 RTStrmFlush(g_pStdOut);
274 RTThreadSleep(256);
275
276 /*
277 * Do the requested testing.
278 */
279 switch (enmTestOpt)
280 {
281 case kTstVMMTest_VMM:
282 {
283 RTTestSub(hTest, "VMM");
284 rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)VMMDoTest, 1, pVM);
285 if (RT_FAILURE(rc))
286 RTTestFailed(hTest, "VMMDoTest failed: rc=%Rrc\n", rc);
287 break;
288 }
289
290 case kTstVMMTest_TM:
291 {
292 RTTestSub(hTest, "TM");
293 for (VMCPUID idCpu = 1; idCpu < g_cCpus; idCpu++)
294 {
295 rc = VMR3ReqCallNoWaitU(pVM->pUVM, idCpu, (PFNRT)tstTMWorker, 2, pVM, hTest);
296 if (RT_FAILURE(rc))
297 RTTestFailed(hTest, "VMR3ReqCall failed: rc=%Rrc\n", rc);
298 }
299
300 rc = VMR3ReqCallWait(pVM, 0 /*idDstCpu*/, (PFNRT)tstTMWorker, 2, pVM, hTest);
301 if (RT_FAILURE(rc))
302 RTTestFailed(hTest, "VMMDoTest failed: rc=%Rrc\n", rc);
303 break;
304 }
305 }
306
307 STAMR3Dump(pVM, "*");
308
309 /*
310 * Cleanup.
311 */
312 rc = VMR3Destroy(pVM);
313 if (RT_FAILURE(rc))
314 RTTestFailed(hTest, "VMR3Destroy failed: rc=%Rrc\n", rc);
315 }
316 else
317 RTTestFailed(hTest, "VMR3Create failed: rc=%Rrc\n", rc);
318
319 return RTTestSummaryAndDestroy(hTest);
320}
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