tstSupSem.cpp revision 84f746c9015f34e9ab096b87e063d0d6ab7fc7ae
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/* $Id$ */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/** @file
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Support Library Testcase - Ring-3 Semaphore interface.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/*
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync *
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * available from http://www.virtualbox.org. This file is free software;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * you can redistribute it and/or modify it under the terms of the GNU
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * General Public License (GPL) as published by the Free Software
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync *
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * The contents of this file may alternatively be used under the terms
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * of the Common Development and Distribution License Version 1.0
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VirtualBox OSE distribution, in which case the provisions of the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * CDDL are applicable instead of those of the GPL.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync *
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * You may elect to license modified versions of this file under the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * terms and conditions of either the GPL or the CDDL or both.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync *
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * additional information or have any questions.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/*******************************************************************************
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync* Header Files *
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync*******************************************************************************/
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <VBox/sup.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <VBox/param.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <iprt/initterm.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <iprt/test.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <iprt/stream.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync#include <iprt/string.h>
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsyncint main(int argc, char **argv)
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync{
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /*
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Init.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync int rc = RTR3InitAndSUPLib();
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync if (RT_FAILURE(rc))
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync {
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTPrintf("tstSupSem: fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync return 1;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync }
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTEST hTest;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync rc = RTTestCreate("tstSupSem", &hTest);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync if (RT_FAILURE(rc))
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync {
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTPrintf("tstSupSem: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync return 1;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync }
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync PSUPDRVSESSION pSession;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync rc = SUPR3Init(&pSession);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync if (RT_FAILURE(rc))
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync {
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync return RTTestSummaryAndDestroy(hTest);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync }
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /*
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Basic API checks.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTestSub(hTest, "Single Release Event API");
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync SUPSEMEVENT hEvent = NIL_SUPSEMEVENT;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VERR_INVALID_HANDLE);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventClose(pSession, NIL_SUPSEMEVENT), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTestSub(hTest, "Multiple Release Event API");
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiReset(pSession, hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VERR_INVALID_HANDLE);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, NIL_SUPSEMEVENTMULTI), VINF_SUCCESS);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /*
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Done.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync return RTTestSummaryAndDestroy(hTest);
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync}
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync