VirtualBox

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

Last change on this file since 15056 was 14831, checked in by vboxsync, 16 years ago

whole bunch: avoid runtime.h, include individual headers indead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.8 KB
Line 
1/* $Id: tstIntNetR0.cpp 14831 2008-11-30 10:31:16Z 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) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
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) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession)
146{
147 if (pSession != g_pSession)
148 {
149 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
150 g_cErrors++;
151 return VERR_INVALID_PARAMETER;
152 }
153 POBJREF pRef = (POBJREF)pvObj;
154 if (!ASMAtomicDecU32(&pRef->cRefs))
155 {
156 pRef->pfnDestructor(pRef, pRef->pvUser1, pRef->pvUser2);
157 RTMemFree(pRef);
158 }
159 return VINF_SUCCESS;
160}
161
162INTNETR3DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName)
163{
164 if (pSession != g_pSession)
165 {
166 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
167 g_cErrors++;
168 return VERR_INVALID_PARAMETER;
169 }
170 return VINF_SUCCESS;
171}
172
173INTNETR3DECL(int) SUPR0MemAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR0PTR ppvR0, PRTR3PTR ppvR3)
174{
175 if (pSession != g_pSession)
176 {
177 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
178 g_cErrors++;
179 return VERR_INVALID_PARAMETER;
180 }
181 void *pv = RTMemAlloc(cb);
182 if (!pv)
183 return VERR_NO_MEMORY;
184 *ppvR0 = (RTR0PTR)pv;
185 if (ppvR3)
186 *ppvR3 = pv;
187 return VINF_SUCCESS;
188}
189
190INTNETR3DECL(int) SUPR0MemFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)
191{
192 if (pSession != g_pSession)
193 {
194 RTPrintf("tstIntNetR0: Invalid session pointer %p, %s!\n", pSession, __FUNCTION__);
195 g_cErrors++;
196 return VERR_INVALID_PARAMETER;
197 }
198 RTMemFree((void *)uPtr);
199 return VINF_SUCCESS;
200}
201
202
203
204/* ugly but necessary for making R0 code compilable for R3. */
205#undef LOG_GROUP
206#include "../SrvIntNetR0.cpp"
207
208typedef struct ARGS
209{
210 PINTNET pIntNet;
211 PINTNETBUF pBuf;
212 INTNETIFHANDLE hIf;
213 RTMAC Mac;
214 uint64_t u64Start;
215 uint64_t u64End;
216} ARGS, *PARGS;
217
218
219#define TEST_TRANSFER_SIZE (_1M*384)
220
221/**
222 * Send thread.
223 * This is constantly broadcasting frames to the network.
224 */
225DECLCALLBACK(int) SendThread(RTTHREAD Thread, void *pvArg)
226{
227 PARGS pArgs = (PARGS)pvArg;
228
229 /*
230 * Send 64 MB of data.
231 */
232 uint8_t abBuf[4096] = {0};
233 PRTMAC pMacSrc = (PRTMAC)&abBuf[0];
234 PRTMAC pMacDst = pMacSrc + 1;
235 *pMacSrc = pArgs->Mac;
236 *pMacDst = pArgs->Mac;
237 pMacDst->au16[2] = pArgs->Mac.au16[2] ? 0 : 1;
238 unsigned *puFrame = (unsigned *)(pMacDst + 1);
239 unsigned iFrame = 0;
240 unsigned cbSent = 0;
241 pArgs->u64Start = RTTimeNanoTS();
242 for (; cbSent < TEST_TRANSFER_SIZE; iFrame++)
243 {
244 const unsigned cb = iFrame % 1519 + 12 + sizeof(unsigned);
245 *puFrame = iFrame;
246#if 0
247 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, abBuf, cb);
248#else
249 INTNETSG Sg;
250 intnetR0SgInitTemp(&Sg, abBuf, cb);
251 int rc = intnetR0RingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, &Sg, NULL);
252 if (RT_SUCCESS(rc))
253 rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, NULL, 0);
254#endif
255 if (RT_FAILURE(rc))
256 {
257 g_cErrors++;
258 RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Rrc (%d)\n", cb, rc, INTNETRingGetWritable(&pArgs->pBuf->Send));
259 }
260 cbSent += cb;
261 }
262
263 /*
264 * Termination frames.
265 */
266 puFrame[0] = 0xffffdead;
267 puFrame[1] = 0xffffdead;
268 puFrame[2] = 0xffffdead;
269 puFrame[3] = 0xffffdead;
270 for (unsigned c = 0; c < 20; c++)
271 {
272 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, g_pSession, abBuf, sizeof(RTMAC) * 2 + sizeof(unsigned) * 4);
273 if (RT_FAILURE(rc))
274 {
275 g_cErrors++;
276 RTPrintf("tstIntNetR0: send failed, rc=%Rrc\n", rc);
277 }
278 RTThreadSleep(1);
279 }
280
281 RTPrintf("tstIntNetR0: sender thread %.6Rhxs terminating. iFrame=%d cbSent=%d\n", &pArgs->Mac, iFrame, cbSent);
282 return 0;
283}
284
285
286/** Ignore lost frames. It only makes things worse to bitch about it. */
287#define IGNORE_LOST_FRAMES
288
289/**
290 * Receive thread.
291 * This is reading stuff from the network.
292 */
293DECLCALLBACK(int) ReceiveThread(RTTHREAD Thread, void *pvArg)
294{
295 unsigned cbReceived = 0;
296 unsigned cLostFrames = 0;
297 unsigned iFrame = ~0;
298 PARGS pArgs = (PARGS)pvArg;
299 for (;;)
300 {
301 /*
302 * Wait for data.
303 */
304 int rc = INTNETR0IfWait(pArgs->pIntNet, pArgs->hIf, g_pSession, RT_INDEFINITE_WAIT);
305 switch (rc)
306 {
307 case VERR_INTERRUPTED:
308 case VINF_SUCCESS:
309 break;
310 case VERR_SEM_DESTROYED:
311 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs terminating. cbReceived=%u cLostFrames=%u iFrame=%u\n",
312 &pArgs->Mac, cbReceived, cLostFrames, iFrame);
313 return VINF_SUCCESS;
314
315 default:
316 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs got odd return value %Rrc! cbReceived=%u cLostFrames=%u iFrame=%u\n",
317 &pArgs->Mac, rc, cbReceived, cLostFrames, iFrame);
318 g_cErrors++;
319 return rc;
320 }
321
322 /*
323 * Read data.
324 */
325 while (INTNETRingGetReadable(&pArgs->pBuf->Recv))
326 {
327 uint8_t abBuf[16384];
328 unsigned cb = intnetR0RingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf);
329 unsigned *puFrame = (unsigned *)&abBuf[sizeof(RTMAC) * 2];
330
331 /* check for termination frame. */
332 if ( cb == sizeof(RTMAC) * 2 + sizeof(unsigned) * 4
333 && puFrame[0] == 0xffffdead
334 && puFrame[1] == 0xffffdead
335 && puFrame[2] == 0xffffdead
336 && puFrame[3] == 0xffffdead)
337 {
338 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs terminating. cbReceived=%u cLostFrames=%u iFrame=%u\n",
339 &pArgs->Mac, cbReceived, cLostFrames, iFrame);
340 pArgs->u64End = RTTimeNanoTS();
341 return VINF_SUCCESS;
342 }
343
344 /* validate frame header */
345 PRTMAC pMacSrc = (PRTMAC)&abBuf[0];
346 PRTMAC pMacDst = pMacSrc + 1;
347 if ( pMacDst->au16[0] != 0x8086
348 || pMacDst->au16[1] != 0
349 || pMacDst->au16[2] != pArgs->Mac.au16[2]
350 || pMacSrc->au16[0] != 0x8086
351 || pMacSrc->au16[1] != 0
352 || pMacSrc->au16[2] == pArgs->Mac.au16[2])
353 {
354 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs received frame header: %.16Rhxs\n",
355 &pArgs->Mac, abBuf);
356 g_cErrors++;
357 }
358
359 /* frame stuff and stats. */
360 int off = iFrame + 1 - *puFrame;
361 if (off)
362 {
363 if (off > 0)
364 {
365 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs: iFrame=%d *puFrame=%d off=%d\n",
366 &pArgs->Mac, iFrame, *puFrame, off);
367 g_cErrors++;
368 cLostFrames++;
369 }
370 else
371 {
372 cLostFrames += -off;
373#ifndef IGNORE_LOST_FRAMES
374 if (off < 50)
375 {
376 RTPrintf("tstIntNetR0: receiver thread %.6Rhxs: iFrame=%d *puFrame=%d off=%d\n",
377 &pArgs->Mac, iFrame, *puFrame, off);
378 g_cErrors++;
379 }
380#endif
381 }
382 }
383 iFrame = *puFrame;
384 cbReceived += cb;
385 }
386 }
387}
388
389int main(int argc, char **argv)
390{
391 /*
392 * Init the runtime and parse arguments.
393 */
394 RTR3Init();
395
396 static RTOPTIONDEF const s_aOptions[] =
397 {
398 { "--recv-buffer", 'r', RTGETOPT_REQ_UINT32 },
399 { "--send-buffer", 's', RTGETOPT_REQ_UINT32 },
400 };
401
402 uint32_t cbRecv = 32 * _1K;
403 uint32_t cbSend = 1536*2;
404
405 int ch;
406 int iArg = 1;
407 RTOPTIONUNION Value;
408 while ((ch = RTGetOpt(argc,argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), &iArg, &Value)))
409 switch (ch)
410 {
411 case 'r':
412 cbRecv = Value.u32;
413 break;
414
415 case 's':
416 cbSend = Value.u32;
417 break;
418
419 default:
420 RTPrintf("tstIntNetR0: invalid argument: %s\n", Value.psz);
421 return 1;
422 }
423 if (iArg < argc)
424 {
425 RTPrintf("tstIntNetR0: invalid argument: %s\n", argv[iArg]);
426 return 1;
427 }
428
429 /*
430 * Create an INTNET instance.
431 */
432 RTPrintf("tstIntNetR0: TESTING cbSend=%d cbRecv=%d ...\n", cbSend, cbRecv);
433 PINTNET pIntNet;
434 int rc = INTNETR0Create(&pIntNet);
435 if (RT_FAILURE(rc))
436 {
437 RTPrintf("tstIntNetR0: INTNETR0Create failed, rc=%Rrc\n");
438 return 1;
439 }
440
441 /*
442 * Create two interfaces.
443 */
444 INTNETIFHANDLE hIf0 = INTNET_HANDLE_INVALID;
445 rc = INTNETR0Open(pIntNet, g_pSession, "test", kIntNetTrunkType_None, "", 0, 1536*2 + 4, 0x8000, &hIf0);
446 if (RT_SUCCESS(rc))
447 {
448 if (hIf0 != INTNET_HANDLE_INVALID)
449 {
450 INTNETIFHANDLE hIf1 = INTNET_HANDLE_INVALID;
451 rc = INTNETR0Open(pIntNet, g_pSession, "test", kIntNetTrunkType_None, NULL, 0, 1536*2 + 4, 0x8000, &hIf1);
452 if (RT_SUCCESS(rc))
453 {
454 if (hIf1 != INTNET_HANDLE_INVALID)
455 {
456 PINTNETBUF pBuf0;
457 rc = INTNETR0IfGetRing0Buffer(pIntNet, hIf0, g_pSession, &pBuf0);
458 if (RT_FAILURE(rc) || !pBuf0)
459 {
460 RTPrintf("tstIntNetR0: INTNETIfGetRing0Buffer failed! pBuf0=%p rc=%Rrc\n", pBuf0, rc);
461 g_cErrors++;
462 }
463 PINTNETBUF pBuf1;
464 rc = INTNETR0IfGetRing0Buffer(pIntNet, hIf1, g_pSession, &pBuf1);
465 if (RT_FAILURE(rc))
466 {
467 RTPrintf("tstIntNetR0: INTNETIfGetRing0Buffer failed! pBuf1=%p rc=%Rrc\n", pBuf1, rc);
468 g_cErrors++;
469 }
470
471 rc = INTNETR0IfSetActive(pIntNet, hIf0, g_pSession, true);
472 if (RT_FAILURE(rc))
473 {
474 RTPrintf("tstIntNetR0: INTNETR0IfSetActive failed! rc=%Rrc\n", rc);
475 g_cErrors++;
476 }
477 rc = INTNETR0IfSetActive(pIntNet, hIf1, g_pSession, true);
478 if (RT_FAILURE(rc))
479 {
480 RTPrintf("tstIntNetR0: INTNETR0IfSetActive failed! rc=%Rrc\n", rc);
481 g_cErrors++;
482 }
483
484
485 /*
486 * Test basic waiting.
487 */
488 rc = INTNETR0IfWait(pIntNet, hIf0, g_pSession, 1);
489 if (rc != VERR_TIMEOUT)
490 {
491 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf0)\n", rc);
492 g_cErrors++;
493 }
494 rc = INTNETR0IfWait(pIntNet, hIf1, g_pSession, 0);
495 if (rc != VERR_TIMEOUT)
496 {
497 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf1)\n", rc);
498 g_cErrors++;
499 }
500
501 /*
502 * Send and receive.
503 */
504 rc = INTNETR0IfSend(pIntNet, hIf0, g_pSession, &g_TestFrame0, sizeof(g_TestFrame0));
505 if (RT_SUCCESS(rc))
506 {
507 rc = INTNETR0IfWait(pIntNet, hIf0, g_pSession, 1);
508 if (rc != VERR_TIMEOUT)
509 {
510 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VERR_TIMEOUT (hIf0, 2nd)\n", rc);
511 g_cErrors++;
512 }
513 rc = INTNETR0IfWait(pIntNet, hIf1, g_pSession, 0);
514 if (rc == VINF_SUCCESS)
515 {
516 /* receive it */
517 uint8_t abBuf[sizeof(g_TestFrame0)];
518 const unsigned cbExpect = RT_ALIGN(sizeof(g_TestFrame0) + sizeof(INTNETHDR), sizeof(INTNETHDR));
519 if (INTNETRingGetReadable(&pBuf1->Recv) != cbExpect)
520 {
521 RTPrintf("tstIntNetR0: %d readable bytes, expected %d!\n", INTNETRingGetReadable(&pBuf1->Recv), cbExpect);
522 g_cErrors++;
523 }
524 unsigned cb = intnetR0RingReadFrame(pBuf1, &pBuf1->Recv, abBuf);
525 if (cb != sizeof(g_TestFrame0))
526 {
527 RTPrintf("tstIntNetR0: read %d frame bytes, expected %d!\n", cb, sizeof(g_TestFrame0));
528 g_cErrors++;
529 }
530 else if (memcmp(abBuf, &g_TestFrame0, sizeof(g_TestFrame0)))
531 {
532 RTPrintf("tstIntNetR0: Got invalid data!\n"
533 "received: %.*Rhxs\n"
534 "expected: %.*Rhxs\n",
535 cb, abBuf, sizeof(g_TestFrame0), &g_TestFrame0);
536 g_cErrors++;
537 }
538
539 /*
540 * Send a packet from If1 just to set its MAC address.
541 */
542 rc = INTNETR0IfSend(pIntNet, hIf1, g_pSession, &g_TestFrame1, sizeof(g_TestFrame1));
543 if (RT_FAILURE(rc))
544 {
545 RTPrintf("tstIntNetR0: INTNETIfSend returned %Rrc! (hIf1)\n", rc);
546 g_cErrors++;
547 }
548
549
550 /*
551 * Start threaded testcase.
552 * Give it 5 mins to finish.
553 */
554 if (!g_cErrors)
555 {
556 ARGS Args0 = {0};
557 Args0.hIf = hIf0;
558 Args0.pBuf = pBuf0;
559 Args0.pIntNet = pIntNet;
560 Args0.Mac.au16[0] = 0x8086;
561 Args0.Mac.au16[1] = 0;
562 Args0.Mac.au16[2] = 0;
563
564 ARGS Args1 = {0};
565 Args1.hIf = hIf1;
566 Args1.pBuf = pBuf1;
567 Args1.pIntNet = pIntNet;
568 Args1.Mac.au16[0] = 0x8086;
569 Args1.Mac.au16[1] = 0;
570 Args1.Mac.au16[2] = 1;
571
572 RTTHREAD ThreadRecv0 = NIL_RTTHREAD;
573 RTTHREAD ThreadRecv1 = NIL_RTTHREAD;
574 RTTHREAD ThreadSend0 = NIL_RTTHREAD;
575 RTTHREAD ThreadSend1 = NIL_RTTHREAD;
576 rc = RTThreadCreate(&ThreadRecv0, ReceiveThread, &Args0, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "RECV0");
577 if (RT_SUCCESS(rc))
578 rc = RTThreadCreate(&ThreadRecv1, ReceiveThread, &Args1, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "RECV1");
579 if (RT_SUCCESS(rc))
580 rc = RTThreadCreate(&ThreadSend0, SendThread, &Args0, 0, RTTHREADTYPE_EMULATION, RTTHREADFLAGS_WAITABLE, "SEND0");
581 if (RT_SUCCESS(rc))
582 rc = RTThreadCreate(&ThreadSend1, SendThread, &Args1, 0, RTTHREADTYPE_EMULATION, RTTHREADFLAGS_WAITABLE, "SEND1");
583 if (RT_SUCCESS(rc))
584 {
585 int rc2 = VINF_SUCCESS;
586 rc = RTThreadWait(ThreadSend0, 5*60*1000, &rc2);
587#if 1 /** @todo it looks like I'm subject to some false wakeup calls here (2.6.23-gentoo-r3 amd64). See #3023.*/
588 for (int cTries = 100; rc == VERR_TIMEOUT && cTries > 0; cTries--)
589 {
590 RTThreadSleep(1);
591 rc = RTThreadWait(ThreadSend0, 1, &rc2);
592 }
593#endif
594 AssertRC(rc);
595 if (RT_SUCCESS(rc))
596 {
597 ThreadSend0 = NIL_RTTHREAD;
598 rc = RTThreadWait(ThreadSend1, 5*60*1000, RT_SUCCESS(rc2) ? &rc2 : NULL);
599#if 1 /** @todo it looks like I'm subject to some false wakeup calls here (2.6.23-gentoo-r3 amd64). See #3023.*/
600 for (int cTries = 100; rc == VERR_TIMEOUT && cTries > 0; cTries--)
601 {
602 RTThreadSleep(1);
603 rc = RTThreadWait(ThreadSend1, 1, &rc2);
604 }
605#endif
606 AssertRC(rc);
607 if (RT_SUCCESS(rc))
608 ThreadSend1 = NIL_RTTHREAD;
609 }
610 if ( RT_SUCCESS(rc)
611 && RT_SUCCESS(rc2))
612 {
613 /*
614 * Wait a bit for the receivers to finish up.
615 */
616 unsigned cYields = 100000;
617 while ( ( INTNETRingGetReadable(&pBuf0->Recv)
618 || INTNETRingGetReadable(&pBuf1->Recv))
619 && cYields-- > 0)
620 RTThreadYield();
621
622 uint64_t u64Elapsed = RT_MAX(Args0.u64End, Args1.u64End) - RT_MIN(Args0.u64Start, Args1.u64Start);
623 uint64_t u64Speed = (uint64_t)((2 * TEST_TRANSFER_SIZE / 1024) / (u64Elapsed / 1000000000.0));
624 RTPrintf("tstIntNetR0: transfered %d bytes in %RU64 ns (%RU64 KB/s)\n",
625 2 * TEST_TRANSFER_SIZE, u64Elapsed, u64Speed);
626
627 /*
628 * Closing time...
629 */
630 rc = RTThreadWait(ThreadRecv0, 5000, &rc2);
631 if (RT_SUCCESS(rc))
632 ThreadRecv0 = NIL_RTTHREAD;
633 if (RT_FAILURE(rc) || RT_FAILURE(rc2))
634 {
635 RTPrintf("tstIntNetR0: Failed waiting on receiver thread 0, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
636 g_cErrors++;
637 }
638
639 rc = RTThreadWait(ThreadRecv1, 5000, &rc2);
640 if (RT_SUCCESS(rc))
641 ThreadRecv1 = NIL_RTTHREAD;
642 if (RT_FAILURE(rc) || RT_FAILURE(rc2))
643 {
644 RTPrintf("tstIntNetR0: Failed waiting on receiver thread 1, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
645 g_cErrors++;
646 }
647
648 rc = INTNETR0IfClose(pIntNet, hIf0, g_pSession);
649 if (RT_SUCCESS(rc))
650 {
651 hIf0 = INTNET_HANDLE_INVALID;
652 pBuf0 = NULL;
653 }
654 else
655 {
656 RTPrintf("tstIntNetR0: INTNETIfClose failed, rc=%Rrc! (hIf0)\n", rc);
657 g_cErrors++;
658 }
659
660 rc = INTNETR0IfClose(pIntNet, hIf1, g_pSession);
661 if (RT_SUCCESS(rc))
662 {
663 hIf1 = INTNET_HANDLE_INVALID;
664 pBuf1 = NULL;
665 }
666 else
667 {
668 RTPrintf("tstIntNetR0: INTNETIfClose failed, rc=%Rrc! (hIf1)\n", rc);
669 g_cErrors++;
670 }
671
672
673 /* check if the network still exist... */
674 if (pIntNet->pNetworks)
675 {
676 RTPrintf("tstIntNetR0: The network wasn't deleted! (g_cErrors=%d)\n", g_cErrors);
677 g_cErrors++;
678 }
679 }
680 else
681 {
682 RTPrintf("tstIntNetR0: Waiting on senders failed, rc=%Rrc, rc2=%Rrc\n", rc, rc2);
683 g_cErrors++;
684 }
685
686 /*
687 * Give them a chance to complete...
688 */
689 RTThreadWait(ThreadRecv0, 5000, NULL);
690 RTThreadWait(ThreadRecv1, 5000, NULL);
691 RTThreadWait(ThreadSend0, 5000, NULL);
692 RTThreadWait(ThreadSend1, 5000, NULL);
693
694 }
695 else
696 {
697 RTPrintf("tstIntNetR0: Failed to create threads, rc=%Rrc\n", rc);
698 g_cErrors++;
699 }
700 }
701 }
702 else
703 {
704 RTPrintf("tstIntNetR0: INTNETIfWait returned %Rrc expected VINF_SUCCESS (hIf1)\n", rc);
705 g_cErrors++;
706 }
707 }
708 else
709 {
710 RTPrintf("tstIntNetR0: INTNETIfSend returned %Rrc! (hIf0)\n", rc);
711 g_cErrors++;
712 }
713 }
714 else
715 {
716 RTPrintf("tstIntNetR0: INTNETOpen returned invalid handle on success! (hIf1)\n");
717 g_cErrors++;
718 }
719
720 if (hIf1 != INTNET_HANDLE_INVALID)
721 rc = INTNETR0IfClose(pIntNet, hIf1, g_pSession);
722 }
723 else
724 {
725 RTPrintf("tstIntNetR0: INTNETOpen failed for the 2nd interface! rc=%Rrc\n", rc);
726 g_cErrors++;
727 }
728
729 if (hIf0 != INTNET_HANDLE_INVALID)
730 rc = INTNETR0IfClose(pIntNet, hIf0, g_pSession);
731 }
732 else
733 {
734 RTPrintf("tstIntNetR0: INTNETOpen returned invalid handle on success! (hIf0)\n");
735 g_cErrors++;
736 }
737 }
738 else
739 {
740 RTPrintf("tstIntNetR0: INTNETOpen failed for the 1st interface! rc=%Rrc\n", rc);
741 g_cErrors++;
742 }
743
744 /*
745 * Destroy the service.
746 */
747 INTNETR0Destroy(pIntNet);
748
749 /*
750 * Summary.
751 */
752 if (!g_cErrors)
753 RTPrintf("tstIntNetR0: SUCCESS\n");
754 else
755 RTPrintf("tstIntNetR0: FAILURE - %d errors\n", g_cErrors);
756
757 return !!g_cErrors;
758}
759
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