tstRTR0SemMutex.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * IPRT R0 Testcase - Mutex Semaphores.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2009-2010 Oracle Corporation
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * available from http://www.virtualbox.org. This file is free software;
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * you can redistribute it and/or modify it under the terms of the GNU
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * General Public License (GPL) as published by the Free Software
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * The contents of this file may alternatively be used under the terms
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * of the Common Development and Distribution License Version 1.0
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * CDDL are applicable instead of those of the GPL.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * You may elect to license modified versions of this file under the
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * terms and conditions of either the GPL or the CDDL or both.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync/*******************************************************************************
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync* Header Files *
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync*******************************************************************************/
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync/*******************************************************************************
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync* Global Variables *
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync*******************************************************************************/
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync/** The mutex used in test #2. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * Service request callback function.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * @returns VBox status code.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * @param pSession The caller's session.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * @param u64Arg 64-bit integer argument.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * @param pReqHdr The request header. Input / Output. Optional.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsyncDECLEXPORT(int) TSTRTR0SemMutexSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync#define SET_ERROR(szFmt) do { if (!*pszErr) RTStrPrintf(pszErr, cchErr, "!" szFmt); } while (0)
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync#define SET_ERROR1(szFmt, a1) do { if (!*pszErr) RTStrPrintf(pszErr, cchErr, "!" szFmt, a1); } while (0)
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync#define SET_ERROR2(szFmt, a1, a2) do { if (!*pszErr) RTStrPrintf(pszErr, cchErr, "!" szFmt, a1, a2); } while (0)
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync#define SET_ERROR3(szFmt, a1, a2, a3) do { if (!*pszErr) RTStrPrintf(pszErr, cchErr, "!" szFmt, a1, a2, a3); } while (0)
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync RTStrPrintf(pszErr, cchErr, "!%s -> %Rrc, expected %Rrc. line %u", szOp, rc, rcExpect, __LINE__); \
d0f7737e04e7174cc1d27c5e3dfa3ba1156f3bc0vboxsync SUPR0Printf("%s -> %d, expected %d. line %u", szOp, rc, rcExpect, __LINE__); \
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync * Set up test timeout (when applicable).
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync SET_ERROR1("Timeout is too large (max 120): %lld", u64Arg);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * The big switch.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexCreate");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * The interruptible version first.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, polling. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, wait for ever. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync rc = RTSemMutexRequestNoResume(hMtx, RT_INDEFINITE_WAIT);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(indef_wait)");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, wait a tiny while. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(133)");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* nested request and release. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync rc = RTSemMutexRequestNoResume(hMtx, RT_INDEFINITE_WAIT);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume#1");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync rc = RTSemMutexRequestNoResume(hMtx, RT_INDEFINITE_WAIT);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume#2");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync rc = RTSemMutexRequestNoResume(hMtx, RT_INDEFINITE_WAIT);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume#3");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#3");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync rc = RTSemMutexRequestNoResume(hMtx, RT_INDEFINITE_WAIT);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume#3b");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#3b");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#2");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#1");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync * The uninterruptible variant.
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, polling. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, wait for ever. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest(indef_wait)");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* simple request and release, wait a tiny while. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest(133)");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* nested request and release. */
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest#1");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest#2");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest#3");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#3");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequest#3b");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#3b");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#2");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease#1");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync } while (false);
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexDestroy");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexCreate");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync for (unsigned i = 0; i < 200; i++)
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync rc = RTSemMutexRequestNoResume(g_hMtxTest2, RT_INDEFINITE_WAIT);
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(,indef_wait)");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync rc = RTSemMutexRequestNoResume(g_hMtxTest2, 30000);
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(,30000)");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync if ((i % 16) == 15 && RTTimeSystemMilliTS() - StartTS >= cMsMax)
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync for (unsigned i = 0; i < 1000000; i++)
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync rc = RTSemMutexRequestNoResume(g_hMtxTest2, RT_INDEFINITE_WAIT);
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(,indef_wait)");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync rc = RTSemMutexRequestNoResume(g_hMtxTest2, 30000);
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume(,30000)");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync if ((i % 256) == 255 && RTTimeSystemMilliTS() - StartTS >= cMsMax)
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync for (unsigned i = 0; i < 1024; i++)
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync rc = RTSemMutexRequestNoResume(g_hMtxTest2, (i % 32));
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRequestNoResume");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexRelease");
4da34d78db758ccce247d0cc80b926a873a7a57cvboxsync CHECK_RC_BREAK(rc, VINF_SUCCESS, "RTSemMutexCreate");
01f0d2858d4377ecf19f5aac2531efe99fef9ffcvboxsync /* The error indicator is the '!' in the message buffer. */