tstRTR0SemMutexDriver.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* IPRT R0 Testcase - Thread Preemption, driver program.
*/
/*
* Copyright (C) 2009-2012 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/initterm.h>
#ifdef VBOX
# include "tstRTR0SemMutex.h"
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct TSTRTR0SEMMUTEXREQ
{
char szMsg[256];
typedef TSTRTR0SEMMUTEXREQ *PTSTRTR0SEMMUTEXREQ;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Thread function employed by tstDoThreadedTest.
*
* @returns IPRT status code.
* @param hThreadSelf The thread.
* @param pvUser The operation to perform.
*/
{
rcCheck);
{
return VERR_GENERAL_FAILURE;
}
return VINF_SUCCESS;
}
/**
* Performs a threaded test.
*
* @returns true on success, false on failure.
* @param enmSetup The setup operation number.
* @param enmDo The do-it operation number.
* @param enmCleanup The cleanup operation number.
* @param cThreads The number of threads.
* @param pReq The request structure.
* @param pszTest The test name.
*/
static bool tstDoThreadedTest(TSTRTR0SEMMUTEX enmSetup, TSTRTR0SEMMUTEX enmDo, TSTRTR0SEMMUTEX enmCleanup,
{
/*
* Setup.
*/
RTTESTI_CHECK_RC_RET(SUPR3CallR0Service("tstRTR0SemMutex", sizeof("tstRTR0SemMutex") - 1, enmSetup, 0, &pReq->Hdr),
VINF_SUCCESS, false);
/*
* Test execution.
*/
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
ahThreads[i] = NIL_RTTHREAD;
int rc = VINF_SUCCESS;
rc = RTThreadCreateF(&ahThreads[i], tstThreadFn, (void *)(uintptr_t)RT_MAKE_U32(enmDo, cSecs), 0, RTTHREADTYPE_DEFAULT,
RTTHREADFLAGS_WAITABLE, "test-%u", i);
for (unsigned i = 0; i < cThreads; i++)
if (ahThreads[i] != NIL_RTTHREAD)
{
int rcThread = VINF_SUCCESS;
if (RT_SUCCESS(rc2))
{
ahThreads[i] = NIL_RTTHREAD;
}
else if (RT_SUCCESS(rc))
}
/*
* Cleanup.
*/
RTTESTI_CHECK_RC_RET(rc = SUPR3CallR0Service("tstRTR0SemMutex", sizeof("tstRTR0SemMutex") - 1, enmCleanup, 0, &pReq->Hdr),
VINF_SUCCESS, false);
if (RT_FAILURE(rc))
for (unsigned i = 0; i < cThreads; i++)
if (ahThreads[i] != NIL_RTTHREAD)
return RT_SUCCESS(rc);
}
{
#ifndef VBOX
RTPrintf("tstSup: SKIPPED\n");
return 0;
#else
/*
* Init.
*/
if (rc)
return rc;
if (RT_FAILURE(rc))
{
return RTTestSummaryAndDestroy(hTest);
}
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
{
return RTTestSummaryAndDestroy(hTest);
}
void *pvImageBase;
"TSTRTR0SemMutexSrvReqHandler",
&pvImageBase);
if (RT_FAILURE(rc))
{
return RTTestSummaryAndDestroy(hTest);
}
/* test request */
/*
* Sanity checks.
*/
if (RT_FAILURE(rc))
return RTTestSummaryAndDestroy(hTest);
return RTTestSummaryAndDestroy(hTest);
if (RT_FAILURE(rc))
return RTTestSummaryAndDestroy(hTest);
RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg));
return RTTestSummaryAndDestroy(hTest);
/*
* Basic tests, bail out on failure.
*/
if (RT_FAILURE(rc))
return RTTestSummaryAndDestroy(hTest);
{
return RTTestSummaryAndDestroy(hTest);
}
/*
* Tests with multiple threads for bugs in the contention part of the code.
* Test #2: Try to hold the semaphore for 1 ms.
* Test #3: Grab and release immediately.
* Test #4: Timeout checks. Try grab it for 0-32 ms and hold it for 1 s.
*/
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST2_SETUP, TSTRTR0SEMMUTEX_TEST2_DO, TSTRTR0SEMMUTEX_TEST2_CLEANUP, 1, 1, &Req, "test #2");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST2_SETUP, TSTRTR0SEMMUTEX_TEST2_DO, TSTRTR0SEMMUTEX_TEST2_CLEANUP, 2, 3, &Req, "test #2");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST2_SETUP, TSTRTR0SEMMUTEX_TEST2_DO, TSTRTR0SEMMUTEX_TEST2_CLEANUP, 3, 3, &Req, "test #2");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST2_SETUP, TSTRTR0SEMMUTEX_TEST2_DO, TSTRTR0SEMMUTEX_TEST2_CLEANUP, 9, 3, &Req, "test #2");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST3_SETUP, TSTRTR0SEMMUTEX_TEST3_DO, TSTRTR0SEMMUTEX_TEST3_CLEANUP, 1, 1, &Req, "test #3");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST3_SETUP, TSTRTR0SEMMUTEX_TEST3_DO, TSTRTR0SEMMUTEX_TEST3_CLEANUP, 2, 3, &Req, "test #3");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST3_SETUP, TSTRTR0SEMMUTEX_TEST3_DO, TSTRTR0SEMMUTEX_TEST3_CLEANUP, 3, 3, &Req, "test #3");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST3_SETUP, TSTRTR0SEMMUTEX_TEST3_DO, TSTRTR0SEMMUTEX_TEST3_CLEANUP, 9, 3, &Req, "test #3");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST4_SETUP, TSTRTR0SEMMUTEX_TEST4_DO, TSTRTR0SEMMUTEX_TEST4_CLEANUP, 1, 1, &Req, "test #4");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST4_SETUP, TSTRTR0SEMMUTEX_TEST4_DO, TSTRTR0SEMMUTEX_TEST4_CLEANUP, 2, 3, &Req, "test #4");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST4_SETUP, TSTRTR0SEMMUTEX_TEST4_DO, TSTRTR0SEMMUTEX_TEST4_CLEANUP, 3, 3, &Req, "test #4");
tstDoThreadedTest(TSTRTR0SEMMUTEX_TEST4_SETUP, TSTRTR0SEMMUTEX_TEST4_DO, TSTRTR0SEMMUTEX_TEST4_CLEANUP, 9, 3, &Req, "test #4");
/*
* Done.
*/
return RTTestSummaryAndDestroy(hTest);
#endif
}