VirtualBox

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

Last change on this file since 10692 was 10681, checked in by vboxsync, 17 years ago

intnet: More TrunkIf code.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette