3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync/* $Id$ */
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync/** @file
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * IPRT Testcase - RTThreadPoke.
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync */
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync/*
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * Copyright (C) 2010 Oracle Corporation
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync *
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * available from http://www.virtualbox.org. This file is free software;
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * General Public License (GPL) as published by the Free Software
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync *
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * The contents of this file may alternatively be used under the terms
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * of the Common Development and Distribution License Version 1.0
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * VirtualBox OSE distribution, in which case the provisions of the
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * CDDL are applicable instead of those of the GPL.
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync *
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * You may elect to license modified versions of this file under the
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync * terms and conditions of either the GPL or the CDDL or both.
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync */
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync/*******************************************************************************
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync* Header Files *
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync*******************************************************************************/
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#include <iprt/thread.h>
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#include <iprt/test.h>
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#include <iprt/string.h>
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync/*******************************************************************************
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync* Global Variables *
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync*******************************************************************************/
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsyncstatic RTTEST g_hTest;
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#ifndef RT_OS_WINDOWS
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsyncstatic DECLCALLBACK(int) test1Thread(RTTHREAD hSelf, void *pvUser)
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync{
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTEST_CHECK_RC(g_hTest, RTThreadSleep(60*1000), VERR_INTERRUPTED);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync return VINF_SUCCESS;
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync}
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsyncstatic void test1(void)
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync{
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTestSub(g_hTest, "Interrupt RTThreadSleep");
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTHREAD hThread;
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread, test1Thread, NULL, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"),
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync VINF_SUCCESS);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTThreadSleep(500); RTThreadSleep(1500); /* fudge */
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTESTI_CHECK_RC(RTThreadPoke(hThread), VINF_SUCCESS);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTTESTI_CHECK_RC(RTThreadWait(hThread, RT_INDEFINITE_WAIT, NULL), VINF_SUCCESS);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync}
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#endif /* !RT_OS_WINDOWS */
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsyncint main()
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync{
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstRTThreadPoke", &g_hTest);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync if (rcExit != RTEXITCODE_SUCCESS)
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync return rcExit;
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#ifdef RT_OS_WINDOWS
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync return RTTestSkipAndDestroy(g_hTest, "No RTThreadPoke on Windows");
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#else
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync test1();
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync return RTTestSummaryAndDestroy(g_hTest);
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync#endif
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync}
3c672b6b491561df7771b9a19012f3cd14fdb672vboxsync