tstRTLockValidator.cpp revision 4538710c37c199a82a3bea00007add73cdb0f3b6
/* $Id$ */
/** @file
* IPRT Testcase - RTLockValidator.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/critsect.h>
#include <iprt/lockvalidator.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static uint32_t g_cThreads;
/**
* Spin until someone else has taken ownership of the critical section.
*
* @returns true on success, false on abort.
* @param pCritSect The critical section.
*/
{
unsigned iLoop = 0;
while (!RTCritSectIsOwned(pCritSect))
{
if (!RTCritSectIsInitialized(pCritSect))
return false;
iLoop++;
}
return true;
}
/**
* Waits for a thread to enter a sleeping state.
*
* @returns true on success, false on abort.
* @param hThread The thread.
*/
{
{
if (RTTHREAD_IS_SLEEPING(enmState))
return true;
if (enmState != RTTHREADSTATE_RUNNING)
return false;
}
}
{
{
int rc;
if (i != g_cThreads - 1)
else
{
/* the last thread triggers the deadlock. */
for (unsigned i = 0; i < g_cThreads - 1; i++)
}
if (RT_SUCCESS(rc))
}
return VINF_SUCCESS;
}
{
uint32_t i;
for (i = 0; i < cThreads; i++)
for (i = 0; i < cThreads && g_ahThreads[i]; i++)
g_ahThreads[i] = NIL_RTTHREAD;
int rc = VINF_SUCCESS;
RTTEST_CHECK_RC_OK(g_hTest, rc = RTThreadCreateF(&g_ahThreads[i], test1Thread, (void *)(uintptr_t)i, 0,
if (RT_SUCCESS(rc))
{
int rc2 = VINF_SUCCESS;
i = cThreads;
{
if (RT_SUCCESS(rc))
g_ahThreads[i] = NIL_RTTHREAD;
}
}
if (g_ahThreads[i] != NIL_RTTHREAD)
{
g_ahThreads[i] = NIL_RTTHREAD;
}
}
static bool testIsLockValidationCompiledIn(void)
{
/* Add check for the other types as we add more scenarios. */
return fRet;
}
int main()
{
/*
* Init.
*/
if (rc)
return rc;
RTLockValidatorSetEnabled(true);
RTLockValidatorSetMayPanic(false);
if (!testIsLockValidationCompiledIn())
return RTTestErrorCount(g_hTest) > 0
test1(2);
test1(3);
test1(15);
test1(30);
return RTTestSummaryAndDestroy(g_hTest);
}