/* $Id$ */
/** @file
* IPRT Testcase - RTLocalIpc.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/localipc.h>
typedef struct LOCALIPCTHREADCTX
{
/** The IPC server handle. */
/** The test handle. */
{
return rc;
}
{
return 0;
}
{
if (RT_SUCCESS(rc))
{
/* Spawn a simple worker thread and let it listen for incoming connections.
* In the meanwhile we try to cancel the server and see what happens. */
if (RT_SUCCESS(rc))
{
do
{
} while (0);
}
else
}
else
return VINF_SUCCESS;
}
{
int rc;
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionConnectionThread: Listening for incoming connections ...\n");
for (;;)
{
RTTestPrintf(pCtx->hTest, RTTESTLVL_DEBUG, "testSessionConnectionThread: Listening returned with rc=%Rrc\n", rc);
if (RT_SUCCESS(rc))
{
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionConnectionThread: Got new client connection\n");
}
else
break;
}
return rc;
}
{
do
{
RTTEST_CHECK_RC_BREAK(hTest, RTLocalIpcSessionConnect(&clientSession, "tstRTLocalIpcSessionConnection",
0 /* Flags */), VINF_SUCCESS);
} while (0);
}
{
if (RT_SUCCESS(rc))
{
#ifndef VBOX_TESTCASES_WITH_NO_THREADING
/* Spawn a simple worker thread and let it listen for incoming connections.
* In the meanwhile we try to cancel the server and see what happens. */
if (RT_SUCCESS(rc))
{
do
{
int threadRc;
}
while (0);
}
else
#else
do
{
if (RT_SUCCESS(rc))
{
}
else
} while (0);
#endif
}
else
return VINF_SUCCESS;
}
{
int rc;
for (;;)
{
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionWaitThread: Listening for incoming connections ...\n");
if (RT_SUCCESS(rc))
{
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionWaitThread: Got new client connection, waiting a bit ...\n");
RTThreadSleep(2000);
}
else
{
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionWaitThread: Listening ended with rc=%Rrc\n", rc);
break;
}
}
return rc;
}
{
do
{
0 /* Flags */), VINF_SUCCESS);
/* Next, try 60s timeout. Should be returning way earlier because the server closed the
* connection after the first client connected. */
/* Last try, also should fail because the server should be not around anymore. */
} while (0);
}
{
if (RT_SUCCESS(rc))
{
/* Spawn a simple worker thread and let it listen for incoming connections.
* In the meanwhile we try to cancel the server and see what happens. */
if (RT_SUCCESS(rc))
{
do
{
/* Wait for the server thread to terminate. */
int threadRc;
/* Check if the child ran successfully. */
}
while (0);
}
else
}
else
return VINF_SUCCESS;
}
/**
* Simple structure holding the test IPC messages.
*/
typedef struct LOCALIPCTESTMSG
{
/** The actual message. */
{
for (;;)
{
size_t cbRead = RTRandU32Ex(1, sizeof(LOCALIPCTESTMSG) - cbReadTotal); /* Force a bit of fragmentation. */
&cbRead), VINF_SUCCESS);
cbReadTotal += cbRead;
{
break;
}
/* Try receiving next part of the message in another round. */
}
}
{
do
{
/* Note: At the moment we only support one client per run. */
RTTestPrintf(pCtx->hTest, RTTESTLVL_INFO, "testSessionDataThread: Listening for incoming connections ...\n");
/* Write how many rounds we're going to send data. */
RTTEST_CHECK_RC_BREAK(pCtx->hTest, RTLocalIpcSessionWrite(hSession, &cRounds, sizeof(cRounds)), VINF_SUCCESS);
{
"YayIGotRound%RU32FromTheServer", i) > 0);
RTTEST_CHECK_RC_BREAK(pCtx->hTest, RTLocalIpcSessionWrite(hSession, &msg, sizeof(msg)), VINF_SUCCESS);
}
/* Try to receive the same amount of rounds from the client. */
{
RTTEST_CHECK_BREAK(pCtx->hTest, RTStrPrintf(szMsg, sizeof(szMsg), "YayIGotRound%RU32FromTheClient", i) > 0);
szMsg), VINF_SUCCESS);
break;
}
} while (0);
}
{
return testSessionDataThreadWorker(pCtx);
}
{
do
{
0 /* Flags */), VINF_SUCCESS);
/* Receive all rounds. */
{
RTTEST_CHECK_BREAK(hTest, RTStrPrintf(szMsg, sizeof(szMsg), "YayIGotRound%RU32FromTheServer", i) > 0);
szMsg), VINF_SUCCESS);
if (RTTestErrorCount(hTest))
break;
}
/* Send all rounds back to the server. */
{
"YayIGotRound%RU32FromTheClient", i) > 0);
}
} while (0);
}
{
return testSessionDataChildWorker(*phTest);
}
{
}
{
if (RT_SUCCESS(rc))
{
#if 0
/* Run server + client in threads instead of fork'ed processes (useful for debugging). */
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
do
{
int threadRc;
} while (0);
}
#else
/* Spawn a simple worker thread and let it listen for incoming connections.
* In the meanwhile we try to cancel the server and see what happens. */
if (RT_SUCCESS(rc))
{
do
{
/* Wait for the server thread to terminate. */
int threadRc;
/* Check if the child ran successfully. */
}
while (0);
}
else
#endif
}
else
}
{
return RTEXITCODE_FAILURE;
/* Note: We assume argv[2] always contains the actual test type to perform. */
if (rcExit)
return rcExit;
RTAssertSetMayPanic(false);
#ifdef DEBUG_andy
RTAssertSetQuiet(false);
#endif
return RTTestSummaryAndDestroy(hTest);
}
{
if ( argc > 2
if (rcExit)
return rcExit;
RTTestISub("Basics");
RTAssertSetMayPanic(false);
#ifdef DEBUG_andy
RTAssertSetQuiet(false);
#endif
/* Server-side. */
RTTESTI_CHECK_RC_RET(RTLocalIpcServerCreate(&ipcServer, "BasicTest", 0 /* Invalid flags */), VERR_INVALID_PARAMETER, 1);
RTTESTI_CHECK_RC_RET(RTLocalIpcServerCreate(&ipcServer, "BasicTest", 1234 /* Invalid flags */), VERR_INVALID_PARAMETER, 1);
/* Basic server creation / destruction. */
RTTESTI_CHECK_RC_RET(RTLocalIpcServerCreate(&ipcServer, "BasicTest", RTLOCALIPC_FLAGS_MULTI_SESSION), VINF_SUCCESS, 1);
/* Client-side (per session). */
RTTESTI_CHECK_RC_RET(RTLocalIpcSessionConnect(&ipcSession, "BasicTest", 1234 /* Invalid flags */), VERR_INVALID_PARAMETER, 1);
/* Basic client creation / destruction. */
RTTESTI_CHECK_RC_RET(RTLocalIpcSessionConnect(&ipcSession, "BasicTest", 0), VERR_FILE_NOT_FOUND, 1);
if (RTTestErrorCount(hTest) == 0)
{
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}