1
/* $Id: tstRTThreadExecutionTime.cpp 34629 2010-12-02 17:09:09Z vboxsync $ */
3
* IPRT Testcase - RTThreadGetExecution.
7
* Copyright (C) 2010 Oracle Corporation
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17
* The contents of this file may alternatively be used under the terms
18
* of the Common Development and Distribution License Version 1.0
19
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20
* VirtualBox OSE distribution, in which case the provisions of the
21
* CDDL are applicable instead of those of the GPL.
23
* You may elect to license modified versions of this file under the
24
* terms and conditions of either the GPL or the CDDL or both.
27
/*******************************************************************************
29
*******************************************************************************/
30
#include <iprt/thread.h>
33
#include <iprt/test.h>
34
#include <iprt/string.h>
35
#include <iprt/stream.h>
36
#include <iprt/time.h>
39
/*******************************************************************************
41
*******************************************************************************/
42
static RTTEST g_hTest;
43
static volatile uint64_t g_kernel, g_user;
46
static DECLCALLBACK(int) testThread(RTTHREAD hSelf, void *pvUser)
48
uint64_t u64Now = RTTimeMilliTS();
49
uint64_t kernel, kernelStart, user, userStart;
50
RTThreadGetExecutionTimeMilli(&kernelStart, &userStart);
51
while (RTTimeMilliTS() < u64Now + 1000)
53
RTThreadGetExecutionTimeMilli(&kernel, &user);
54
RTPrintf("kernel = %4lldms, user = %4lldms\n", kernel - kernelStart, user - userStart);
55
ASMAtomicAddU64(&g_kernel, kernel);
56
ASMAtomicAddU64(&g_user, user);
62
static void test1(void)
64
RTTestSub(g_hTest, "Interrupt RTThreadSleep");
66
RTMSINTERVAL msWait = 1000;
67
for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
69
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread[i], testThread, NULL, 0, RTTHREADTYPE_DEFAULT,
70
RTTHREADFLAGS_WAITABLE, "test"), VINF_SUCCESS);
73
RTPrintf("Waiting for %dms ...\n", msWait);
74
RTThreadSleep(msWait);
75
for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
76
RTTESTI_CHECK_RC(RTThreadWait(hThread[i], RT_INDEFINITE_WAIT, NULL), VINF_SUCCESS);
78
RTPrintf("sum kernel = %lldms, sum user = %lldms\n", g_kernel, g_user);
84
RTEXITCODE rcExit = RTTestInitAndCreate("tstRTThreadExecutionTime", &g_hTest);
85
if (rcExit != RTEXITCODE_SUCCESS)
89
return RTTestSummaryAndDestroy(g_hTest);