VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem.cpp@ 35650

Last change on this file since 35650 was 33383, checked in by vboxsync, 14 years ago

tstSupSem: Fix return code check

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 KB
Line 
1/* $Id: tstSupSem.cpp 33383 2010-10-24 14:33:13Z vboxsync $ */
2/** @file
3 * Support Library Testcase - Ring-3 Semaphore interface.
4 */
5
6/*
7 * Copyright (C) 2009-2010 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 <VBox/sup.h>
32
33#include <VBox/param.h>
34#include <iprt/err.h>
35#include <iprt/initterm.h>
36#include <iprt/stream.h>
37#include <iprt/test.h>
38#include <iprt/thread.h>
39#include <iprt/process.h>
40#include <iprt/env.h>
41#include <iprt/string.h>
42#include <iprt/time.h>
43
44
45/*******************************************************************************
46* Structures and Typedefs *
47*******************************************************************************/
48static PSUPDRVSESSION g_pSession;
49static RTTEST g_hTest;
50static uint32_t g_cMillies; /* Used by the interruptible tests. */
51
52
53
54static DECLCALLBACK(int) tstSupSemInterruptibleSRE(RTTHREAD hSelf, void *pvUser)
55{
56 SUPSEMEVENT hEvent = (SUPSEMEVENT)pvUser;
57 RTThreadUserSignal(hSelf);
58 return SUPSemEventWaitNoResume(g_pSession, hEvent, g_cMillies);
59}
60
61
62static DECLCALLBACK(int) tstSupSemInterruptibleMRE(RTTHREAD hSelf, void *pvUser)
63{
64 SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)pvUser;
65 RTThreadUserSignal(hSelf);
66 return SUPSemEventMultiWaitNoResume(g_pSession, hEventMulti, g_cMillies);
67}
68
69
70int main(int argc, char **argv)
71{
72 bool fSys = true;
73 bool fGip = false;
74#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
75 fGip = true;
76#endif
77
78 /*
79 * Init.
80 */
81 int rc = RTR3InitAndSUPLib();
82 if (RT_FAILURE(rc))
83 {
84 RTPrintf("tstSupSem: fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
85 return 1;
86 }
87
88 if (argc == 2 && !strcmp(argv[1], "child"))
89 {
90 RTThreadSleep(300);
91 return 0;
92 }
93
94 RTTEST hTest;
95 rc = RTTestCreate("tstSupSem", &hTest);
96 if (RT_FAILURE(rc))
97 {
98 RTPrintf("tstSupSem: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
99 return 1;
100 }
101 g_hTest = hTest;
102
103 PSUPDRVSESSION pSession;
104 rc = SUPR3Init(&pSession);
105 if (RT_FAILURE(rc))
106 {
107 RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
108 return RTTestSummaryAndDestroy(hTest);
109 }
110 g_pSession = pSession;
111 RTTestBanner(hTest);
112
113 /*
114 * Basic API checks.
115 */
116 RTTestSub(hTest, "Single Release Event (SRE) API");
117 SUPSEMEVENT hEvent = NIL_SUPSEMEVENT;
118 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
119 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
120 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VERR_TIMEOUT);
121 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VERR_TIMEOUT);
122 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VERR_TIMEOUT);
123 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
124 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
125 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
126 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
127 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VINF_SUCCESS);
128 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
129 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VINF_SUCCESS);
130 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
131 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VINF_SUCCESS);
132 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
133 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 20), VINF_SUCCESS);
134 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
135 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,1000),VINF_SUCCESS);
136 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
137 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
138 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
139 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
140 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VERR_TIMEOUT);
141 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VERR_TIMEOUT);
142 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VERR_TIMEOUT);
143 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
144 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
145 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VERR_INVALID_HANDLE);
146 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, NIL_SUPSEMEVENT), VINF_SUCCESS);
147
148 RTTestSub(hTest, "Multiple Release Event (MRE) API");
149 SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT;
150 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
151 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
152 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VERR_TIMEOUT);
153 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VERR_TIMEOUT);
154 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VERR_TIMEOUT);
155 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
156 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
157 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
158 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
159 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
160 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VINF_SUCCESS);
161 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VINF_SUCCESS);
162 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VINF_SUCCESS);
163 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VINF_SUCCESS);
164 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,1000), VINF_SUCCESS);
165 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
166 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
167 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
168 RTTESTI_CHECK_RC(SUPSemEventMultiReset(pSession, hEventMulti), VINF_SUCCESS);
169 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
170 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VERR_TIMEOUT);
171 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VERR_TIMEOUT);
172 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VERR_TIMEOUT);
173 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
174 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
175 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
176 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VINF_SUCCESS);
177 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VINF_SUCCESS);
178 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VINF_SUCCESS);
179 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 20), VINF_SUCCESS);
180 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,1000), VINF_SUCCESS);
181 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
182 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VERR_INVALID_HANDLE);
183 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, NIL_SUPSEMEVENTMULTI), VINF_SUCCESS);
184
185#if !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
186 RTTestSub(hTest, "SRE Interruptibility");
187 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
188 g_cMillies = RT_INDEFINITE_WAIT;
189 RTTHREAD hThread = NIL_RTTHREAD;
190 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
191 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
192 RTThreadSleep(120);
193 RTThreadPoke(hThread);
194 int rcThread = VINF_SUCCESS;
195 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
196 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
197 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
198
199 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
200 g_cMillies = 120*1000;
201 hThread = NIL_RTTHREAD;
202 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
203 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
204 RTThreadSleep(120);
205 RTThreadPoke(hThread);
206 rcThread = VINF_SUCCESS;
207 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
208 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
209 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
210
211
212 RTTestSub(hTest, "MRE Interruptibility");
213 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
214 g_cMillies = RT_INDEFINITE_WAIT;
215 hThread = NIL_RTTHREAD;
216 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS);
217 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
218 RTThreadSleep(120);
219 RTThreadPoke(hThread);
220 rcThread = VINF_SUCCESS;
221 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
222 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
223 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
224
225 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
226 g_cMillies = 120*1000;
227 hThread = NIL_RTTHREAD;
228 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS);
229 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
230 RTThreadSleep(120);
231 RTThreadPoke(hThread);
232 rcThread = VINF_SUCCESS;
233 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
234 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
235 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
236
237 /*
238 * Fork test.
239 * Spawn a thread waiting for an event, then spawn a new child process (of
240 * ourselves) and make sure that this does not alter the intended behaviour
241 * of our event semaphore implementation (see #5090).
242 */
243 RTTestSub(hTest, "SRE Process Spawn");
244 hThread = NIL_RTTHREAD;
245 g_cMillies = 120*1000;
246 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
247 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
248
249 const char *apszArgs[3] = { argv[0], "child", NULL };
250 RTPROCESS Process = NIL_RTPROCESS;
251 RTThreadSleep(250);
252 RTTESTI_CHECK_RC(RTProcCreate(apszArgs[0], apszArgs, RTENV_DEFAULT, 0, &Process), VINF_SUCCESS);
253
254 RTThreadSleep(250);
255 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
256
257 rcThread = VERR_GENERAL_FAILURE;
258 RTTESTI_CHECK_RC(RTThreadWait(hThread, 120*1000, &rcThread), VINF_SUCCESS);
259 RTTESTI_CHECK_RC(rcThread, VINF_SUCCESS);
260 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
261
262
263 RTTestSub(hTest, "MRE Process Spawn");
264 hThread = NIL_RTTHREAD;
265 g_cMillies = 120*1000;
266 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
267 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
268
269 RTTHREAD hThread2 = NIL_RTTHREAD;
270 RTTESTI_CHECK_RC(RTThreadCreate(&hThread2, tstSupSemInterruptibleMRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
271
272 Process = NIL_RTPROCESS;
273 RTThreadSleep(250);
274 RTTESTI_CHECK_RC(RTProcCreate(apszArgs[0], apszArgs, RTENV_DEFAULT, 0, &Process), VINF_SUCCESS);
275
276 RTThreadSleep(250);
277 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEvent), VINF_SUCCESS);
278
279 rcThread = VERR_GENERAL_FAILURE;
280 RTTESTI_CHECK_RC(RTThreadWait(hThread, 120*1000, &rcThread), VINF_SUCCESS);
281 RTTESTI_CHECK_RC(rcThread, VINF_SUCCESS);
282
283 int rcThread2 = VERR_GENERAL_FAILURE;
284 RTTESTI_CHECK_RC(RTThreadWait(hThread2, 120*1000, &rcThread2), VINF_SUCCESS);
285 RTTESTI_CHECK_RC(rcThread2, VINF_SUCCESS);
286
287 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
288
289#endif /* !OS2 && !WINDOWS */
290
291 {
292 static unsigned const s_acMsIntervals[] = { 0, 1, 2, 3, 4, 8, 10, 16, 32 };
293 if (RTTestErrorCount(hTest) == 0)
294 {
295 RTTestSub(hTest, "SRE Timeout Accuracy (ms)");
296 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
297
298 for (unsigned i = 0; i < RT_ELEMENTS(s_acMsIntervals); i++)
299 {
300 uint64_t cMs = s_acMsIntervals[i];
301 uint64_t cNsMinSys = UINT64_MAX;
302 uint64_t cNsMin = UINT64_MAX;
303 uint64_t cNsTotalSys= 0;
304 uint64_t cNsTotal = 0;
305 for (unsigned j = 0; j < 10; j++)
306 {
307 uint64_t u64StartSys = RTTimeSystemNanoTS();
308 uint64_t u64Start = RTTimeNanoTS();
309 int rcX = SUPSemEventWaitNoResume(pSession, hEvent, cMs);
310 if (rcX != VERR_TIMEOUT)
311 RTTestFailed(hTest, "%Rrc j=%u cMs=%u", rcX, j, cMs);
312 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
313 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
314 if (cNsElapsedSys < cNsMinSys)
315 cNsMinSys = cNsElapsedSys;
316 if (cNsElapsed < cNsMin)
317 cNsMin = cNsElapsed;
318 cNsTotalSys += cNsElapsedSys;
319 cNsTotal += cNsElapsed;
320 }
321 if (fSys)
322 {
323 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%u ms min (clock=sys)", cMs);
324 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%u ms avg (clock=sys)", cMs);
325 }
326 if (fGip)
327 {
328 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%u ms min (clock=gip)", cMs);
329 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%u ms avg (clock=gip)", cMs);
330 }
331 }
332
333 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
334 }
335
336 if (RTTestErrorCount(hTest) == 0)
337 {
338 RTTestSub(hTest, "MRE Timeout Accuracy (ms)");
339 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
340
341 for (unsigned i = 0; i < RT_ELEMENTS(s_acMsIntervals); i++)
342 {
343 uint64_t cMs = s_acMsIntervals[i];
344 uint64_t cNsMinSys = UINT64_MAX;
345 uint64_t cNsMin = UINT64_MAX;
346 uint64_t cNsTotalSys= 0;
347 uint64_t cNsTotal = 0;
348 for (unsigned j = 0; j < 10; j++)
349 {
350 uint64_t u64StartSys = RTTimeSystemNanoTS();
351 uint64_t u64Start = RTTimeNanoTS();
352 int rcX = SUPSemEventMultiWaitNoResume(pSession, hEvent, cMs);
353 if (rcX != VERR_TIMEOUT)
354 RTTestFailed(hTest, "%Rrc j=%u cMs=%u", rcX, j, cMs);
355 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
356 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
357 if (cNsElapsedSys < cNsMinSys)
358 cNsMinSys = cNsElapsedSys;
359 if (cNsElapsed < cNsMin)
360 cNsMin = cNsElapsed;
361 cNsTotalSys += cNsElapsedSys;
362 cNsTotal += cNsElapsed;
363 }
364 if (fSys)
365 {
366 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%u ms min (clock=sys)", cMs);
367 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%u ms avg (clock=sys)", cMs);
368 }
369 if (fGip)
370 {
371 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%u ms min (clock=gip)", cMs);
372 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%u ms avg (clock=gip)", cMs);
373 }
374 }
375
376 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
377 }
378 }
379
380 {
381 static uint32_t const s_acNsIntervals[] =
382 {
383 0, 1000, 5000, 15000, 30000, 50000, 100000, 250000, 500000, 750000, 900000, 1500000, 2200000
384 };
385
386 if (RTTestErrorCount(hTest) == 0)
387 {
388 RTTestSub(hTest, "SUPSemEventWaitNsRelIntr Accuracy");
389 RTTestValueF(hTest, SUPSemEventGetResolution(pSession), RTTESTUNIT_NS, "SRE resolution");
390 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
391
392 for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
393 {
394 uint64_t cNs = s_acNsIntervals[i];
395 uint64_t cNsMinSys = UINT64_MAX;
396 uint64_t cNsMin = UINT64_MAX;
397 uint64_t cNsTotalSys= 0;
398 uint64_t cNsTotal = 0;
399 for (unsigned j = 0; j < 10; j++)
400 {
401 uint64_t u64StartSys = RTTimeSystemNanoTS();
402 uint64_t u64Start = RTTimeNanoTS();
403 int rcX = SUPSemEventWaitNsRelIntr(pSession, hEvent, cNs);
404 if (rcX != VERR_TIMEOUT)
405 RTTestFailed(hTest, "%Rrc j=%u cNs=%u", rcX, j, cNs);
406 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
407 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
408 if (cNsElapsedSys < cNsMinSys)
409 cNsMinSys = cNsElapsedSys;
410 if (cNsElapsed < cNsMin)
411 cNsMin = cNsElapsed;
412 cNsTotalSys += cNsElapsedSys;
413 cNsTotal += cNsElapsed;
414 }
415 if (fSys)
416 {
417 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
418 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
419 }
420 if (fGip)
421 {
422 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
423 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
424 }
425 }
426
427 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
428 }
429
430 if (RTTestErrorCount(hTest) == 0)
431 {
432 RTTestSub(hTest, "SUPSemEventMultiWaitNsRelIntr Accuracy");
433 RTTestValueF(hTest, SUPSemEventMultiGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
434 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
435
436 for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
437 {
438 uint64_t cNs = s_acNsIntervals[i];
439 uint64_t cNsMinSys = UINT64_MAX;
440 uint64_t cNsMin = UINT64_MAX;
441 uint64_t cNsTotalSys= 0;
442 uint64_t cNsTotal = 0;
443 for (unsigned j = 0; j < 10; j++)
444 {
445 uint64_t u64StartSys = RTTimeSystemNanoTS();
446 uint64_t u64Start = RTTimeNanoTS();
447 int rcX = SUPSemEventMultiWaitNsRelIntr(pSession, hEvent, cNs);
448 if (rcX != VERR_TIMEOUT)
449 RTTestFailed(hTest, "%Rrc j=%u cNs=%u", rcX, j, cNs);
450 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
451 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
452 if (cNsElapsedSys < cNsMinSys)
453 cNsMinSys = cNsElapsedSys;
454 if (cNsElapsed < cNsMin)
455 cNsMin = cNsElapsed;
456 cNsTotalSys += cNsElapsedSys;
457 cNsTotal += cNsElapsed;
458 }
459 if (fSys)
460 {
461 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
462 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
463 }
464 if (fGip)
465 {
466 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
467 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
468 }
469 }
470
471 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
472 }
473
474 if (RTTestErrorCount(hTest) == 0)
475 {
476 RTTestSub(hTest, "SUPSemEventWaitNsAbsIntr Accuracy");
477 RTTestValueF(hTest, SUPSemEventGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
478 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
479
480 for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
481 {
482 uint64_t cNs = s_acNsIntervals[i];
483 uint64_t cNsMinSys = UINT64_MAX;
484 uint64_t cNsMin = UINT64_MAX;
485 uint64_t cNsTotalSys= 0;
486 uint64_t cNsTotal = 0;
487 for (unsigned j = 0; j < 10; j++)
488 {
489 uint64_t u64StartSys = RTTimeSystemNanoTS();
490 uint64_t u64Start = RTTimeNanoTS();
491 uint64_t uAbsDeadline = (fGip ? u64Start : u64StartSys) + cNs;
492 int rcX = SUPSemEventWaitNsAbsIntr(pSession, hEvent, uAbsDeadline);
493 if (rcX != VERR_TIMEOUT)
494 RTTestFailed(hTest, "%Rrc j=%u cNs=%u", rcX, j, cNs);
495 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
496 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
497 if (cNsElapsedSys < cNsMinSys)
498 cNsMinSys = cNsElapsedSys;
499 if (cNsElapsed < cNsMin)
500 cNsMin = cNsElapsed;
501 cNsTotalSys += cNsElapsedSys;
502 cNsTotal += cNsElapsed;
503 }
504 if (fSys)
505 {
506 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
507 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
508 }
509 if (fGip)
510 {
511 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
512 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
513 }
514 }
515
516 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
517 }
518
519
520 if (RTTestErrorCount(hTest) == 0)
521 {
522 RTTestSub(hTest, "SUPSemEventMultiWaitNsAbsIntr Accuracy");
523 RTTestValueF(hTest, SUPSemEventMultiGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
524 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
525
526 for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
527 {
528 uint64_t cNs = s_acNsIntervals[i];
529 uint64_t cNsMinSys = UINT64_MAX;
530 uint64_t cNsMin = UINT64_MAX;
531 uint64_t cNsTotalSys= 0;
532 uint64_t cNsTotal = 0;
533 for (unsigned j = 0; j < 10; j++)
534 {
535 uint64_t u64StartSys = RTTimeSystemNanoTS();
536 uint64_t u64Start = RTTimeNanoTS();
537 uint64_t uAbsDeadline = (fGip ? u64Start : u64StartSys) + cNs;
538 int rcX = SUPSemEventMultiWaitNsAbsIntr(pSession, hEvent, uAbsDeadline);
539 if (rcX != VERR_TIMEOUT)
540 RTTestFailed(hTest, "%Rrc j=%u cNs=%u", rcX, j, cNs);
541 uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
542 uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
543 if (cNsElapsedSys < cNsMinSys)
544 cNsMinSys = cNsElapsedSys;
545 if (cNsElapsed < cNsMin)
546 cNsMin = cNsElapsed;
547 cNsTotalSys += cNsElapsedSys;
548 cNsTotal += cNsElapsed;
549 }
550 if (fSys)
551 {
552 RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
553 RTTestValueF(hTest, cNsTotalSys / 10, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
554 }
555 if (fGip)
556 {
557 RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
558 RTTestValueF(hTest, cNsTotal / 10, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
559 }
560 }
561
562 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
563 }
564
565 }
566
567
568 /*
569 * Done.
570 */
571 return RTTestSummaryAndDestroy(hTest);
572}
573
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