Changeset 46632 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jun 18, 2013 4:58:49 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstMp-1.cpp
r46144 r46632 31 31 #include <iprt/cpuset.h> 32 32 #include <iprt/err.h> 33 #include <iprt/initterm.h>34 #include <iprt/stream.h>35 33 #include <iprt/string.h> 36 37 38 /******************************************************************************* 39 * Global Variables * 40 *******************************************************************************/ 41 static unsigned g_cErrors = 0; 34 #include <iprt/test.h> 35 42 36 43 37 44 38 int main() 45 39 { 46 RTR3InitExeNoArguments(0); 47 RTPrintf("tstMp-1: TESTING...\n"); 40 RTTEST hTest; 41 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTMp-1", &hTest); 42 if (rcExit != RTEXITCODE_SUCCESS) 43 return rcExit; 44 RTTestBanner(hTest); 48 45 49 46 /* … … 52 49 RTCPUID cCpus = RTMpGetCount(); 53 50 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++; 51 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCount -> %u\n", cCpus); 52 else 53 { 54 RTTestIFailed("RTMpGetCount returned zero"); 59 55 cCpus = 1; 60 56 } … … 62 58 RTCPUID cCoreCpus = RTMpGetCoreCount(); 63 59 if (cCoreCpus > 0) 64 RTPrintf("tstMp-1: RTMpGetCoreCount -> %d\n", (int)cCoreCpus); 65 else 66 { 67 RTPrintf("tstMp-1: FAILURE: RTMpGetCoreCount -> %d\n", (int)cCoreCpus); 68 g_cErrors++; 60 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCoreCount -> %d\n", (int)cCoreCpus); 61 else 62 { 63 RTTestIFailed("RTMpGetCoreCount returned zero"); 69 64 cCoreCpus = 1; 70 65 } 66 RTTESTI_CHECK(cCoreCpus <= cCpus); 71 67 72 68 RTCPUSET Set; 73 69 PRTCPUSET pSet = RTMpGetSet(&Set); 70 RTTESTI_CHECK(pSet == &Set); 74 71 if (pSet == &Set) 75 72 { 76 if ((RTCPUID)RTCpuSetCount(&Set) != cCpus) 77 { 78 RTPrintf("tstMp-1: FAILURE: RTMpGetSet returned a set with a different cpu count; %d, expected %d\n", 79 RTCpuSetCount(&Set), cCpus); 80 g_cErrors++; 81 } 82 RTPrintf("tstMp-1: Possible CPU mask:\n"); 73 RTTESTI_CHECK((RTCPUID)RTCpuSetCount(&Set) == cCpus); 74 75 RTTestIPrintf(RTTESTLVL_ALWAYS, "Possible CPU mask:\n"); 83 76 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 84 77 { … … 86 79 if (RTCpuSetIsMemberByIndex(&Set, iCpu)) 87 80 { 88 RT Printf("tstMp-1:%2d - id %d: %u/%u MHz", iCpu, (int)idCpu,89 RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu));81 RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz", iCpu, (int)idCpu, 82 RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu)); 90 83 if (RTMpIsCpuPresent(idCpu)) 91 RT Printf(RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n");84 RTTestIPrintf(RTTESTLVL_ALWAYS, RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n"); 92 85 else 93 86 { 94 87 if (!RTMpIsCpuOnline(idCpu)) 95 RT Printf(" absent\n");88 RTTestIPrintf(RTTESTLVL_ALWAYS, " absent\n"); 96 89 else 97 90 { 98 RTPrintf(" online but absent!\n"); 99 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu); 100 g_cErrors++; 91 RTTestIPrintf(RTTESTLVL_ALWAYS, " online but absent!\n"); 92 RTTestIFailed("Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu); 101 93 } 102 94 } 103 95 if (!RTMpIsCpuPossible(idCpu)) 104 { 105 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu); 106 g_cErrors++; 107 } 96 RTTestIFailed("Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu); 108 97 } 109 98 else if (RTMpIsCpuPossible(idCpu)) 110 { 111 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu); 112 g_cErrors++; 113 } 99 RTTestIFailed("Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu); 114 100 else if (RTMpGetCurFrequency(idCpu) != 0) 115 { 116 RTPrintf("tstMp-1: FAILURE: RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu); 117 g_cErrors++; 118 } 101 RTTestIFailed("RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu); 119 102 else if (RTMpGetMaxFrequency(idCpu) != 0) 120 { 121 RTPrintf("tstMp-1: FAILURE: RTMpGetMaxFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu); 122 g_cErrors++; 123 } 103 RTTestIFailed("RTMpGetMaxFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu); 124 104 } 125 105 } 126 106 else 127 107 { 128 RTPrintf("tstMp-1: FAILURE: RTMpGetSet -> %p, expected %p\n", pSet, &Set);129 g_cErrors++;130 108 RTCpuSetEmpty(&Set); 131 109 RTCpuSetAdd(&Set, RTMpCpuIdFromSetIndex(0)); … … 139 117 { 140 118 if (cCpusOnline <= cCpus) 141 RT Printf("tstMp-1:RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);119 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetOnlineCount -> %d\n", (int)cCpusOnline); 142 120 else 143 121 { 144 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus); 145 g_cErrors++; 122 RTTestIFailed("RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus); 146 123 cCpusOnline = cCpus; 147 124 } … … 149 126 else 150 127 { 151 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline); 152 g_cErrors++; 128 RTTestIFailed("RTMpGetOnlineCount -> %d\n", (int)cCpusOnline); 153 129 cCpusOnline = 1; 154 130 } … … 159 135 { 160 136 if (RTCpuSetCount(&SetOnline) <= 0) 161 { 162 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned an empty set!\n"); 163 g_cErrors++; 164 } 137 RTTestIFailed("RTMpGetOnlineSet returned an empty set!\n"); 165 138 else if ((RTCPUID)RTCpuSetCount(&SetOnline) > cCpus) 166 { 167 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n", 168 RTCpuSetCount(&SetOnline), cCpus); 169 g_cErrors++; 170 } 171 RTPrintf("tstMp-1: Online CPU mask:\n"); 139 RTTestIFailed("RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n", 140 RTCpuSetCount(&SetOnline), cCpus); 141 RTTestIPrintf(RTTESTLVL_ALWAYS, "Online CPU mask:\n"); 172 142 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 173 143 if (RTCpuSetIsMemberByIndex(&SetOnline, iCpu)) 174 144 { 175 145 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu); 176 RT Printf("tstMp-1:%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),177 RTMpGetMaxFrequency(idCpu), RTMpIsCpuOnline(idCpu) ? "online" : "offline");146 RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu), 147 RTMpGetMaxFrequency(idCpu), RTMpIsCpuOnline(idCpu) ? "online" : "offline"); 178 148 if (!RTCpuSetIsMemberByIndex(&Set, iCpu)) 179 { 180 RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu); 181 g_cErrors++; 182 } 149 RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu); 183 150 } 184 151 … … 186 153 } 187 154 else 188 { 189 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set); 190 g_cErrors++; 191 } 155 RTTestIFailed("RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set); 192 156 193 157 /* … … 199 163 if ( cCpusPresent <= cCpus 200 164 && cCpusPresent >= cCpusOnline) 201 RT Printf("tstMp-1:RTMpGetPresentCount -> %d\n", (int)cCpusPresent);165 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetPresentCount -> %d\n", (int)cCpusPresent); 202 166 else 203 { 204 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d, expected <= %d and >= %d\n", (int)cCpusPresent, (int)cCpus, (int)cCpusOnline); 205 g_cErrors++; 206 } 207 } 208 else 209 { 210 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d\n", (int)cCpusPresent); 211 g_cErrors++; 167 RTTestIFailed("RTMpGetPresentCount -> %d, expected <= %d and >= %d\n", 168 (int)cCpusPresent, (int)cCpus, (int)cCpusOnline); 169 } 170 else 171 { 172 RTTestIFailed("RTMpGetPresentCount -> %d\n", (int)cCpusPresent); 212 173 cCpusPresent = 1; 213 174 } … … 218 179 { 219 180 if (RTCpuSetCount(&SetPresent) <= 0) 220 { 221 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned an empty set!\n"); 222 g_cErrors++; 223 } 181 RTTestIFailed("RTMpGetPresentSet returned an empty set!\n"); 224 182 else if ((RTCPUID)RTCpuSetCount(&SetPresent) != cCpusPresent) 225 { 226 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned a bad value; %d, expected = %d\n", 227 RTCpuSetCount(&SetPresent), cCpusPresent); 228 g_cErrors++; 229 } 230 RTPrintf("tstMp-1: Present CPU mask:\n"); 183 RTTestIFailed("RTMpGetPresentSet returned a bad value; %d, expected = %d\n", 184 RTCpuSetCount(&SetPresent), cCpusPresent); 185 RTTestIPrintf(RTTESTLVL_ALWAYS, "Present CPU mask:\n"); 231 186 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++) 232 187 if (RTCpuSetIsMemberByIndex(&SetPresent, iCpu)) 233 188 { 234 189 RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu); 235 RT Printf("tstMp-1:%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),236 RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent");190 RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu), 191 RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent"); 237 192 if (!RTCpuSetIsMemberByIndex(&Set, iCpu)) 238 { 239 RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu); 240 g_cErrors++; 241 } 193 RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu); 242 194 } 243 195 … … 245 197 } 246 198 else 247 { 248 RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set); 249 g_cErrors++; 250 } 199 RTTestIFailed("RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set); 251 200 252 201 … … 264 213 if (RT_SUCCESS(rc)) 265 214 { 266 RT Printf("tstMp-1:RTMpGetDescription -> '%s'\n", szBuf);215 RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetDescription -> '%s'\n", szBuf); 267 216 268 217 size_t cch = strlen(szBuf); 269 218 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch); 270 219 if (rc != VERR_BUFFER_OVERFLOW) 271 { 272 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc); 273 g_cErrors++; 274 } 220 RTTestIFailed("RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc); 221 275 222 rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch + 1); 276 223 if (RT_FAILURE(rc)) 277 { 278 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc); 279 g_cErrors++; 280 } 281 } 282 else 283 { 284 RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc\n", rc); 285 g_cErrors++; 286 } 287 288 289 if (!g_cErrors) 290 RTPrintf("tstMp-1: SUCCESS\n", g_cErrors); 291 else 292 RTPrintf("tstMp-1: FAILURE - %d errors\n", g_cErrors); 293 return !!g_cErrors; 224 RTTestIFailed("RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc); 225 } 226 else 227 RTTestIFailed("RTMpGetDescription -> %Rrc\n", rc); 228 229 return RTTestSummaryAndDestroy(hTest); 294 230 } 295 231
Note:
See TracChangeset
for help on using the changeset viewer.