VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp@ 15738

Last change on this file since 15738 was 15505, checked in by vboxsync, 16 years ago

SUPDrv,INTNet: Heads up! SupDrv version bumped. Added SUPR0ObjAddRefEx for dealing with the handle table callback which occurs while owning a spinlock. Normally SUPR0ObjAddRef[Ex] would always allocate a usage record, which means RTMemAlloc, but this is a bad idea when inside a spinlock. SUPR0ObjAddRefEx sports an additional parameter indicating whether it is allowed block or not.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.9 KB
Line 
1/* $Id: tstIntNetR0.cpp 15505 2008-12-15 14:36:30Z vboxsync $ */
2/** @file
3 * Internal networking - Usermode testcase for the kernel mode bits.
4 *
5 * This is a bit hackish as we're mixing context here, however it is
6 * very useful when making changes to the internal networking service.
7 */
8
9/*
10 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21 * Clara, CA 95054 USA or visit http://www.sun.com if you need
22 * additional information or have any questions.
23 */
24
25
26/*******************************************************************************
27* Header Files *
28*******************************************************************************/
29#define IN_INTNET_TESTCASE
30#define IN_INTNET_R3
31#include <VBox/cdefs.h>
32#undef INTNETR0DECL
33#define INTNETR0DECL INTNETR3DECL
34#undef DECLR0CALLBACKMEMBER
35#define DECLR0CALLBACKMEMBER(type, name, args) DECLR3CALLBACKMEMBER(type, name, args)
36#include <VBox/types.h>
37typedef void *MYPSUPDRVSESSION;
38#define PSUPDRVSESSION MYPSUPDRVSESSION
39
40#include <VBox/intnet.h>
41#include <VBox/sup.h>
42#include <VBox/err.h>
43#include <iprt/stream.h>
44#include <iprt/alloc.h>
45#include <iprt/initterm.h>
46#include <iprt/thread.h>
47#include <iprt/time.h>
48#include <iprt/asm.h>
49#include <iprt/getopt.h>
50
51
52/*******************************************************************************
53* Structures and Typedefs *
54*******************************************************************************/
55/**
56 * Security objectype.
57 */
58typedef enum SUPDRVOBJTYPE
59{
60 /** The usual invalid object. */
61 SUPDRVOBJTYPE_INVALID = 0,
62 /** Internal network. */
63 SUPDRVOBJTYPE_INTERNAL_NETWORK,
64 /** Internal network interface. */
65 SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE,
66 /** The first invalid object type in this end. */
67 SUPDRVOBJTYPE_END,
68 /** The usual 32-bit type size hack. */
69 SUPDRVOBJTYPE_32_BIT_HACK = 0x7ffffff
70} SUPDRVOBJTYPE;
71
72/**
73 * Object destructor callback.
74 * This is called for reference counted objectes when the count reaches 0.
75 *
76 * @param pvObj The object pointer.
77 * @param pvUser1 The first user argument.
78 * @param pvUser2 The second user argument.
79 */
80typedef DECLCALLBACK(void) FNSUPDRVDESTRUCTOR(void *pvObj, void *pvUser1, void *pvUser2);
81/** Pointer to a FNSUPDRVDESTRUCTOR(). */
82typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
83
84
85/**
86 * Dummy
87 */
88typedef struct OBJREF
89{
90 PFNSUPDRVDESTRUCTOR pfnDestructor;
91 void *pvUser1;
92 void *pvUser2;
93 uint32_t volatile cRefs;
94} OBJREF, *POBJREF;
95
96
97/*******************************************************************************
98* Global Variables *
99*******************************************************************************/
100/** The error count. */
101unsigned g_cErrors = 0;
102
103/** Fake session handle. */
104const PSUPDRVSESSION g_pSession = (PSUPDRVSESSION)0xdeadface;
105
106/** Testframe 0 */
107struct TESTFRAME
108{
109 uint16_t au16[7];
110} g_TestFrame0 = { { /* dst:*/ 0xffff, 0xffff, 0xffff, /*src:*/0x8086, 0, 0, 0x0800 } },
111 g_TestFrame1 = { { /* dst:*/ 0, 0, 0, /*src:*/0x8086, 0, 1, 0x0800 } };
112
113
114INTNETR3DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2)
115{
116 if (pSession != g_pSession)
117 {
118 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
119 g_cErrors++;
120 return NULL;
121 }
122 POBJREF pRef = (POBJREF)RTMemAlloc(sizeof(OBJREF));
123 if (!pRef)
124 return NULL;
125 pRef->cRefs = 1;
126 pRef->pfnDestructor = pfnDestructor;
127 pRef->pvUser1 = pvUser1;
128 pRef->pvUser2 = pvUser2;
129 return pRef;
130}
131
132INTNETR3DECL(int) SUPR0ObjAddRefEx(void *pvObj, PSUPDRVSESSION pSession, bool fNoBlocking)
133{
134 if (pSession != g_pSession)
135 {
136 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
137 g_cErrors++;
138 return VERR_INVALID_PARAMETER;
139 }
140 POBJREF pRef = (POBJREF)pvObj;
141 ASMAtomicIncU32(&pRef->cRefs);
142 return VINF_SUCCESS;
143}
144
145INTNETR3DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
146{
147 return SUPR0ObjAddRefEx(pvObj, pSession, false);
148}
149
150INTNETR3DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession)
151{
152 if (pSession != g_pSession)
153 {
154 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
155 g_cErrors++;
156 return VERR_INVALID_PARAMETER;
157 }
158 POBJREF pRef = (POBJREF)pvObj;
159 if (!ASMAtomicDecU32(&pRef->cRefs))
160 {
161 pRef->pfnDestructor(pRef, pRef->pvUser1, pRef->pvUser2);
162 RTMemFree(pRef);
163 }
164 return VINF_SUCCESS;
165}
166
167INTNETR3DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName)
168{
169 if (pSession != g_pSession)
170 {
171 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
172 g_cErrors++;
173 return VERR_INVALID_PARAMETER;
174 }
175 return VINF_SUCCESS;
176}
177
178INTNETR3DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
179{
180 if (pSession != g_pSession)
181 {
182 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
183 g_cErrors++;
184 return VERR_INVALID_PARAMETER;
185 }
186 void *pv = RTMemAlloc(cb);
187 if (!pv)
188 return VERR_NO_MEMORY;
189 *ppvR0 = (RTR0PTR)pv;
190 if (ppvR3)
191 *ppvR3 = pv;
192 return VINF_SUCCESS;
193}
194
195INTNETR3DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
196{
197 if (pSession != g_pSession)
198 {
199 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
200 g_cErrors++;
201 return VERR_INVALID_PARAMETER;
202 }
203 RTMemFree((void *)uPtr);
204 return VINF_SUCCESS;
205}
206
207
208
209/* ugly but necessary for making R0 code compilable for R3. */
210#undef LOG_GROUP
211#include "../SrvIntNetR0.cpp"
212
213typedef struct ARGS
214{
215 PINTNET pIntNet;
216 PINTNETBUF pBuf;
217 INTNETIFHANDLE hIf;
218 RTMAC Mac;
219 uint64_t u64Start;
220 uint64_t u64End;
221} ARGS, *PARGS;
222
223
224#define TEST_TRANSFER_SIZE (_1M*384)
225
226/**
227 * Send thread.
228 * This is constantly broadcasting frames to the network.
229 */
230DECLCALLBACK(int) SendThread(RTTHREAD Thread, void *pvArg)
231{
232 PARGS pArgs = (PARGS)pvArg;
233
234 /*
235 * Send 64 MB of data.
236 */
237 uint8_t abBuf[4096] = {0};
238 PRTMAC pMacSrc = (PRTMAC)&abBuf[0];
239 PRTMAC pMacDst = pMacSrc + 1;
240 *pMacSrc = pArgs->Mac;
241 *pMacDst = pArgs->Mac;
242 pMacDst->au16[2] = pArgs->Mac.au16[2] ? 0 : 1;
243 unsigned *puFrame = (unsigned *)(pMacDst + 1);
244 unsigned iFrame = 0;
245 unsigned cbSent = 0;
246 pArgs->u64Start = RTTimeNanoTS();
247 for (; cbSent < TEST_TRANSFER_SIZE; iFrame++)
248 {
249 const unsigned cb = iFrame % 1519 + 12 + sizeof(unsigned);
250 *puFrame = iFrame;
251#if 0
252 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, abBuf, cb);
253#else
254 INTNETSG Sg;
255 intnetR0SgInitTemp(&Sg, abBuf, cb);
256 int rc = intnetR0RingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, &Sg, NULL);
257 if (RT_SUCCESS(rc))
258 rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, NULL, 0);
259#endif
260 if (RT_FAILURE(rc))
261 {
262 g_cErrors++;
263 RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Rrc (%d)\n", cb, rc, INTNETRingGetWritable(&pArgs->pBuf->Send));
264 }
265 cbSent += cb;
266 }
267
268 /*
269 * Termination frames.
270 */
271 puFrame[0] = 0xffffdead;
272 puFrame[1] = 0xffffdead;
273 puFrame[2] = 0xffffdead;
274 puFrame[3] = 0xffffdead;
275 for (unsigned c = 0; c < 20; c++)
276 {
277 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, abBuf, sizeof(RTMAC) * 2 + sizeof(unsigned) * 4);
278 if (RT_FAILURE(rc))
279 {
280 g_cErrors++;
281 RTPrintf("tstIntNetR0: send failed, rc=%Rrc\n", rc);
282 }
283 RTThreadSleep(1);
284 }
285
286 RTPrintf("tstIntNetR0: sender thread %.6Rhxs terminating. iFrame=%d cbSent=%d\n", &pArgs->Mac, iFrame, cbSent);
287 return 0;
288}
289
290
291/** Ignore lost frames. It only makes things worse to bitch about it. */
292#define IGNORE_LOST_FRAMES
293
294/**
295 * Receive thread.
296 * This is reading stuff from the network.
297 */
298DECLCALLBACK(int) ReceiveThread(RTTHREAD Thread, void *pvArg)
299{
300 unsigned cbReceived = 0;
301 unsigned cLostFrames = 0;
302 unsigned iFrame = ~0;
303 PARGS pArgs = (PARGS)pvArg;
304 for (;;)
305 {
306 /*
307 * Wait for data.
308 */
309 int rc = INTNETR0IfWait(pArgs->pIntNet, pArgs->hIf, g_pSession, RT_INDEFINITE_WAIT);
310 switch (rc)
311 {
312 case VERR_INTERRUPTED:
313 case VINF_SUCCESS:
314 break;
315 case VERR_SEM_DESTROYED:
316 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs terminating. cbReceived=%u cLostFrames=%u iFrame=%u\n",
317 &pArgs->Mac, cbReceived, cLostFrames, iFrame);
318 return VINF_SUCCESS;
319
320 default:
321 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs got odd return value %Rrc! cbReceived=%u cLostFrames=%u iFrame=%u\n",
322 &pArgs->Mac, rc, cbReceived, cLostFrames, iFrame);
323 g_cErrors++;
324 return rc;
325 }
326
327 /*
328 * Read data.
329 */
330 while (INTNETRingGetReadable(&pArgs->pBuf->Recv))
331 {
332 uint8_t abBuf[16384];
333 unsigned cb = intnetR0RingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf);
334 unsigned *puFrame = (unsigned *)&abBuf[sizeof(RTMAC) * 2];
335
336 /* check for termination frame. */
337 if ( cb == sizeof(RTMAC) * 2 + sizeof(unsigned) * 4
338 && puFrame[0] == 0xffffdead
339 && puFrame[1] == 0xffffdead
340 && puFrame[2] == 0xffffdead
341 && puFrame[3] == 0xffffdead)
342 {
343 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs terminating. cbReceived=%u cLostFrames=%u iFrame=%u\n",
344 &pArgs->Mac, cbReceived, cLostFrames, iFrame);
345 pArgs->u64End = RTTimeNanoTS();
346 return VINF_SUCCESS;
347 }
348
349 /* validate frame header */
350 PRTMAC pMacSrc = (PRTMAC)&abBuf[0];
351 PRTMAC pMacDst = pMacSrc + 1;
352 if ( pMacDst->au16[0] != 0x8086
353 || pMacDst->au16[1] != 0
354 || pMacDst->au16[2] != pArgs->Mac.au16[2]
355 || pMacSrc->au16[0] != 0x8086
356 || pMacSrc->au16[1] != 0
357 || pMacSrc->au16[2] == pArgs->Mac.au16[2])
358 {
359 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs received frame header: %.16Rhxs\n",
360 &pArgs->Mac, abBuf);
361 g_cErrors++;
362 }
363
364 /* frame stuff and stats. */
365 int off = iFrame + 1 - *puFrame;
366 if (off)
367 {
368 if (off > 0)
369 {
370 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs: iFrame=%d *puFrame=%d off=%d\n",
371 &pArgs->Mac, iFrame, *puFrame, off);
372 g_cErrors++;
373 cLostFrames++;
374 }
375 else
376 {
377 cLostFrames += -off;
378#ifndef IGNORE_LOST_FRAMES
379 if (off < 50)
380 {
381 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs: iFrame=%d *puFrame=%d off=%d\n",
382 &pArgs->Mac, iFrame, *puFrame, off);
383 g_cErrors++;
384 }
385#endif
386 }
387 }
388 iFrame = *puFrame;
389 cbReceived += cb;
390 }
391 }
392}
393
394int main(int argc, char **argv)
395{
396 /*
397 * Init the runtime and parse arguments.
398 */
399 RTR3Init();
400
401 static RTOPTIONDEF const s_aOptions[] =
402 {
403 { "--recv-buffer", 'r', RTGETOPT_REQ_UINT32 },
404 { "--send-buffer", 's', RTGETOPT_REQ_UINT32 },
405 };
406
407 uint32_t cbRecv = 32 * _1K;
408 uint32_t cbSend = 1536*2;
409
410 int ch;
411 int iArg = 1;
412 RTOPTIONUNION Value;
413 while ((ch = RTGetOpt(argc,argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), &iArg, &Value)))
414 switch (ch)
415 {
416 case 'r':
417 cbRecv = Value.u32;
418 break;
419
420 case 's':
421 cbSend = Value.u32;
422 break;
423
424 default:
425 RTPrintf("tstIntNetR0: invalid argument: %s\n", Value.psz);
426 return 1;
427 }
428 if (iArg < argc)
429 {
430 RTPrintf("tstIntNetR0: invalid argument: %s\n", argv[iArg]);
431 return 1;
432 }
433
434 /*
435 * Create an INTNET instance.
436 */
437 RTPrintf("tstIntNetR0: TESTING cbSend=%d cbRecv=%d ...\n", cbSend, cbRecv);
438 PINTNET pIntNet;
439 int rc = INTNETR0Create(&pIntNet);
440 if (RT_FAILURE(rc))
441 {
442 RTPrintf("tstIntNetR0: INTNETR0Create failed, rc=%Rrc\n");
443 return 1;
444 }
445
446 /*
447 * Create two interfaces.
448 */
449 INTNETIFHANDLE hIf0 = INTNET_HANDLE_INVALID;
450 rc = INTNETR0Open(pIntNet, g_pSession, "test", kIntNetTrunkType_None, "", 0, 1536*2 + 4, 0x8000, &hIf0);
451 if (RT_SUCCESS(rc))
452 {
453 if (hIf0 != INTNET_HANDLE_INVALID)
454 {
455 INTNETIFHANDLE hIf1 = INTNET_HANDLE_INVALID;
456 rc = INTNETR0Open(pIntNet, g_pSession, "test", kIntNetTrunkType_None, NULL, 0, 1536*2 + 4, 0x8000, &hIf1);
457 if (RT_SUCCESS(rc))
458 {
459 if (hIf1 != INTNET_HANDLE_INVALID)
460 {
461 PINTNETBUF pBuf0;
462 rc = INTNETR0IfGetRing0Buffer(pIntNet, hIf0, g_pSession, &pBuf0);
463 if (RT_FAILURE(rc) || !pBuf0)
464 {
465 RTPrintf("tstIntNetR0: INTNETIfGetRing0Buffer failed! pBuf0=%p rc=%Rrc\n", pBuf0, rc);
466 g_cErrors++;
467 }
468 PINTNETBUF pBuf1;
469 rc = INTNETR0IfGetRing0Buffer(pIntNet, hIf1, g_pSession, &pBuf1);
470 if (RT_FAILURE(rc))
471 {
472 RTPrintf("tstIntNetR0: INTNETIfGetRing0Buffer failed! pBuf1=%p rc=%Rrc\n", pBuf1, rc);
473 g_cErrors++;
474 }
475
476 rc = INTNETR0IfSetActive(pIntNet, hIf0, g_pSession, true);
477 if (RT_FAILURE(rc))
478 {
479 RTPrintf("tstIntNetR0: INTNETR0IfSetActive failed! rc=%Rrc\n", rc);
480 g_cErrors++;
481 }
482 rc = INTNETR0IfSetActive(pIntNet, hIf1, g_pSession, true);
483 if (RT_FAILURE(rc))
484 {
485 RTPrintf("tstIntNetR0: INTNETR0IfSetActive failed! rc=%Rrc\n", rc);
486 g_cErrors++;
487 }
488
489
490 /*
491 * Test basic waiting.
492 */
493 rc = INTNETR0IfWait(pIntNet, hIf0, g_pSession, 1);
494 if (rc != VERR_TIMEOUT)
495 {
496 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf0)\n", rc);
497 g_cErrors++;
498 }
499 rc = INTNETR0IfWait(pIntNet, hIf1, g_pSession, 0);
500 if (rc != VERR_TIMEOUT)
501 {
502 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf1)\n", rc);
503 g_cErrors++;
504 }
505
506 /*
507 * Send and receive.
508 */
509 rc = INTNETR0IfSend(pIntNet, hIf0, g_pSession, &g_TestFrame0, sizeof(g_TestFrame0));
510 if (RT_SUCCESS(rc))
511 {
512 rc = INTNETR0IfWait(pIntNet, hIf0, g_pSession, 1);
513 if (rc != VERR_TIMEOUT)
514 {
515 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf0, 2nd)\n", rc);
516 g_cErrors++;
517 }
518 rc = INTNETR0IfWait(pIntNet, hIf1, g_pSession, 0);
519 if (rc == VINF_SUCCESS)
520 {
521 /* receive it */
522 uint8_t abBuf[sizeof(g_TestFrame0)];
523 const unsigned cbExpect = RT_ALIGN(sizeof(g_TestFrame0) + sizeof(INTNETHDR), sizeof(INTNETHDR));
524 if (INTNETRingGetReadable(&pBuf1->Recv) != cbExpect)
525 {
526 RTPrintf("tstIntNetR0: %d readable bytes, expected %d!\n", INTNETRingGetReadable(&pBuf1->Recv), cbExpect);
527 g_cErrors++;
528 }
529 unsigned cb = intnetR0RingReadFrame(pBuf1, &pBuf1->Recv, abBuf);
530 if (cb != sizeof(g_TestFrame0))
531 {
532 RTPrintf("tstIntNetR0: read %d frame bytes, expected %d!\n", cb, sizeof(g_TestFrame0));
533 g_cErrors++;
534 }
535 else if (memcmp(abBuf, &g_TestFrame0, sizeof(g_TestFrame0)))
536 {
537 RTPrintf("tstIntNetR0: Got invalid data!\n"
538 "received: %.*Rhxs\n"
539 "expected: %.*Rhxs\n",
540 cb, abBuf, sizeof(g_TestFrame0), &g_TestFrame0);
541 g_cErrors++;
542 }
543
544 /*
545 * Send a packet from If1 just to set its MAC address.
546 */
547 rc = INTNETR0IfSend(pIntNet, hIf1, g_pSession, &g_TestFrame1, sizeof(g_TestFrame1));
548 if (RT_FAILURE(rc))
549 {
550 RTPrintf("tstIntNetR0: INTNETIfSend returned %Rrc! (hIf1)\n", rc);
551 g_cErrors++;
552 }
553
554
555 /*
556 * Start threaded testcase.
557 * Give it 5 mins to finish.
558 */
559 if (!g_cErrors)
560 {
561 ARGS Args0 = {0};
562 Args0.hIf = hIf0;
563 Args0.pBuf = pBuf0;
564 Args0.pIntNet = pIntNet;
565 Args0.Mac.au16[0] = 0x8086;
566 Args0.Mac.au16[1] = 0;
567 Args0.Mac.au16[2] = 0;
568
569 ARGS Args1 = {0};
570 Args1.hIf = hIf1;
571 Args1.pBuf = pBuf1;
572 Args1.pIntNet = pIntNet;
573 Args1.Mac.au16[0] = 0x8086;
574 Args1.Mac.au16[1] = 0;
575 Args1.Mac.au16[2] = 1;
576
577 RTTHREAD ThreadRecv0 = NIL_RTTHREAD;
578 RTTHREAD ThreadRecv1 = NIL_RTTHREAD;
579 RTTHREAD ThreadSend0 = NIL_RTTHREAD;
580 RTTHREAD ThreadSend1 = NIL_RTTHREAD;
581 rc = RTThreadCreate(&ThreadRecv0, ReceiveThread, &Args0, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "RECV0");
582 if (RT_SUCCESS(rc))
583 rc = RTThreadCreate(&ThreadRecv1, ReceiveThread, &Args1, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "RECV1");
584 if (RT_SUCCESS(rc))
585 rc = RTThreadCreate(&ThreadSend0, SendThread, &Args0, 0, RTTHREADTYPE_EMULATION, RTTHREADFLAGS_WAITABLE, "SEND0");
586 if (RT_SUCCESS(rc))
587 rc = RTThreadCreate(&ThreadSend1, SendThread, &Args1, 0, RTTHREADTYPE_EMULATION, RTTHREADFLAGS_WAITABLE, "SEND1");
588 if (RT_SUCCESS(rc))
589 {
590 int rc2 = VINF_SUCCESS;
591 rc = RTThreadWait(ThreadSend0, 5*60*1000, &rc2);
592#if 1 /** @todo it looks like I'm subject to some false wakeup calls here (2.6.23-gentoo-r3 amd64). See #3023.*/
593 for (int cTries = 100; rc == VERR_TIMEOUT && cTries > 0; cTries--)
594 {
595 RTThreadSleep(1);
596 rc = RTThreadWait(ThreadSend0, 1, &rc2);
597 }
598#endif
599 AssertRC(rc);
600 if (RT_SUCCESS(rc))
601 {
602 ThreadSend0 = NIL_RTTHREAD;
603 rc = RTThreadWait(ThreadSend1, 5*60*1000, RT_SUCCESS(rc2) ? &rc2 : NULL);
604#if 1 /** @todo it looks like I'm subject to some false wakeup calls here (2.6.23-gentoo-r3 amd64). See #3023.*/
605 for (int cTries = 100; rc == VERR_TIMEOUT && cTries > 0; cTries--)
606 {
607 RTThreadSleep(1);
608 rc = RTThreadWait(ThreadSend1, 1, &rc2);
609 }
610#endif
611 AssertRC(rc);
612 if (RT_SUCCESS(rc))
613 ThreadSend1 = NIL_RTTHREAD;
614 }
615 if ( RT_SUCCESS(rc)
616 && RT_SUCCESS(rc2))
617 {
618 /*
619 * Wait a bit for the receivers to finish up.
620 */
621 unsigned cYields = 100000;
622 while ( ( INTNETRingGetReadable(&pBuf0->Recv)
623 || INTNETRingGetReadable(&pBuf1->Recv))
624 && cYields-- > 0)
625 RTThreadYield();
626
627 uint64_t u64Elapsed = RT_MAX(Args0.u64End, Args1.u64End) - RT_MIN(Args0.u64Start, Args1.u64Start);
628 uint64_t u64Speed = (uint64_t)((2 * TEST_TRANSFER_SIZE / 1024) / (u64Elapsed / 1000000000.0));
629 RTPrintf("tstIntNetR0: transfered %d bytes in %RU64 ns (%RU64 KB/s)\n",
630 2 * TEST_TRANSFER_SIZE, u64Elapsed, u64Speed);
631
632 /*
633 * Closing time...
634 */
635 rc = RTThreadWait(ThreadRecv0, 5000, &rc2);
636 if (RT_SUCCESS(rc))
637 ThreadRecv0 = NIL_RTTHREAD;
638 if (RT_FAILURE(rc) || RT_FAILURE(rc2))
639 {
640 RTPrintf("tstIntNetR0: Failed waiting on receiver thread 0, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
641 g_cErrors++;
642 }
643
644 rc = RTThreadWait(ThreadRecv1, 5000, &rc2);
645 if (RT_SUCCESS(rc))
646 ThreadRecv1 = NIL_RTTHREAD;
647 if (RT_FAILURE(rc) || RT_FAILURE(rc2))
648 {
649 RTPrintf("tstIntNetR0: Failed waiting on receiver thread 1, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
650 g_cErrors++;
651 }
652
653 rc = INTNETR0IfClose(pIntNet, hIf0, g_pSession);
654 if (RT_SUCCESS(rc))
655 {
656 hIf0 = INTNET_HANDLE_INVALID;
657 pBuf0 = NULL;
658 }
659 else
660 {
661 RTPrintf("tstIntNetR0: INTNETIfClose failed, rc=%Rrc! (hIf0)\n", rc);
662 g_cErrors++;
663 }
664
665 rc = INTNETR0IfClose(pIntNet, hIf1, g_pSession);
666 if (RT_SUCCESS(rc))
667 {
668 hIf1 = INTNET_HANDLE_INVALID;
669 pBuf1 = NULL;
670 }
671 else
672 {
673 RTPrintf("tstIntNetR0: INTNETIfClose failed, rc=%Rrc! (hIf1)\n", rc);
674 g_cErrors++;
675 }
676
677
678 /* check if the network still exist... */
679 if (pIntNet->pNetworks)
680 {
681 RTPrintf("tstIntNetR0: The network wasn't deleted! (g_cErrors=%d)\n", g_cErrors);
682 g_cErrors++;
683 }
684 }
685 else
686 {
687 RTPrintf("tstIntNetR0: Waiting on senders failed, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
688 g_cErrors++;
689 }
690
691 /*
692 * Give them a chance to complete...
693 */
694 RTThreadWait(ThreadRecv0, 5000, NULL);
695 RTThreadWait(ThreadRecv1, 5000, NULL);
696 RTThreadWait(ThreadSend0, 5000, NULL);
697 RTThreadWait(ThreadSend1, 5000, NULL);
698
699 }
700 else
701 {
702 RTPrintf("tstIntNetR0: Failed to create threads, rc=%Rrc\n", rc);
703 g_cErrors++;
704 }
705 }
706 }
707 else
708 {
709 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VINF_SUCCESS (hIf1)\n", rc);
710 g_cErrors++;
711 }
712 }
713 else
714 {
715 RTPrintf("tstIntNetR0: INTNETIfSend returned %Rrc! (hIf0)\n", rc);
716 g_cErrors++;
717 }
718 }
719 else
720 {
721 RTPrintf("tstIntNetR0: INTNETOpen returned invalid handle on success! (hIf1)\n");
722 g_cErrors++;
723 }
724
725 if (hIf1 != INTNET_HANDLE_INVALID)
726 rc = INTNETR0IfClose(pIntNet, hIf1, g_pSession);
727 }
728 else
729 {
730 RTPrintf("tstIntNetR0: INTNETOpen failed for the 2nd interface! rc=%Rrc\n", rc);
731 g_cErrors++;
732 }
733
734 if (hIf0 != INTNET_HANDLE_INVALID)
735 rc = INTNETR0IfClose(pIntNet, hIf0, g_pSession);
736 }
737 else
738 {
739 RTPrintf("tstIntNetR0: INTNETOpen returned invalid handle on success! (hIf0)\n");
740 g_cErrors++;
741 }
742 }
743 else
744 {
745 RTPrintf("tstIntNetR0: INTNETOpen failed for the 1st interface! rc=%Rrc\n", rc);
746 g_cErrors++;
747 }
748
749 /*
750 * Destroy the service.
751 */
752 INTNETR0Destroy(pIntNet);
753
754 /*
755 * Summary.
756 */
757 if (!g_cErrors)
758 RTPrintf("tstIntNetR0: SUCCESS\n");
759 else
760 RTPrintf("tstIntNetR0: FAILURE - %d errors\n", g_cErrors);
761
762 return !!g_cErrors;
763}
764
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