VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstVMREQ.cpp@ 3723

Last change on this file since 3723 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1/* $Id: tstVMREQ.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * VMM Testcase.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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/err.h>
30#include <VBox/log.h>
31#include <iprt/assert.h>
32#include <iprt/runtime.h>
33#include <iprt/semaphore.h>
34#include <iprt/stream.h>
35#include <iprt/thread.h>
36#include <iprt/time.h>
37
38
39
40
41/*******************************************************************************
42* Defined Constants And Macros *
43*******************************************************************************/
44#define TESTCASE "tstVMREQ"
45
46/**
47 * Thread function which allocates and frees requests like wildfire.
48 */
49DECLCALLBACK(int) Thread(RTTHREAD Thread, void *pvUser)
50{
51 int rc = VINF_SUCCESS;
52 PVM pVM = (PVM)pvUser;
53 for (unsigned i = 0; i < 100000; i++)
54 {
55 PVMREQ apReq[17];
56 const unsigned cReqs = i % ELEMENTS(apReq);
57 unsigned iReq;
58 for (iReq = 0; iReq < cReqs; iReq++)
59 {
60 rc = VMR3ReqAlloc(pVM, &apReq[iReq], VMREQTYPE_INTERNAL);
61 if (VBOX_FAILURE(rc))
62 {
63 RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d rc=%Vrc (alloc)\n", i, iReq, cReqs, rc);
64 return rc;
65 }
66 apReq[iReq]->iStatus = iReq + i;
67 }
68
69 for (iReq = 0; iReq < cReqs; iReq++)
70 {
71 if (apReq[iReq]->iStatus != (int)(iReq + i))
72 {
73 RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d: iStatus=%d != %d\n", i, iReq, cReqs, apReq[iReq]->iStatus, iReq + i);
74 return VERR_GENERAL_FAILURE;
75 }
76 rc = VMR3ReqFree(apReq[iReq]);
77 if (VBOX_FAILURE(rc))
78 {
79 RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d rc=%Vrc (free)\n", i, iReq, cReqs, rc);
80 return rc;
81 }
82 }
83 //if (!(i % 10000))
84 // RTPrintf(TESTCASE ": i=%d\n", i);
85 }
86
87 return VINF_SUCCESS;
88}
89
90
91
92int main(int argc, char **argv)
93{
94 int cErrors = 0;
95
96 RTR3Init();
97 RTPrintf(TESTCASE ": TESTING...\n");
98
99 /*
100 * Create empty VM.
101 */
102 PVM pVM;
103 int rc = VMR3Create(NULL, NULL, NULL, NULL, &pVM);
104 if (VBOX_SUCCESS(rc))
105 {
106 /*
107 * Do testing.
108 */
109 uint64_t u64StartTS = RTTimeNanoTS();
110 RTTHREAD Thread0;
111 rc = RTThreadCreate(&Thread0, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
112 if (VBOX_SUCCESS(rc))
113 {
114 RTTHREAD Thread1;
115 rc = RTThreadCreate(&Thread1, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
116 if (VBOX_SUCCESS(rc))
117 {
118 int rcThread1;
119 rc = RTThreadWait(Thread1, RT_INDEFINITE_WAIT, &rcThread1);
120 if (VBOX_FAILURE(rc))
121 {
122 RTPrintf(TESTCASE ": RTThreadWait(Thread1,,) failed, rc=%Vrc\n", rc);
123 cErrors++;
124 }
125 if (VBOX_FAILURE(rcThread1))
126 cErrors++;
127 }
128 else
129 {
130 RTPrintf(TESTCASE ": RTThreadCreate(&Thread1,,,,) failed, rc=%Vrc\n", rc);
131 cErrors++;
132 }
133
134 int rcThread0;
135 rc = RTThreadWait(Thread0, RT_INDEFINITE_WAIT, &rcThread0);
136 if (VBOX_FAILURE(rc))
137 {
138 RTPrintf(TESTCASE ": RTThreadWait(Thread1,,) failed, rc=%Vrc\n", rc);
139 cErrors++;
140 }
141 if (VBOX_FAILURE(rcThread0))
142 cErrors++;
143 }
144 else
145 {
146 RTPrintf(TESTCASE ": RTThreadCreate(&Thread0,,,,) failed, rc=%Vrc\n", rc);
147 cErrors++;
148 }
149 uint64_t u64ElapsedTS = RTTimeNanoTS() - u64StartTS;
150 RTPrintf(TESTCASE ": %llu ns elapsed\n", u64ElapsedTS);
151
152 /*
153 * Print stats.
154 */
155 STAMR3Print(pVM, "/VM/Req/*");
156
157 /*
158 * Cleanup.
159 */
160 rc = VMR3Destroy(pVM);
161 if (!VBOX_SUCCESS(rc))
162 {
163 RTPrintf(TESTCASE ": error: failed to destroy vm! rc=%Vrc\n", rc);
164 cErrors++;
165 }
166 }
167 else
168 {
169 RTPrintf(TESTCASE ": fatal error: failed to create vm! rc=%Vrc\n", rc);
170 cErrors++;
171 }
172
173 /*
174 * Summary and return.
175 */
176 if (!cErrors)
177 RTPrintf(TESTCASE ": SUCCESS\n");
178 else
179 RTPrintf(TESTCASE ": FAILURE - %d errors\n", cErrors);
180
181 return !!cErrors;
182}
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