VirtualBox

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

Last change on this file since 40282 was 38636, checked in by vboxsync, 13 years ago

*,IPRT: Redid the ring-3 init to always convert the arguments to UTF-8.

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