VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTMp-1.cpp@ 68155

Last change on this file since 68155 was 64281, checked in by vboxsync, 8 years ago

IPRT,SUP: Major vboxdrv and GIP version change; more flexible processor group handling on Windows.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.4 KB
Line 
1/* $Id: tstRTMp-1.cpp 64281 2016-10-15 16:46:29Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTMp.
4 */
5
6/*
7 * Copyright (C) 2008-2016 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/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/mp.h>
32#include <iprt/cpuset.h>
33#include <iprt/err.h>
34#include <iprt/string.h>
35#include <iprt/test.h>
36#ifdef VBOX
37# include <VBox/sup.h>
38#endif
39
40
41
42int main(int argc, char **argv)
43{
44 RTTEST hTest;
45 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTMp-1", &hTest);
46 if (rcExit != RTEXITCODE_SUCCESS)
47 return rcExit;
48 RTTestBanner(hTest);
49
50 NOREF(argc); NOREF(argv);
51#ifdef VBOX
52 if (argc > 1)
53 SUPR3Init(NULL);
54#endif
55
56 /*
57 * Present and possible CPUs.
58 */
59 RTCPUID cCpus = RTMpGetCount();
60 if (cCpus > 0)
61 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCount -> %u\n", cCpus);
62 else
63 {
64 RTTestIFailed("RTMpGetCount returned zero");
65 cCpus = 1;
66 }
67
68 RTCPUID cCoreCpus = RTMpGetCoreCount();
69 if (cCoreCpus > 0)
70 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCoreCount -> %d\n", (int)cCoreCpus);
71 else
72 {
73 RTTestIFailed("RTMpGetCoreCount returned zero");
74 cCoreCpus = 1;
75 }
76 RTTESTI_CHECK(cCoreCpus <= cCpus);
77
78 RTCPUSET Set;
79 PRTCPUSET pSet = RTMpGetSet(&Set);
80 RTTESTI_CHECK(pSet == &Set);
81 if (pSet == &Set)
82 {
83 RTTESTI_CHECK((RTCPUID)RTCpuSetCount(&Set) == cCpus);
84
85 RTTestIPrintf(RTTESTLVL_ALWAYS, "Possible CPU mask:\n");
86 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
87 {
88 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
89 if (RTCpuSetIsMemberByIndex(&Set, iCpu))
90 {
91 RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz", iCpu, (int)idCpu,
92 RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu));
93 if (RTMpIsCpuPresent(idCpu))
94 RTTestIPrintf(RTTESTLVL_ALWAYS, RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n");
95 else
96 {
97 if (!RTMpIsCpuOnline(idCpu))
98 RTTestIPrintf(RTTESTLVL_ALWAYS, " absent\n");
99 else
100 {
101 RTTestIPrintf(RTTESTLVL_ALWAYS, " online but absent!\n");
102 RTTestIFailed("Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu);
103 }
104 }
105 if (!RTMpIsCpuPossible(idCpu))
106 RTTestIFailed("Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu);
107 }
108 else if (RTMpIsCpuPossible(idCpu))
109 RTTestIFailed("Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu);
110 else if (RTMpGetCurFrequency(idCpu) != 0)
111 RTTestIFailed("RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
112 else if (RTMpGetMaxFrequency(idCpu) != 0)
113 RTTestIFailed("RTMpGetMaxFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
114 }
115 }
116 else
117 {
118 RTCpuSetEmpty(&Set);
119 RTCpuSetAdd(&Set, RTMpCpuIdFromSetIndex(0));
120 }
121
122 /*
123 * Online CPUs.
124 */
125 RTCPUID cCpusOnline = RTMpGetOnlineCount();
126 if (cCpusOnline > 0)
127 {
128 if (cCpusOnline <= cCpus)
129 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
130 else
131 {
132 RTTestIFailed("RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus);
133 cCpusOnline = cCpus;
134 }
135 }
136 else
137 {
138 RTTestIFailed("RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
139 cCpusOnline = 1;
140 }
141
142 RTCPUID cCoresOnline = RTMpGetOnlineCoreCount();
143 if (cCoresOnline > 0)
144 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetOnlineCoreCount -> %d\n", (int)cCoresOnline);
145 else
146 {
147 RTTestIFailed("RTMpGetOnlineCoreCount -> %d, expected <= %d\n", (int)cCoresOnline, (int)cCpusOnline);
148 cCoresOnline = 1;
149 }
150 RTTESTI_CHECK(cCoresOnline <= cCpusOnline);
151
152 RTCPUSET SetOnline;
153 pSet = RTMpGetOnlineSet(&SetOnline);
154 if (pSet == &SetOnline)
155 {
156 if (RTCpuSetCount(&SetOnline) <= 0)
157 RTTestIFailed("RTMpGetOnlineSet returned an empty set!\n");
158 else if ((RTCPUID)RTCpuSetCount(&SetOnline) > cCpus)
159 RTTestIFailed("RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n",
160 RTCpuSetCount(&SetOnline), cCpus);
161 RTTestIPrintf(RTTESTLVL_ALWAYS, "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 RTTestIPrintf(RTTESTLVL_ALWAYS, "%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 RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
170 }
171
172 /* There isn't any sane way of testing RTMpIsCpuOnline really... :-/ */
173 }
174 else
175 RTTestIFailed("RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set);
176
177 /*
178 * Present CPUs.
179 */
180 RTCPUID cCpusPresent = RTMpGetPresentCount();
181 if (cCpusPresent > 0)
182 {
183 if ( cCpusPresent <= cCpus
184 && cCpusPresent >= cCpusOnline)
185 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
186 else
187 RTTestIFailed("RTMpGetPresentCount -> %d, expected <= %d and >= %d\n",
188 (int)cCpusPresent, (int)cCpus, (int)cCpusOnline);
189 }
190 else
191 {
192 RTTestIFailed("RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
193 cCpusPresent = 1;
194 }
195
196 RTCPUSET SetPresent;
197 pSet = RTMpGetPresentSet(&SetPresent);
198 if (pSet == &SetPresent)
199 {
200 if (RTCpuSetCount(&SetPresent) <= 0)
201 RTTestIFailed("RTMpGetPresentSet returned an empty set!\n");
202 else if ((RTCPUID)RTCpuSetCount(&SetPresent) != cCpusPresent)
203 RTTestIFailed("RTMpGetPresentSet returned a bad value; %d, expected = %d\n",
204 RTCpuSetCount(&SetPresent), cCpusPresent);
205 RTTestIPrintf(RTTESTLVL_ALWAYS, "Present CPU mask:\n");
206 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
207 if (RTCpuSetIsMemberByIndex(&SetPresent, iCpu))
208 {
209 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
210 RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
211 RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent");
212 if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
213 RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
214 }
215
216 /* There isn't any sane way of testing RTMpIsCpuPresent really... :-/ */
217 }
218 else
219 RTTestIFailed("RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set);
220
221
222 /* Find an online cpu for the next test. */
223 RTCPUID idCpuOnline;
224 for (idCpuOnline = 0; idCpuOnline < RTCPUSET_MAX_CPUS; idCpuOnline++)
225 if (RTMpIsCpuOnline(idCpuOnline))
226 break;
227
228 /*
229 * Quick test of RTMpGetDescription.
230 */
231 char szBuf[64];
232 int rc = RTMpGetDescription(idCpuOnline, &szBuf[0], sizeof(szBuf));
233 if (RT_SUCCESS(rc))
234 {
235 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetDescription -> '%s'\n", szBuf);
236
237 size_t cch = strlen(szBuf);
238 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch);
239 if (rc != VERR_BUFFER_OVERFLOW)
240 RTTestIFailed("RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc);
241
242 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch + 1);
243 if (RT_FAILURE(rc))
244 RTTestIFailed("RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc);
245 }
246 else
247 RTTestIFailed("RTMpGetDescription -> %Rrc\n", rc);
248
249 return RTTestSummaryAndDestroy(hTest);
250}
251
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