VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTPoll.cpp@ 27123

Last change on this file since 27123 was 26844, checked in by vboxsync, 15 years ago

RTPollSetCount.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/* $Id: tstRTPoll.cpp 26844 2010-02-26 13:03:11Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTPoll.
4 */
5
6/*
7 * Copyright (C) 2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/poll.h>
36
37#include <iprt/err.h>
38#include <iprt/file.h>
39#include <iprt/mem.h>
40#include <iprt/pipe.h>
41#include <iprt/string.h>
42#include <iprt/test.h>
43
44
45static void tstRTPoll2(void)
46{
47 RTTestISub("Negative");
48
49 /*
50 * Bad set pointer and handle values.
51 */
52 RTTESTI_CHECK_RC(RTPollSetCreate(NULL), VERR_INVALID_POINTER);
53 RTPOLLSET hSetInvl = (RTPOLLSET)(intptr_t)-3;
54 RTTESTI_CHECK_RC(RTPollSetDestroy(hSetInvl), VERR_INVALID_HANDLE);
55 RTHANDLE Handle;
56 Handle.enmType = RTHANDLETYPE_PIPE;
57 Handle.u.hPipe = NIL_RTPIPE;
58 RTTESTI_CHECK_RC(RTPollSetAdd(hSetInvl, &Handle, RTPOLL_EVT_ERROR, 1), VERR_INVALID_HANDLE);
59 RTTESTI_CHECK_RC(RTPollSetRemove(hSetInvl, 1), VERR_INVALID_HANDLE);
60 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSetInvl, 1, NULL), VERR_INVALID_HANDLE);
61 RTTESTI_CHECK(RTPollSetCount(hSetInvl) == UINT32_MAX);
62 RTTESTI_CHECK_RC(RTPoll(hSetInvl, 0, NULL, NULL), VERR_INVALID_HANDLE);
63 RTTESTI_CHECK_RC(RTPollNoResume(hSetInvl, 0, NULL, NULL), VERR_INVALID_HANDLE);
64
65 /*
66 * Invalid arguments and other stuff.
67 */
68 RTPOLLSET hSet = NIL_RTPOLLSET;
69 RTTESTI_CHECK_RC_RETV(RTPollSetCreate(&hSet), VINF_SUCCESS);
70
71 RTTESTI_CHECK_RC(RTPoll(hSet, RT_INDEFINITE_WAIT, NULL, NULL), VERR_DEADLOCK);
72 RTTESTI_CHECK_RC(RTPollNoResume(hSet, RT_INDEFINITE_WAIT, NULL, NULL), VERR_DEADLOCK);
73
74 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, UINT32_MAX), VERR_INVALID_PARAMETER);
75 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1, NULL), VERR_POLL_HANDLE_ID_NOT_FOUND);
76
77 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 1), VERR_POLL_HANDLE_ID_NOT_FOUND);
78
79 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, NULL, RTPOLL_EVT_ERROR, 1), VINF_SUCCESS);
80 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, &Handle, RTPOLL_EVT_ERROR, UINT32_MAX), VERR_INVALID_PARAMETER);
81 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, &Handle, UINT32_MAX, 3), VERR_INVALID_PARAMETER);
82 Handle.enmType = RTHANDLETYPE_INVALID;
83 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, &Handle, RTPOLL_EVT_ERROR, 3), VERR_INVALID_PARAMETER);
84 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, NULL, RTPOLL_EVT_ERROR, UINT32_MAX), VERR_INVALID_PARAMETER);
85
86 /* duplicate id */
87 RTPIPE hPipeR;
88 RTPIPE hPipeW;
89 RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0/*fFlags*/), VINF_SUCCESS);
90 RTTESTI_CHECK_RC(RTPollSetAddPipe(hSet, hPipeR, RTPOLL_EVT_ERROR, 0), VINF_SUCCESS);
91 RTTESTI_CHECK_RC(RTPollSetAddPipe(hSet, hPipeR, RTPOLL_EVT_ERROR, 0), VERR_POLL_HANDLE_ID_EXISTS);
92 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 0), VINF_SUCCESS);
93 RTPipeClose(hPipeR);
94 RTPipeClose(hPipeW);
95
96 /* non-pollable handle */
97 RTFILE hBitBucket;
98 RTTESTI_CHECK_RC_RETV(RTFileOpenBitBucket(&hBitBucket, RTFILE_O_WRITE), VINF_SUCCESS);
99 Handle.enmType = RTHANDLETYPE_FILE;
100 Handle.u.hFile = hBitBucket;
101 RTTESTI_CHECK_RC(RTPollSetAdd(hSet, &Handle, RTPOLL_EVT_WRITE, 10), VERR_POLL_HANDLE_NOT_POLLABLE);
102 RTFileClose(hBitBucket);
103
104 RTTESTI_CHECK_RC_RETV(RTPollSetDestroy(hSet), VINF_SUCCESS);
105
106
107
108}
109
110
111static void tstRTPoll1(void)
112{
113 RTTestISub("Basics");
114
115 /* create and destroy. */
116 RTPOLLSET hSet = NIL_RTPOLLSET;
117 RTTESTI_CHECK_RC_RETV(RTPollSetCreate(&hSet), VINF_SUCCESS);
118 RTTESTI_CHECK_RETV(hSet != NIL_RTPOLLSET);
119 RTTESTI_CHECK_RC(RTPollSetDestroy(hSet), VINF_SUCCESS);
120 RTTESTI_CHECK_RC(RTPollSetDestroy(NIL_RTPOLLSET), VINF_SUCCESS);
121
122 /* empty set, adding a NIL handle. */
123 hSet = NIL_RTPOLLSET;
124 RTTESTI_CHECK_RC_RETV(RTPollSetCreate(&hSet), VINF_SUCCESS);
125 RTTESTI_CHECK_RETV(hSet != NIL_RTPOLLSET);
126
127 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 0);
128 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 0, NULL), VERR_POLL_HANDLE_ID_NOT_FOUND);
129
130 RTTESTI_CHECK_RC(RTPollSetAddPipe(hSet, NIL_RTPIPE, RTPOLL_EVT_READ, 1 /*id*/), VINF_SUCCESS);
131 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 0);
132 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1 /*id*/, NULL), VERR_POLL_HANDLE_ID_NOT_FOUND);
133 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 0), VERR_POLL_HANDLE_ID_NOT_FOUND);
134 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 0);
135
136 RTTESTI_CHECK_RC(RTPollSetDestroy(hSet), VINF_SUCCESS);
137
138 /*
139 * Set with pipes
140 */
141 RTPIPE hPipeR;
142 RTPIPE hPipeW;
143 RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0/*fFlags*/), VINF_SUCCESS);
144
145 hSet = NIL_RTPOLLSET;
146 RTTESTI_CHECK_RC_RETV(RTPollSetCreate(&hSet), VINF_SUCCESS);
147 RTTESTI_CHECK_RETV(hSet != NIL_RTPOLLSET);
148
149 /* add the read pipe */
150 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeR, RTPOLL_EVT_READ, 1 /*id*/), VINF_SUCCESS);
151 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 1);
152 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1 /*id*/, NULL), VINF_SUCCESS);
153 RTHANDLE Handle;
154 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 1 /*id*/, &Handle), VINF_SUCCESS);
155 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
156 RTTESTI_CHECK(Handle.u.hPipe == hPipeR);
157
158 /* poll on the set, should time out. */
159 RTTESTI_CHECK_RC(RTPoll(hSet, 0, NULL, NULL), VERR_TIMEOUT);
160 RTTESTI_CHECK_RC(RTPoll(hSet, 1, NULL, NULL), VERR_TIMEOUT);
161
162 /* add the write pipe */
163 RTTESTI_CHECK_RC(RTPollSetAddPipe(hSet, hPipeW, RTPOLL_EVT_WRITE, 10 /*id*/), VINF_SUCCESS);
164 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 2);
165 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 10 /*id*/, NULL), VINF_SUCCESS);
166
167 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 10 /*id*/, &Handle), VINF_SUCCESS);
168 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
169 RTTESTI_CHECK(Handle.u.hPipe == hPipeW);
170
171 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 1 /*id*/, &Handle), VINF_SUCCESS);
172 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
173 RTTESTI_CHECK(Handle.u.hPipe == hPipeR);
174
175 /* poll on the set again, now it should indicate hPipeW is ready. */
176 int rc;
177 RTTESTI_CHECK_RC(RTPoll(hSet, 0, NULL, NULL), VINF_SUCCESS);
178 RTTESTI_CHECK_RC(rc = RTPoll(hSet, 100, NULL, NULL), VINF_SUCCESS);
179 if (RT_SUCCESS(rc))
180 RTTESTI_CHECK_RC(RTPoll(hSet, RT_INDEFINITE_WAIT, NULL, NULL), VINF_SUCCESS);
181
182 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, 0, NULL, NULL), VINF_SUCCESS);
183 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, 100, NULL, NULL), VINF_SUCCESS);
184 if (RT_SUCCESS(rc))
185 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, RT_INDEFINITE_WAIT, NULL, NULL), VINF_SUCCESS);
186
187 uint32_t fEvents = UINT32_MAX;
188 uint32_t id = UINT32_MAX;
189 RTTESTI_CHECK_RC(RTPoll(hSet, 0, &fEvents, &id), VINF_SUCCESS);
190 RTTESTI_CHECK(id == 10);
191 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
192
193 fEvents = UINT32_MAX;
194 id = UINT32_MAX;
195 RTTESTI_CHECK_RC(rc = RTPoll(hSet, 250, &fEvents, &id), VINF_SUCCESS);
196 RTTESTI_CHECK(id == 10);
197 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
198
199 if (RT_SUCCESS(rc))
200 {
201 fEvents = UINT32_MAX;
202 id = UINT32_MAX;
203 RTTESTI_CHECK_RC(RTPoll(hSet, RT_INDEFINITE_WAIT, &fEvents, &id), VINF_SUCCESS);
204 RTTESTI_CHECK(id == 10);
205 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
206 }
207
208 fEvents = UINT32_MAX;
209 id = UINT32_MAX;
210 RTTESTI_CHECK_RC(RTPollNoResume(hSet, 0, &fEvents, &id), VINF_SUCCESS);
211 RTTESTI_CHECK(id == 10);
212 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
213
214 fEvents = UINT32_MAX;
215 id = UINT32_MAX;
216 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, 100, &fEvents, &id), VINF_SUCCESS);
217 RTTESTI_CHECK(id == 10);
218 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
219
220 if (RT_SUCCESS(rc))
221 {
222 fEvents = UINT32_MAX;
223 id = UINT32_MAX;
224 RTTESTI_CHECK_RC(RTPollNoResume(hSet, RT_INDEFINITE_WAIT, &fEvents, &id), VINF_SUCCESS);
225 RTTESTI_CHECK(id == 10);
226 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
227 }
228
229 /* Write to the pipe. Currently ASSUMING we'll get the read ready now... Good idea? */
230 RTTESTI_CHECK_RC(rc = RTPipeWriteBlocking(hPipeW, "hello", 5, NULL), VINF_SUCCESS);
231 if (RT_SUCCESS(rc))
232 {
233 fEvents = UINT32_MAX;
234 id = UINT32_MAX;
235 RTTESTI_CHECK_RC(RTPoll(hSet, 0, &fEvents, &id), VINF_SUCCESS);
236 RTTESTI_CHECK(id == 1);
237 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
238
239 fEvents = UINT32_MAX;
240 id = UINT32_MAX;
241 RTTESTI_CHECK_RC(rc = RTPoll(hSet, 256, &fEvents, &id), VINF_SUCCESS);
242 RTTESTI_CHECK(id == 1);
243 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
244
245 if (RT_SUCCESS(rc))
246 {
247 fEvents = UINT32_MAX;
248 id = UINT32_MAX;
249 RTTESTI_CHECK_RC(RTPoll(hSet, RT_INDEFINITE_WAIT, &fEvents, &id), VINF_SUCCESS);
250 RTTESTI_CHECK(id == 1);
251 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
252 }
253
254 fEvents = UINT32_MAX;
255 id = UINT32_MAX;
256 RTTESTI_CHECK_RC(RTPollNoResume(hSet, 0, &fEvents, &id), VINF_SUCCESS);
257 RTTESTI_CHECK(id == 1);
258 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
259
260 fEvents = UINT32_MAX;
261 id = UINT32_MAX;
262 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, 383, &fEvents, &id), VINF_SUCCESS);
263 RTTESTI_CHECK(id == 1);
264 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
265
266 if (RT_SUCCESS(rc))
267 {
268 fEvents = UINT32_MAX;
269 id = UINT32_MAX;
270 RTTESTI_CHECK_RC(RTPollNoResume(hSet, RT_INDEFINITE_WAIT, &fEvents, &id), VINF_SUCCESS);
271 RTTESTI_CHECK(id == 1);
272 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
273 }
274 }
275
276 /* Remove the read pipe, do a quick poll check. */
277 RTTESTI_CHECK_RC_RETV(RTPollSetRemove(hSet, 1), VINF_SUCCESS);
278 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 1);
279 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1 /*id*/, NULL), VERR_POLL_HANDLE_ID_NOT_FOUND);
280 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 10 /*id*/, &Handle), VINF_SUCCESS);
281 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
282 RTTESTI_CHECK(Handle.u.hPipe == hPipeW);
283
284 RTTESTI_CHECK_RC(RTPoll(hSet, 0, NULL, NULL), VINF_SUCCESS);
285
286 /* Add it back and check that we now get the write handle when polling.
287 (Is this FIFOing a good idea?) */
288 RTTESTI_CHECK_RC_RETV(RTPoll(hSet, 0, NULL, NULL), VINF_SUCCESS);
289
290 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeR, RTPOLL_EVT_READ, 1 /*id*/), VINF_SUCCESS);
291 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 2);
292 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1 /*id*/, NULL), VINF_SUCCESS);
293
294 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 1 /*id*/, &Handle), VINF_SUCCESS);
295 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
296 RTTESTI_CHECK(Handle.u.hPipe == hPipeR);
297
298 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 10 /*id*/, &Handle), VINF_SUCCESS);
299 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
300 RTTESTI_CHECK(Handle.u.hPipe == hPipeW);
301
302 fEvents = UINT32_MAX;
303 id = UINT32_MAX;
304 RTTESTI_CHECK_RC(rc = RTPollNoResume(hSet, 555, &fEvents, &id), VINF_SUCCESS);
305 RTTESTI_CHECK(id == 10);
306 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
307
308 /* Remove it again and break the pipe by closing the read end. */
309 RTTESTI_CHECK_RC_RETV(RTPollSetRemove(hSet, 1), VINF_SUCCESS);
310 RTTESTI_CHECK_RETV(RTPollSetCount(hSet) == 1);
311 RTTESTI_CHECK_RC(RTPollSetQueryHandle(hSet, 1 /*id*/, NULL), VERR_POLL_HANDLE_ID_NOT_FOUND);
312 RTTESTI_CHECK_RC_RETV(RTPollSetQueryHandle(hSet, 10 /*id*/, &Handle), VINF_SUCCESS);
313 RTTESTI_CHECK(Handle.enmType == RTHANDLETYPE_PIPE);
314 RTTESTI_CHECK(Handle.u.hPipe == hPipeW);
315
316 RTTESTI_CHECK_RC(RTPoll(hSet, 0, NULL, NULL), VINF_SUCCESS);
317
318 RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
319
320 fEvents = UINT32_MAX;
321 id = UINT32_MAX;
322 RTTESTI_CHECK_RC(RTPollNoResume(hSet, 0, &fEvents, &id), VINF_SUCCESS);
323 RTTESTI_CHECK(id == 10);
324 RTTESTI_CHECK(fEvents == RTPOLL_EVT_ERROR);
325
326 RTTESTI_CHECK_RC(RTPollSetDestroy(hSet), VINF_SUCCESS);
327 RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
328
329 /*
330 * Check FIFO order when removing and adding.
331 *
332 * Note! FIFO order is not guaranteed when a handle has more than one entry
333 * in the set.
334 */
335 RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0/*fFlags*/), VINF_SUCCESS);
336 RTPIPE hPipeR2, hPipeW2;
337 RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR2, &hPipeW2, 0/*fFlags*/), VINF_SUCCESS);
338 RTPIPE hPipeR3, hPipeW3;
339 RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR3, &hPipeW3, 0/*fFlags*/), VINF_SUCCESS);
340 RTTESTI_CHECK_RC_RETV(RTPollSetCreate(&hSet), VINF_SUCCESS);
341 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeR, RTPOLL_EVT_READ, 1 /*id*/), VINF_SUCCESS);
342 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeW, RTPOLL_EVT_WRITE, 2 /*id*/), VINF_SUCCESS);
343 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeR2, RTPOLL_EVT_READ, 3 /*id*/), VINF_SUCCESS);
344 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeW2, RTPOLL_EVT_WRITE, 4 /*id*/), VINF_SUCCESS);
345 RTTESTI_CHECK_RC_RETV(RTPollSetAddPipe(hSet, hPipeR3, RTPOLL_EVT_READ, 5 /*id*/), VINF_SUCCESS);
346
347 id = UINT32_MAX; fEvents = UINT32_MAX;
348 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
349 RTTESTI_CHECK(id == 2);
350 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
351
352 RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeW, "hello", 5, NULL), VINF_SUCCESS);
353 RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeW2, "hello", 5, NULL), VINF_SUCCESS);
354 RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeW3, "hello", 5, NULL), VINF_SUCCESS);
355 id = UINT32_MAX; fEvents = UINT32_MAX;
356 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
357 RTTESTI_CHECK(id == 1);
358 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
359
360 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 1), VINF_SUCCESS);
361 id = UINT32_MAX; fEvents = UINT32_MAX;
362 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
363 RTTESTI_CHECK(id == 2);
364 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
365
366 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 2), VINF_SUCCESS);
367 id = UINT32_MAX; fEvents = UINT32_MAX;
368 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
369 RTTESTI_CHECK(id == 3);
370 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
371
372 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 3), VINF_SUCCESS);
373 id = UINT32_MAX; fEvents = UINT32_MAX;
374 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
375 RTTESTI_CHECK(id == 4);
376 RTTESTI_CHECK(fEvents == RTPOLL_EVT_WRITE);
377
378 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 4), VINF_SUCCESS);
379 id = UINT32_MAX; fEvents = UINT32_MAX;
380 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VINF_SUCCESS);
381 RTTESTI_CHECK(id == 5);
382 RTTESTI_CHECK(fEvents == RTPOLL_EVT_READ);
383
384 RTTESTI_CHECK_RC(RTPollSetRemove(hSet, 5), VINF_SUCCESS);
385 id = UINT32_MAX; fEvents = UINT32_MAX;
386 RTTESTI_CHECK_RC(RTPoll(hSet, 5, &fEvents, &id), VERR_TIMEOUT);
387
388 RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
389 RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
390 RTTESTI_CHECK_RC(RTPipeClose(hPipeW2), VINF_SUCCESS);
391 RTTESTI_CHECK_RC(RTPipeClose(hPipeR2), VINF_SUCCESS);
392 RTTESTI_CHECK_RC(RTPipeClose(hPipeW3), VINF_SUCCESS);
393 RTTESTI_CHECK_RC(RTPipeClose(hPipeR3), VINF_SUCCESS);
394 RTTESTI_CHECK_RC(RTPollSetDestroy(hSet), VINF_SUCCESS);
395
396}
397
398int main()
399{
400 RTTEST hTest;
401 int rc = RTTestInitAndCreate("tstRTPoll", &hTest);
402 if (rc)
403 return rc;
404 RTTestBanner(hTest);
405
406 /*
407 * The tests.
408 */
409 tstRTPoll1();
410 if (RTTestErrorCount(hTest) == 0)
411 {
412 bool fMayPanic = RTAssertMayPanic();
413 bool fQuiet = RTAssertAreQuiet();
414 RTAssertSetMayPanic(false);
415 RTAssertSetQuiet(true);
416 tstRTPoll2();
417 RTAssertSetQuiet(fQuiet);
418 RTAssertSetMayPanic(fMayPanic);
419 }
420
421 /*
422 * Summary.
423 */
424 return RTTestSummaryAndDestroy(hTest);
425}
426
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