tstRTSemEventMulti.cpp revision deecef7b65012715a024874f954be670896766a5
/* $Id$ */
/** @file
* IPRT Testcase - Multiple Release Event Semaphores.
*/
/*
* Copyright (C) 2009-2010 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/semaphore.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The test handle. */
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
static void test1(void)
{
RTTestISub("Three threads");
/*
* Create the threads and let them block on the event multi semaphore.
*/
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, test1Thread2, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test2"), VINF_SUCCESS);
RTThreadSleep(100);
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, test1Thread1, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"), VINF_SUCCESS);
/* Force first thread (which has a timeout of 1 second) to timeout in the
* first wait, and the second wait will succeed. */
}
{
#if 1
#else
0),
RTTimeSystemNanoTS() + 1000*i),
RTTimeNanoTS() + 1000*i),
0),
#endif
}
{
#if 1
#else
0),
RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS);
RTTimeSystemNanoTS() + 1000*i),
RTTimeNanoTS() + 1000*i),
0),
_1G),
RTTimeSystemMilliTS() + 1000*i),
RTTimeMilliTS() + 1000*i),
0),
_1M),
#endif
}
static void testBasics(void)
{
RTTestISub("Basics");
/* The semaphore is created in a reset state, calling reset explicitly
shouldn't make any difference. */
if (RTTestIErrorCount())
return;
/* When signalling the semaphore all successive wait calls shall
succeed, signalling it again should make no difference. */
if (RTTestIErrorCount())
return;
/* After resetting it we should time out again. */
if (RTTestIErrorCount())
return;
/* The number of resets or signal calls shouldn't matter. */
/* Destroy it. */
/* Whether it is reset (above), signalled or not used shouldn't matter. */
}
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
testBasics();
if (!RTTestErrorCount(g_hTest))
{
test1();
}
return RTTestSummaryAndDestroy(g_hTest);
}