1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
/* $Id$ */
/** @file
* Support Library Testcase - Ring-3 Semaphore interface.
*/
/*
* Copyright (C) 2009-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#include <VBox/sup.h>
#include <VBox/param.h>
#include <iprt/err.h>
#include <iprt/initterm.h>
#include <iprt/message.h>
#include <iprt/stream.h>
#include <iprt/test.h>
#include <iprt/thread.h>
#include <iprt/process.h>
#include <iprt/env.h>
#include <iprt/string.h>
#include <iprt/time.h>
/*********************************************************************************************************************************
* Structures and Typedefs *
*********************************************************************************************************************************/
static PSUPDRVSESSION g_pSession;
static RTTEST g_hTest;
static uint32_t g_cMillies; /* Used by the interruptible tests. */
static DECLCALLBACK(int) tstSupSemInterruptibleSRE(RTTHREAD hSelf, void *pvUser)
{
SUPSEMEVENT hEvent = (SUPSEMEVENT)pvUser;
RTThreadUserSignal(hSelf);
return SUPSemEventWaitNoResume(g_pSession, hEvent, g_cMillies);
}
static DECLCALLBACK(int) tstSupSemInterruptibleMRE(RTTHREAD hSelf, void *pvUser)
{
SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)pvUser;
RTThreadUserSignal(hSelf);
return SUPSemEventMultiWaitNoResume(g_pSession, hEventMulti, g_cMillies);
}
int main(int argc, char **argv)
{
bool fSys = true;
bool fGip = false;
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
fGip = true;
#endif
/*
* Init.
*/
int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
if (argc == 2 && !strcmp(argv[1], "child"))
{
RTThreadSleep(300);
return 0;
}
RTTEST hTest;
rc = RTTestCreate("tstSupSem", &hTest);
if (RT_FAILURE(rc))
{
RTPrintf("tstSupSem: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
return 1;
}
g_hTest = hTest;
PSUPDRVSESSION pSession;
rc = SUPR3Init(&pSession);
if (RT_FAILURE(rc))
{
RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
return RTTestSummaryAndDestroy(hTest);
}
g_pSession = pSession;
RTTestBanner(hTest);
/*
* Basic API checks.
*/
RTTestSub(hTest, "Single Release Event (SRE) API");
SUPSEMEVENT hEvent = NIL_SUPSEMEVENT;
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 20), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,1000),VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 1), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 2), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 8), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VERR_INVALID_HANDLE);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, NIL_SUPSEMEVENT), VINF_SUCCESS);
RTTestSub(hTest, "Multiple Release Event (MRE) API");
SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT;
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,1000), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiReset(pSession, hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 1), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 2), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 8), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 20), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,1000), VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VERR_INVALID_HANDLE);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, NIL_SUPSEMEVENTMULTI), VINF_SUCCESS);
#if !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
RTTestSub(hTest, "SRE Interruptibility");
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
g_cMillies = RT_INDEFINITE_WAIT;
RTTHREAD hThread = NIL_RTTHREAD;
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
RTThreadSleep(120);
RTThreadPoke(hThread);
int rcThread = VINF_SUCCESS;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
g_cMillies = 120*1000;
hThread = NIL_RTTHREAD;
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
RTThreadSleep(120);
RTThreadPoke(hThread);
rcThread = VINF_SUCCESS;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestSub(hTest, "MRE Interruptibility");
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
g_cMillies = RT_INDEFINITE_WAIT;
hThread = NIL_RTTHREAD;
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
RTThreadSleep(120);
RTThreadPoke(hThread);
rcThread = VINF_SUCCESS;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
g_cMillies = 120*1000;
hThread = NIL_RTTHREAD;
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS);
RTThreadSleep(120);
RTThreadPoke(hThread);
rcThread = VINF_SUCCESS;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
/*
* Fork test.
* Spawn a thread waiting for an event, then spawn a new child process (of
* ourselves) and make sure that this does not alter the intended behaviour
* of our event semaphore implementation (see @bugref{5090}).
*/
RTTestSub(hTest, "SRE Process Spawn");
hThread = NIL_RTTHREAD;
g_cMillies = 120*1000;
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
const char *apszArgs[3] = { argv[0], "child", NULL };
RTPROCESS Process = NIL_RTPROCESS;
RTThreadSleep(250);
RTTESTI_CHECK_RC(RTProcCreate(apszArgs[0], apszArgs, RTENV_DEFAULT, 0, &Process), VINF_SUCCESS);
RTThreadSleep(250);
RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
rcThread = VERR_GENERAL_FAILURE;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 120*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestSub(hTest, "MRE Process Spawn");
hThread = NIL_RTTHREAD;
g_cMillies = 120*1000;
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
RTTHREAD hThread2 = NIL_RTTHREAD;
RTTESTI_CHECK_RC(RTThreadCreate(&hThread2, tstSupSemInterruptibleMRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS);
Process = NIL_RTPROCESS;
RTThreadSleep(250);
RTTESTI_CHECK_RC(RTProcCreate(apszArgs[0], apszArgs, RTENV_DEFAULT, 0, &Process), VINF_SUCCESS);
RTThreadSleep(250);
RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEvent), VINF_SUCCESS);
rcThread = VERR_GENERAL_FAILURE;
RTTESTI_CHECK_RC(RTThreadWait(hThread, 120*1000, &rcThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread, VINF_SUCCESS);
int rcThread2 = VERR_GENERAL_FAILURE;
RTTESTI_CHECK_RC(RTThreadWait(hThread2, 120*1000, &rcThread2), VINF_SUCCESS);
RTTESTI_CHECK_RC(rcThread2, VINF_SUCCESS);
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
#endif /* !OS2 && !WINDOWS */
{
#define LOOP_COUNT 20
static unsigned const s_acMsIntervals[] = { 0, 1, 2, 3, 4, 8, 10, 16, 32 };
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "SRE Timeout Accuracy (ms)");
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acMsIntervals); i++)
{
uint64_t cMs = s_acMsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
int rcX = SUPSemEventWaitNoResume(pSession, hEvent, cMs);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cMs=%u", rcX, cLoops, cMs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%u ms min (clock=sys)", cMs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%u ms avg (clock=sys)", cMs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%u ms min (clock=gip)", cMs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%u ms avg (clock=gip)", cMs);
}
}
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "MRE Timeout Accuracy (ms)");
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acMsIntervals); i++)
{
uint64_t cMs = s_acMsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
int rcX = SUPSemEventMultiWaitNoResume(pSession, hEvent, cMs);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cMs=%u", rcX, cLoops, cMs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%u ms min (clock=sys)", cMs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%u ms avg (clock=sys)", cMs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%u ms min (clock=gip)", cMs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%u ms avg (clock=gip)", cMs);
}
}
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
}
{
static uint32_t const s_acNsIntervals[] =
{
0, 1000, 5000, 15000, 30000, 50000, 100000, 250000, 500000, 750000, 900000, 1500000, 2200000
};
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "SUPSemEventWaitNsRelIntr Accuracy");
RTTestValueF(hTest, SUPSemEventGetResolution(pSession), RTTESTUNIT_NS, "SRE resolution");
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
{
uint64_t cNs = s_acNsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
int rcX = SUPSemEventWaitNsRelIntr(pSession, hEvent, cNs);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cNs=%u", rcX, cLoops, cNs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
}
}
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "SUPSemEventMultiWaitNsRelIntr Accuracy");
RTTestValueF(hTest, SUPSemEventMultiGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
{
uint64_t cNs = s_acNsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
int rcX = SUPSemEventMultiWaitNsRelIntr(pSession, hEvent, cNs);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cNs=%u", rcX, cLoops, cNs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
}
}
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "SUPSemEventWaitNsAbsIntr Accuracy");
RTTestValueF(hTest, SUPSemEventGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
{
uint64_t cNs = s_acNsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
uint64_t uAbsDeadline = (fGip ? u64Start : u64StartSys) + cNs;
int rcX = SUPSemEventWaitNsAbsIntr(pSession, hEvent, uAbsDeadline);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cNs=%u", rcX, cLoops, cNs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
}
}
RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
if (RTTestErrorCount(hTest) == 0)
{
RTTestSub(hTest, "SUPSemEventMultiWaitNsAbsIntr Accuracy");
RTTestValueF(hTest, SUPSemEventMultiGetResolution(pSession), RTTESTUNIT_NS, "MRE resolution");
RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEvent), VINF_SUCCESS);
uint32_t cInterrupted = 0;
for (unsigned i = 0; i < RT_ELEMENTS(s_acNsIntervals); i++)
{
uint64_t cNs = s_acNsIntervals[i];
uint64_t cNsMinSys = UINT64_MAX;
uint64_t cNsMin = UINT64_MAX;
uint64_t cNsTotalSys= 0;
uint64_t cNsTotal = 0;
unsigned cLoops = 0;
while (cLoops < LOOP_COUNT)
{
uint64_t u64StartSys = RTTimeSystemNanoTS();
uint64_t u64Start = RTTimeNanoTS();
uint64_t uAbsDeadline = (fGip ? u64Start : u64StartSys) + cNs;
int rcX = SUPSemEventMultiWaitNsAbsIntr(pSession, hEvent, uAbsDeadline);
uint64_t cNsElapsedSys = RTTimeSystemNanoTS() - u64StartSys;
uint64_t cNsElapsed = RTTimeNanoTS() - u64Start;
if (rcX == VERR_INTERRUPTED)
{
cInterrupted++;
continue; /* retry */
}
if (rcX != VERR_TIMEOUT)
RTTestFailed(hTest, "%Rrc cLoops=%u cNs=%u", rcX, cLoops, cNs);
if (cNsElapsedSys < cNsMinSys)
cNsMinSys = cNsElapsedSys;
if (cNsElapsed < cNsMin)
cNsMin = cNsElapsed;
cNsTotalSys += cNsElapsedSys;
cNsTotal += cNsElapsed;
cLoops++;
}
if (fSys)
{
RTTestValueF(hTest, cNsMinSys, RTTESTUNIT_NS, "%'u ns min (clock=sys)", cNs);
RTTestValueF(hTest, cNsTotalSys / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=sys)", cNs);
}
if (fGip)
{
RTTestValueF(hTest, cNsMin, RTTESTUNIT_NS, "%'u ns min (clock=gip)", cNs);
RTTestValueF(hTest, cNsTotal / cLoops, RTTESTUNIT_NS, "%'u ns avg (clock=gip)", cNs);
}
}
RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
RTTestValueF(hTest, cInterrupted, RTTESTUNIT_OCCURRENCES, "VERR_INTERRUPTED returned");
}
}
/*
* Done.
*/
return RTTestSummaryAndDestroy(hTest);
}
|