VirtualBox

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

Last change on this file since 10419 was 10419, checked in by vboxsync, 16 years ago

Linux implementation of the RTMp* bits we current need in ring-3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1/* $Id: tstMp-1.cpp 10419 2008-07-09 13:46:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTMp.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/mp.h>
36#include <iprt/cpuset.h>
37#include <iprt/err.h>
38#include <iprt/stream.h>
39#include <iprt/initterm.h>
40
41
42/*******************************************************************************
43* Defined Constants And Macros *
44*******************************************************************************/
45
46/*******************************************************************************
47* Global Variables *
48*******************************************************************************/
49static unsigned g_cErrors = 0;
50
51
52int main()
53{
54 RTR3Init();
55 RTPrintf("tstMp-1: TESTING...\n");
56
57#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX)
58 /*
59 * Present and possible CPUs.
60 */
61 RTCPUID cCpus = RTMpGetCount();
62 if (cCpus > 0)
63 RTPrintf("tstMp-1: RTMpGetCount -> %d\n", (int)cCpus);
64 else
65 {
66 RTPrintf("tstMp-1: FAILURE: RTMpGetCount -> %d\n", (int)cCpus);
67 g_cErrors++;
68 cCpus = 1;
69 }
70
71 RTCPUSET Set;
72 PRTCPUSET pSet = RTMpGetSet(&Set);
73 if (pSet == &Set)
74 {
75 if ((RTCPUID)RTCpuSetCount(&Set) != cCpus)
76 {
77 RTPrintf("tstMp-1: FAILURE: RTMpGetSet returned a set with a different cpu count; %d, expected %d\n",
78 RTCpuSetCount(&Set), cCpus);
79 g_cErrors++;
80 }
81 RTPrintf("tstMp-1: Possible CPU mask:\n");
82 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
83 {
84 if (RTCpuSetIsMemberByIndex(&Set, iCpu))
85 {
86 RTPrintf("tstMp-1: %2d - id %d\n", iCpu, RTMpCpuIdFromSetIndex(iCpu));
87 if (!RTMpIsCpuPossible(RTMpCpuIdFromSetIndex(iCpu)))
88 {
89 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu);
90 g_cErrors++;
91 }
92 }
93 else if (RTMpIsCpuPossible(RTMpCpuIdFromSetIndex(iCpu)))
94 {
95 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu);
96 g_cErrors++;
97 }
98 }
99 }
100 else
101 {
102 RTPrintf("tstMp-1: FAILURE: RTMpGetSet -> %p, expected %p\n", pSet, &Set);
103 g_cErrors++;
104 RTCpuSetEmpty(&Set);
105 RTCpuSetAdd(&Set, RTMpCpuIdFromSetIndex(0));
106 }
107
108 /*
109 * Online CPUs.
110 */
111 RTCPUID cCpusOnline = RTMpGetOnlineCount();
112 if (cCpusOnline > 0)
113 {
114 if (cCpusOnline <= cCpus)
115 RTPrintf("tstMp-1: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
116 else
117 {
118 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus);
119 g_cErrors++;
120 cCpusOnline = cCpus;
121 }
122 }
123 else
124 {
125 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
126 g_cErrors++;
127 cCpusOnline = 1;
128 }
129
130 RTCPUSET SetOnline;
131 pSet = RTMpGetOnlineSet(&SetOnline);
132 if (pSet == &SetOnline)
133 {
134 if (RTCpuSetCount(&SetOnline) <= 0)
135 {
136 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned an empty set!\n");
137 g_cErrors++;
138 }
139 else if ((RTCPUID)RTCpuSetCount(&SetOnline) > cCpus)
140 {
141 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n",
142 RTCpuSetCount(&SetOnline), cCpus);
143 g_cErrors++;
144 }
145 RTPrintf("tstMp-1: Online CPU mask:\n");
146 for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
147 if (RTCpuSetIsMemberByIndex(&SetOnline, iCpu))
148 {
149 RTPrintf("tstMp-1: %2d - id %d\n", iCpu, RTMpCpuIdFromSetIndex(iCpu));
150 if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
151 {
152 RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
153 g_cErrors++;
154 }
155 }
156
157 /* There isn't any sane way of testing RTMpIsCpuOnline really... :-/ */
158 }
159 else
160 {
161 RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set);
162 g_cErrors++;
163 }
164
165#else
166 RTPrintf("tstMp-1: SKIPPED - RTMp is not implemented on this host OS.\n");
167#endif
168
169 if (!g_cErrors)
170 RTPrintf("tstMp-1: SUCCESS\n", g_cErrors);
171 else
172 RTPrintf("tstMp-1: FAILURE - %d errors\n", g_cErrors);
173 return !!g_cErrors;
174}
175
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