VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTSemRW.cpp@ 59675

Last change on this file since 59675 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 20.2 KB
Line 
1/* $Id: tstRTSemRW.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Reader/Writer Semaphore.
4 */
5
6/*
7 * Copyright (C) 2009-2015 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 <iprt/semaphore.h>
32
33#include <iprt/asm.h>
34#include <iprt/assert.h>
35#include <iprt/err.h>
36#include <iprt/initterm.h>
37#include <iprt/lockvalidator.h>
38#include <iprt/rand.h>
39#include <iprt/string.h>
40#include <iprt/stream.h>
41#include <iprt/test.h>
42#include <iprt/time.h>
43#include <iprt/thread.h>
44
45
46/*********************************************************************************************************************************
47* Global Variables *
48*********************************************************************************************************************************/
49static RTTEST g_hTest;
50static RTSEMRW g_hSemRW = NIL_RTSEMRW;
51static bool volatile g_fTerminate;
52static bool g_fYield;
53static bool g_fQuiet;
54static unsigned g_uWritePercent;
55static uint32_t volatile g_cConcurrentWriters;
56static uint32_t volatile g_cConcurrentReaders;
57
58
59static DECLCALLBACK(int) Test4Thread(RTTHREAD ThreadSelf, void *pvUser)
60{
61 /* Use randomization to get a little more variation of the sync pattern.
62 We use a pseudo random generator here so that we don't end up testing
63 the speed of the /dev/urandom implementation, but rather the read-write
64 semaphores. */
65 int rc;
66 RTRAND hRand;
67 RTTEST_CHECK_RC_OK_RET(g_hTest, rc = RTRandAdvCreateParkMiller(&hRand), rc);
68 RTTEST_CHECK_RC_OK_RET(g_hTest, rc = RTRandAdvSeed(hRand, (uintptr_t)ThreadSelf), rc);
69 unsigned c100 = RTRandAdvU32Ex(hRand, 0, 99);
70
71 uint64_t *pcItr = (uint64_t *)pvUser;
72 bool fWrite;
73 for (;;)
74 {
75 unsigned readrec = RTRandAdvU32Ex(hRand, 0, 3);
76 unsigned writerec = RTRandAdvU32Ex(hRand, 0, 3);
77 /* Don't overdo recursion testing. */
78 if (readrec > 1)
79 readrec--;
80 if (writerec > 1)
81 writerec--;
82
83 fWrite = (c100 < g_uWritePercent);
84 if (fWrite)
85 {
86 for (unsigned i = 0; i <= writerec; i++)
87 {
88 rc = RTSemRWRequestWriteNoResume(g_hSemRW, RT_INDEFINITE_WAIT);
89 if (RT_FAILURE(rc))
90 {
91 RTTestFailed(g_hTest, "Write recursion %u on %s failed with rc=%Rrc", i, RTThreadSelfName(), rc);
92 break;
93 }
94 }
95 if (RT_FAILURE(rc))
96 break;
97 if (ASMAtomicIncU32(&g_cConcurrentWriters) != 1)
98 {
99 RTTestFailed(g_hTest, "g_cConcurrentWriters=%u on %s after write locking it",
100 g_cConcurrentWriters, RTThreadSelfName());
101 break;
102 }
103 if (g_cConcurrentReaders != 0)
104 {
105 RTTestFailed(g_hTest, "g_cConcurrentReaders=%u on %s after write locking it",
106 g_cConcurrentReaders, RTThreadSelfName());
107 break;
108 }
109 }
110 else
111 {
112 rc = RTSemRWRequestReadNoResume(g_hSemRW, RT_INDEFINITE_WAIT);
113 if (RT_FAILURE(rc))
114 {
115 RTTestFailed(g_hTest, "Read locking on %s failed with rc=%Rrc", RTThreadSelfName(), rc);
116 break;
117 }
118 ASMAtomicIncU32(&g_cConcurrentReaders);
119 if (g_cConcurrentWriters != 0)
120 {
121 RTTestFailed(g_hTest, "g_cConcurrentWriters=%u on %s after read locking it",
122 g_cConcurrentWriters, RTThreadSelfName());
123 break;
124 }
125 }
126 for (unsigned i = 0; i < readrec; i++)
127 {
128 rc = RTSemRWRequestReadNoResume(g_hSemRW, RT_INDEFINITE_WAIT);
129 if (RT_FAILURE(rc))
130 {
131 RTTestFailed(g_hTest, "Read recursion %u on %s failed with rc=%Rrc", i, RTThreadSelfName(), rc);
132 break;
133 }
134 }
135 if (RT_FAILURE(rc))
136 break;
137
138 /*
139 * Check for fairness: The values of the threads should not differ too much
140 */
141 (*pcItr)++;
142
143 /*
144 * Check for correctness: Give other threads a chance. If the implementation is
145 * correct, no other thread will be able to enter this lock now.
146 */
147 if (g_fYield)
148 RTThreadYield();
149
150 for (unsigned i = 0; i < readrec; i++)
151 {
152 rc = RTSemRWReleaseRead(g_hSemRW);
153 if (RT_FAILURE(rc))
154 {
155 RTTestFailed(g_hTest, "Read release %u on %s failed with rc=%Rrc", i, RTThreadSelfName(), rc);
156 break;
157 }
158 }
159 if (RT_FAILURE(rc))
160 break;
161
162 if (fWrite)
163 {
164 if (ASMAtomicDecU32(&g_cConcurrentWriters) != 0)
165 {
166 RTTestFailed(g_hTest, "g_cConcurrentWriters=%u on %s before write release",
167 g_cConcurrentWriters, RTThreadSelfName());
168 break;
169 }
170 if (g_cConcurrentReaders != 0)
171 {
172 RTTestFailed(g_hTest, "g_cConcurrentReaders=%u on %s before write release",
173 g_cConcurrentReaders, RTThreadSelfName());
174 break;
175 }
176 for (unsigned i = 0; i <= writerec; i++)
177 {
178 rc = RTSemRWReleaseWrite(g_hSemRW);
179 if (RT_FAILURE(rc))
180 {
181 RTTestFailed(g_hTest, "Write release %u on %s failed with rc=%Rrc", i, RTThreadSelfName(), rc);
182 break;
183 }
184 }
185 }
186 else
187 {
188 if (g_cConcurrentWriters != 0)
189 {
190 RTTestFailed(g_hTest, "g_cConcurrentWriters=%u on %s before read release",
191 g_cConcurrentWriters, RTThreadSelfName());
192 break;
193 }
194 ASMAtomicDecU32(&g_cConcurrentReaders);
195 rc = RTSemRWReleaseRead(g_hSemRW);
196 if (RT_FAILURE(rc))
197 {
198 RTTestFailed(g_hTest, "Read release on %s failed with rc=%Rrc", RTThreadSelfName(), rc);
199 break;
200 }
201 }
202
203 if (g_fTerminate)
204 break;
205
206 c100++;
207 c100 %= 100;
208 }
209 if (!g_fQuiet)
210 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Thread %s exited with %lld\n", RTThreadSelfName(), *pcItr);
211 RTRandAdvDestroy(hRand);
212 return VINF_SUCCESS;
213}
214
215
216static void Test4(unsigned cThreads, unsigned cSeconds, unsigned uWritePercent, bool fYield, bool fQuiet)
217{
218 unsigned i;
219 uint64_t acIterations[32];
220 RTTHREAD aThreads[RT_ELEMENTS(acIterations)];
221 AssertRelease(cThreads <= RT_ELEMENTS(acIterations));
222
223 RTTestSubF(g_hTest, "Test4 - %u threads, %u sec, %u%% writes, %syielding",
224 cThreads, cSeconds, uWritePercent, fYield ? "" : "non-");
225
226 /*
227 * Init globals.
228 */
229 g_fYield = fYield;
230 g_fQuiet = fQuiet;
231 g_fTerminate = false;
232 g_uWritePercent = uWritePercent;
233 g_cConcurrentWriters = 0;
234 g_cConcurrentReaders = 0;
235
236 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreate(&g_hSemRW), VINF_SUCCESS);
237
238 /*
239 * Create the threads and let them block on the semrw.
240 */
241 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWRequestWrite(g_hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS);
242
243 for (i = 0; i < cThreads; i++)
244 {
245 acIterations[i] = 0;
246 RTTEST_CHECK_RC_RETV(g_hTest, RTThreadCreateF(&aThreads[i], Test4Thread, &acIterations[i], 0,
247 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE,
248 "test-%u", i), VINF_SUCCESS);
249 }
250
251 /*
252 * Do the test run.
253 */
254 uint32_t cErrorsBefore = RTTestErrorCount(g_hTest);
255 uint64_t u64StartTS = RTTimeNanoTS();
256 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_hSemRW), VINF_SUCCESS);
257 RTThreadSleep(cSeconds * 1000);
258 ASMAtomicWriteBool(&g_fTerminate, true);
259 uint64_t ElapsedNS = RTTimeNanoTS() - u64StartTS;
260
261 /*
262 * Clean up the threads and semaphore.
263 */
264 for (i = 0; i < cThreads; i++)
265 RTTEST_CHECK_RC(g_hTest, RTThreadWait(aThreads[i], 5000, NULL), VINF_SUCCESS);
266
267 RTTEST_CHECK_MSG(g_hTest, g_cConcurrentWriters == 0, (g_hTest, "g_cConcurrentWriters=%u at end of test\n", g_cConcurrentWriters));
268 RTTEST_CHECK_MSG(g_hTest, g_cConcurrentReaders == 0, (g_hTest, "g_cConcurrentReaders=%u at end of test\n", g_cConcurrentReaders));
269
270 RTTEST_CHECK_RC(g_hTest, RTSemRWDestroy(g_hSemRW), VINF_SUCCESS);
271 g_hSemRW = NIL_RTSEMRW;
272
273 if (RTTestErrorCount(g_hTest) != cErrorsBefore)
274 RTThreadSleep(100);
275
276 /*
277 * Collect and display the results.
278 */
279 uint64_t cItrTotal = acIterations[0];
280 for (i = 1; i < cThreads; i++)
281 cItrTotal += acIterations[i];
282
283 uint64_t cItrNormal = cItrTotal / cThreads;
284 uint64_t cItrMinOK = cItrNormal / 20; /* 5% */
285 uint64_t cItrMaxDeviation = 0;
286 for (i = 0; i < cThreads; i++)
287 {
288 uint64_t cItrDelta = RT_ABS((int64_t)(acIterations[i] - cItrNormal));
289 if (acIterations[i] < cItrMinOK)
290 RTTestFailed(g_hTest, "Thread %u did less than 5%% of the iterations - %llu (it) vs. %llu (5%%) - %llu%%\n",
291 i, acIterations[i], cItrMinOK, cItrDelta * 100 / cItrNormal);
292 else if (cItrDelta > cItrNormal / 2)
293 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
294 "Warning! Thread %u deviates by more than 50%% - %llu (it) vs. %llu (avg) - %llu%%\n",
295 i, acIterations[i], cItrNormal, cItrDelta * 100 / cItrNormal);
296 if (cItrDelta > cItrMaxDeviation)
297 cItrMaxDeviation = cItrDelta;
298
299 }
300
301 //RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
302 // "Threads: %u Total: %llu Per Sec: %llu Avg: %llu ns Max dev: %llu%%\n",
303 // cThreads,
304 // cItrTotal,
305 // cItrTotal / cSeconds,
306 // ElapsedNS / cItrTotal,
307 // cItrMaxDeviation * 100 / cItrNormal
308 // );
309 //
310 RTTestValue(g_hTest, "Thruput", cItrTotal * UINT32_C(1000000000) / ElapsedNS, RTTESTUNIT_CALLS_PER_SEC);
311 RTTestValue(g_hTest, "Max diviation", cItrMaxDeviation * 100 / cItrNormal, RTTESTUNIT_PCT);
312}
313
314
315static DECLCALLBACK(int) Test2Thread(RTTHREAD hThreadSelf, void *pvUser)
316{
317 RTSEMRW hSemRW = (RTSEMRW)pvUser;
318
319 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestRead(hSemRW, 0), VERR_TIMEOUT);
320 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(hSemRW, 0), VERR_TIMEOUT);
321
322 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestRead(hSemRW, 1), VERR_TIMEOUT);
323 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(hSemRW, 1), VERR_TIMEOUT);
324
325 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestRead(hSemRW, 50), VERR_TIMEOUT);
326 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(hSemRW, 50), VERR_TIMEOUT);
327
328 return VINF_SUCCESS;
329}
330
331
332static void Test3(void)
333{
334 RTTestSub(g_hTest, "Negative");
335 bool fSavedAssertQuiet = RTAssertSetQuiet(true);
336 bool fSavedAssertMayPanic = RTAssertSetMayPanic(false);
337 bool fSavedLckValEnabled = RTLockValidatorSetEnabled(false);
338
339 RTSEMRW hSemRW;
340 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreate(&hSemRW), VINF_SUCCESS);
341
342 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead(hSemRW), VERR_NOT_OWNER);
343 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(hSemRW), VERR_NOT_OWNER);
344
345 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS);
346 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead(hSemRW), VERR_NOT_OWNER);
347
348 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestRead(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS);
349 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(hSemRW), VERR_WRONG_ORDER); /* cannot release the final write before the reads. */
350 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS);
351 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS);
352
353 RTTEST_CHECK_RC(g_hTest, RTSemRWDestroy(hSemRW), VINF_SUCCESS);
354
355 RTLockValidatorSetEnabled(fSavedLckValEnabled);
356 RTAssertSetMayPanic(fSavedAssertMayPanic);
357 RTAssertSetQuiet(fSavedAssertQuiet);
358}
359
360static void Test2(void)
361{
362 RTTestSub(g_hTest, "Timeout");
363
364 RTSEMRW hSemRW = NIL_RTSEMRW;
365 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreate(&hSemRW), VINF_SUCCESS);
366
367 /* Lock it for writing and let the thread do the remainder of the test. */
368 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWRequestWrite(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS);
369
370 RTTHREAD hThread;
371 RTTEST_CHECK_RC_RETV(g_hTest, RTThreadCreate(&hThread, Test2Thread, hSemRW, 0,
372 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test2"),
373 VINF_SUCCESS);
374 RTTEST_CHECK_RC(g_hTest, RTThreadWait(hThread, 15000, NULL), VINF_SUCCESS);
375 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS);
376
377 RTTEST_CHECK_RC(g_hTest, RTSemRWDestroy(hSemRW), VINF_SUCCESS);
378}
379
380
381static bool Test1(void)
382{
383 RTTestSub(g_hTest, "Basics");
384
385 RTSEMRW hSemRW = NIL_RTSEMRW;
386 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWCreate(&hSemRW), VINF_SUCCESS, false);
387 RTTEST_CHECK_RET(g_hTest, hSemRW != NIL_RTSEMRW, false);
388
389 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS, false);
390 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS, false);
391
392 for (unsigned cMs = 0; cMs < 50; cMs++)
393 {
394 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hSemRW, cMs), VINF_SUCCESS, false);
395 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hSemRW, cMs), VINF_SUCCESS, false);
396 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS, false);
397 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS, false);
398 }
399
400 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS, false);
401 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS, false);
402
403 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS, false);
404 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hSemRW, RT_INDEFINITE_WAIT), VINF_SUCCESS, false);
405 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS, false);
406 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS, false);
407
408 for (unsigned cMs = 0; cMs < 50; cMs++)
409 {
410 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hSemRW, cMs), VINF_SUCCESS, false);
411 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 1, false);
412 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 0, false);
413 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
414
415 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hSemRW, cMs), VINF_SUCCESS, false);
416 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 2, false);
417 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 0, false);
418 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
419
420 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hSemRW, cMs), VINF_SUCCESS, false);
421 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 2, false);
422 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 1, false);
423 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
424
425 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hSemRW, cMs), VINF_SUCCESS, false);
426 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 3, false);
427 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 1, false);
428 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
429
430 /* midway */
431
432 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS, false);
433 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 2, false);
434 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 1, false);
435 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
436
437 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseRead(hSemRW), VINF_SUCCESS, false);
438 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 2, false);
439 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 0, false);
440 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
441
442 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS, false);
443 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 1, false);
444 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 0, false);
445 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == true, false);
446
447 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWReleaseWrite(hSemRW), VINF_SUCCESS, false);
448 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriteRecursion(hSemRW) == 0, false);
449 RTTEST_CHECK_RET(g_hTest, RTSemRWGetWriterReadRecursion(hSemRW) == 0, false);
450 RTTEST_CHECK_RET(g_hTest, RTSemRWIsWriteOwner(hSemRW) == false, false);
451 }
452
453 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWDestroy(hSemRW), VINF_SUCCESS, false);
454 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWDestroy(NIL_RTSEMRW), VINF_SUCCESS, false);
455
456 return true;
457}
458
459int main(int argc, char **argv)
460{
461 int rc = RTTestInitAndCreate("tstRTSemRW", &g_hTest);
462 if (rc)
463 return 1;
464 RTTestBanner(g_hTest);
465
466 if (Test1())
467 {
468 if (argc == 1)
469 {
470 Test2();
471 Test3();
472
473 /* threads, seconds, writePercent, yield, quiet */
474 Test4( 1, 1, 0, true, false);
475 Test4( 1, 1, 1, true, false);
476 Test4( 1, 1, 5, true, false);
477 Test4( 2, 1, 3, true, false);
478 Test4( 10, 1, 5, true, false);
479 Test4( 10, 10, 10, false, false);
480
481 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "benchmarking...\n");
482 for (unsigned cThreads = 1; cThreads < 32; cThreads++)
483 Test4(cThreads, 2, 1, false, true);
484
485 /** @todo add a testcase where some stuff times out. */
486 }
487 else
488 {
489 /* threads, seconds, writePercent, yield, quiet */
490 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "benchmarking...\n");
491 Test4( 1, 3, 1, false, true);
492 Test4( 1, 3, 1, false, true);
493 Test4( 1, 3, 1, false, true);
494 Test4( 2, 3, 1, false, true);
495 Test4( 2, 3, 1, false, true);
496 Test4( 2, 3, 1, false, true);
497 Test4( 3, 3, 1, false, true);
498 Test4( 3, 3, 1, false, true);
499 Test4( 3, 3, 1, false, true);
500 }
501 }
502
503 return RTTestSummaryAndDestroy(g_hTest);
504}
505
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