1 | /* $Id: tstVMREQ.cpp 4071 2007-08-07 17:07:59Z 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 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include <VBox/vm.h>
|
---|
23 | #include <VBox/vmm.h>
|
---|
24 | #include <VBox/cpum.h>
|
---|
25 | #include <VBox/err.h>
|
---|
26 | #include <VBox/log.h>
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/runtime.h>
|
---|
29 | #include <iprt/semaphore.h>
|
---|
30 | #include <iprt/stream.h>
|
---|
31 | #include <iprt/thread.h>
|
---|
32 | #include <iprt/time.h>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | /*******************************************************************************
|
---|
38 | * Defined Constants And Macros *
|
---|
39 | *******************************************************************************/
|
---|
40 | #define TESTCASE "tstVMREQ"
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Thread function which allocates and frees requests like wildfire.
|
---|
44 | */
|
---|
45 | DECLCALLBACK(int) Thread(RTTHREAD Thread, void *pvUser)
|
---|
46 | {
|
---|
47 | int rc = VINF_SUCCESS;
|
---|
48 | PVM pVM = (PVM)pvUser;
|
---|
49 | for (unsigned i = 0; i < 100000; i++)
|
---|
50 | {
|
---|
51 | PVMREQ apReq[17];
|
---|
52 | const unsigned cReqs = i % ELEMENTS(apReq);
|
---|
53 | unsigned iReq;
|
---|
54 | for (iReq = 0; iReq < cReqs; iReq++)
|
---|
55 | {
|
---|
56 | rc = VMR3ReqAlloc(pVM, &apReq[iReq], VMREQTYPE_INTERNAL);
|
---|
57 | if (VBOX_FAILURE(rc))
|
---|
58 | {
|
---|
59 | RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d rc=%Vrc (alloc)\n", i, iReq, cReqs, rc);
|
---|
60 | return rc;
|
---|
61 | }
|
---|
62 | apReq[iReq]->iStatus = iReq + i;
|
---|
63 | }
|
---|
64 |
|
---|
65 | for (iReq = 0; iReq < cReqs; iReq++)
|
---|
66 | {
|
---|
67 | if (apReq[iReq]->iStatus != (int)(iReq + i))
|
---|
68 | {
|
---|
69 | RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d: iStatus=%d != %d\n", i, iReq, cReqs, apReq[iReq]->iStatus, iReq + i);
|
---|
70 | return VERR_GENERAL_FAILURE;
|
---|
71 | }
|
---|
72 | rc = VMR3ReqFree(apReq[iReq]);
|
---|
73 | if (VBOX_FAILURE(rc))
|
---|
74 | {
|
---|
75 | RTPrintf(TESTCASE ": i=%d iReq=%d cReqs=%d rc=%Vrc (free)\n", i, iReq, cReqs, rc);
|
---|
76 | return rc;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | //if (!(i % 10000))
|
---|
80 | // RTPrintf(TESTCASE ": i=%d\n", i);
|
---|
81 | }
|
---|
82 |
|
---|
83 | return VINF_SUCCESS;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | int main(int argc, char **argv)
|
---|
89 | {
|
---|
90 | int cErrors = 0;
|
---|
91 |
|
---|
92 | RTR3Init();
|
---|
93 | RTPrintf(TESTCASE ": TESTING...\n");
|
---|
94 |
|
---|
95 | /*
|
---|
96 | * Create empty VM.
|
---|
97 | */
|
---|
98 | PVM pVM;
|
---|
99 | int rc = VMR3Create(NULL, NULL, NULL, NULL, &pVM);
|
---|
100 | if (VBOX_SUCCESS(rc))
|
---|
101 | {
|
---|
102 | /*
|
---|
103 | * Do testing.
|
---|
104 | */
|
---|
105 | uint64_t u64StartTS = RTTimeNanoTS();
|
---|
106 | RTTHREAD Thread0;
|
---|
107 | rc = RTThreadCreate(&Thread0, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
|
---|
108 | if (VBOX_SUCCESS(rc))
|
---|
109 | {
|
---|
110 | RTTHREAD Thread1;
|
---|
111 | rc = RTThreadCreate(&Thread1, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
|
---|
112 | if (VBOX_SUCCESS(rc))
|
---|
113 | {
|
---|
114 | int rcThread1;
|
---|
115 | rc = RTThreadWait(Thread1, RT_INDEFINITE_WAIT, &rcThread1);
|
---|
116 | if (VBOX_FAILURE(rc))
|
---|
117 | {
|
---|
118 | RTPrintf(TESTCASE ": RTThreadWait(Thread1,,) failed, rc=%Vrc\n", rc);
|
---|
119 | cErrors++;
|
---|
120 | }
|
---|
121 | if (VBOX_FAILURE(rcThread1))
|
---|
122 | cErrors++;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | RTPrintf(TESTCASE ": RTThreadCreate(&Thread1,,,,) failed, rc=%Vrc\n", rc);
|
---|
127 | cErrors++;
|
---|
128 | }
|
---|
129 |
|
---|
130 | int rcThread0;
|
---|
131 | rc = RTThreadWait(Thread0, RT_INDEFINITE_WAIT, &rcThread0);
|
---|
132 | if (VBOX_FAILURE(rc))
|
---|
133 | {
|
---|
134 | RTPrintf(TESTCASE ": RTThreadWait(Thread1,,) failed, rc=%Vrc\n", rc);
|
---|
135 | cErrors++;
|
---|
136 | }
|
---|
137 | if (VBOX_FAILURE(rcThread0))
|
---|
138 | cErrors++;
|
---|
139 | }
|
---|
140 | else
|
---|
141 | {
|
---|
142 | RTPrintf(TESTCASE ": RTThreadCreate(&Thread0,,,,) failed, rc=%Vrc\n", rc);
|
---|
143 | cErrors++;
|
---|
144 | }
|
---|
145 | uint64_t u64ElapsedTS = RTTimeNanoTS() - u64StartTS;
|
---|
146 | RTPrintf(TESTCASE ": %llu ns elapsed\n", u64ElapsedTS);
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * Print stats.
|
---|
150 | */
|
---|
151 | STAMR3Print(pVM, "/VM/Req/*");
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * Cleanup.
|
---|
155 | */
|
---|
156 | rc = VMR3Destroy(pVM);
|
---|
157 | if (!VBOX_SUCCESS(rc))
|
---|
158 | {
|
---|
159 | RTPrintf(TESTCASE ": error: failed to destroy vm! rc=%Vrc\n", rc);
|
---|
160 | cErrors++;
|
---|
161 | }
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | RTPrintf(TESTCASE ": fatal error: failed to create vm! rc=%Vrc\n", rc);
|
---|
166 | cErrors++;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * Summary and return.
|
---|
171 | */
|
---|
172 | if (!cErrors)
|
---|
173 | RTPrintf(TESTCASE ": SUCCESS\n");
|
---|
174 | else
|
---|
175 | RTPrintf(TESTCASE ": FAILURE - %d errors\n", cErrors);
|
---|
176 |
|
---|
177 | return !!cErrors;
|
---|
178 | }
|
---|