VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstMp-1.cpp@ 30552

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1/* $Id: tstMp-1.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTMp.
4 */
5
6/*
7 * Copyright (C) 2008 Oracle Corporation
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
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/mp.h>
31#include <iprt/cpuset.h>
32#include <iprt/err.h>
33#include <iprt/initterm.h>
34#include <iprt/stream.h>
35#include <iprt/string.h>
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41static unsigned g_cErrors = 0;
42
43
44int main()
45{
46 RTR3Init();
47 RTPrintf("tstMp-1: TESTING...\n");
48
49 /*
50 * Present and possible CPUs.
51 */
52 RTCPUID cCpus = RTMpGetCount();
53 if (cCpus > 0)
54 RTPrintf("tstMp-1: RTMpGetCount -> %d\n", (int)cCpus);
55 else
56 {
57 RTPrintf("tstMp-1: FAILURE: RTMpGetCount -> %d\n", (int)cCpus);
58 g_cErrors++;
59 cCpus = 1;
60 }
61
62 RTCPUSET Set;
63 PRTCPUSET pSet = RTMpGetSet(&Set);
64 if (pSet == &Set)
65 {
66 if ((RTCPUID)RTCpuSetCount(&Set) != cCpus)
67 {
68 RTPrintf("tstMp-1: FAILURE: RTMpGetSet returned a set with a different cpu count; %d, expected %d\n",
69 RTCpuSetCount(&Set), cCpus);
70 g_cErrors++;
71 }
72 RTPrintf("tstMp-1: Possible CPU mask:\n");
73 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
74 {
75 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
76 if (RTCpuSetIsMemberByIndex(&Set, iCpu))
77 {
78 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz", iCpu, (int)idCpu,
79 RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu));
80 if (RTMpIsCpuPresent(idCpu))
81 RTPrintf(RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n");
82 else
83 {
84 if (!RTMpIsCpuOnline(idCpu))
85 RTPrintf(" absent\n");
86 else
87 {
88 RTPrintf(" online but absent!\n");
89 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu);
90 g_cErrors++;
91 }
92 }
93 if (!RTMpIsCpuPossible(idCpu))
94 {
95 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu);
96 g_cErrors++;
97 }
98 }
99 else if (RTMpIsCpuPossible(idCpu))
100 {
101 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu);
102 g_cErrors++;
103 }
104 else if (RTMpGetCurFrequency(idCpu) != 0)
105 {
106 RTPrintf("tstMp-1: FAILURE: RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
107 g_cErrors++;
108 }
109 else if (RTMpGetMaxFrequency(idCpu) != 0)
110 {
111 RTPrintf("tstMp-1: FAILURE: RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
112 g_cErrors++;
113 }
114 }
115 }
116 else
117 {
118 RTPrintf("tstMp-1: FAILURE: RTMpGetSet -> %p, expected %p\n", pSet, &Set);
119 g_cErrors++;
120 RTCpuSetEmpty(&Set);
121 RTCpuSetAdd(&Set, RTMpCpuIdFromSetIndex(0));
122 }
123
124 /*
125 * Online CPUs.
126 */
127 RTCPUID cCpusOnline = RTMpGetOnlineCount();
128 if (cCpusOnline > 0)
129 {
130 if (cCpusOnline <= cCpus)
131 RTPrintf("tstMp-1: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
132 else
133 {
134 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus);
135 g_cErrors++;
136 cCpusOnline = cCpus;
137 }
138 }
139 else
140 {
141 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
142 g_cErrors++;
143 cCpusOnline = 1;
144 }
145
146 RTCPUSET SetOnline;
147 pSet = RTMpGetOnlineSet(&SetOnline);
148 if (pSet == &SetOnline)
149 {
150 if (RTCpuSetCount(&SetOnline) <= 0)
151 {
152 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned an empty set!\n");
153 g_cErrors++;
154 }
155 else if ((RTCPUID)RTCpuSetCount(&SetOnline) > cCpus)
156 {
157 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n",
158 RTCpuSetCount(&SetOnline), cCpus);
159 g_cErrors++;
160 }
161 RTPrintf("tstMp-1: Online CPU mask:\n");
162 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
163 if (RTCpuSetIsMemberByIndex(&SetOnline, iCpu))
164 {
165 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
166 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
167 RTMpGetMaxFrequency(idCpu), RTMpIsCpuOnline(idCpu) ? "online" : "offline");
168 if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
169 {
170 RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
171 g_cErrors++;
172 }
173 }
174
175 /* There isn't any sane way of testing RTMpIsCpuOnline really... :-/ */
176 }
177 else
178 {
179 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set);
180 g_cErrors++;
181 }
182
183 /*
184 * Present CPUs.
185 */
186 RTCPUID cCpusPresent = RTMpGetPresentCount();
187 if (cCpusPresent > 0)
188 {
189 if ( cCpusPresent <= cCpus
190 && cCpusPresent >= cCpusOnline)
191 RTPrintf("tstMp-1: RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
192 else
193 {
194 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d, expected <= %d and >= %d\n", (int)cCpusPresent, (int)cCpus, (int)cCpusOnline);
195 g_cErrors++;
196 }
197 }
198 else
199 {
200 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
201 g_cErrors++;
202 cCpusPresent = 1;
203 }
204
205 RTCPUSET SetPresent;
206 pSet = RTMpGetPresentSet(&SetPresent);
207 if (pSet == &SetPresent)
208 {
209 if (RTCpuSetCount(&SetPresent) <= 0)
210 {
211 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned an empty set!\n");
212 g_cErrors++;
213 }
214 else if ((RTCPUID)RTCpuSetCount(&SetPresent) != cCpusPresent)
215 {
216 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned a bad value; %d, expected = %d\n",
217 RTCpuSetCount(&SetPresent), cCpusPresent);
218 g_cErrors++;
219 }
220 RTPrintf("tstMp-1: Present CPU mask:\n");
221 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
222 if (RTCpuSetIsMemberByIndex(&SetPresent, iCpu))
223 {
224 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
225 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
226 RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent");
227 if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
228 {
229 RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
230 g_cErrors++;
231 }
232 }
233
234 /* There isn't any sane way of testing RTMpIsCpuPresent really... :-/ */
235 }
236 else
237 {
238 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set);
239 g_cErrors++;
240 }
241
242
243 /* Find an online cpu for the next test. */
244 RTCPUID idCpuOnline;
245 for (idCpuOnline = 0; idCpuOnline < RTCPUSET_MAX_CPUS; idCpuOnline++)
246 if (RTMpIsCpuOnline(idCpuOnline))
247 break;
248
249 /*
250 * Quick test of RTMpGetDescription.
251 */
252 char szBuf[64];
253 int rc = RTMpGetDescription(idCpuOnline, &szBuf[0], sizeof(szBuf));
254 if (RT_SUCCESS(rc))
255 {
256 RTPrintf("tstMp-1: RTMpGetDescription -> '%s'\n", szBuf);
257
258 size_t cch = strlen(szBuf);
259 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch);
260 if (rc != VERR_BUFFER_OVERFLOW)
261 {
262 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc);
263 g_cErrors++;
264 }
265 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch + 1);
266 if (RT_FAILURE(rc))
267 {
268 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc);
269 g_cErrors++;
270 }
271 }
272 else
273 {
274 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc\n", rc);
275 g_cErrors++;
276 }
277
278
279 if (!g_cErrors)
280 RTPrintf("tstMp-1: SUCCESS\n", g_cErrors);
281 else
282 RTPrintf("tstMp-1: FAILURE - %d errors\n", g_cErrors);
283 return !!g_cErrors;
284}
285
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