VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTThreadExecutionTime.cpp@ 66404

Last change on this file since 66404 was 62571, checked in by vboxsync, 8 years ago

IPRT: More unused parameters.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: tstRTThreadExecutionTime.cpp 62571 2016-07-26 15:58:26Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTThreadGetExecution.
4 */
5
6/*
7 * Copyright (C) 2010-2016 Oracle Corporation
8 *
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.
16 *
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.
22 *
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.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/thread.h>
32
33#include <iprt/asm.h>
34#include <iprt/test.h>
35#include <iprt/string.h>
36#include <iprt/stream.h>
37#include <iprt/time.h>
38
39
40/*********************************************************************************************************************************
41* Global Variables *
42*********************************************************************************************************************************/
43static RTTEST g_hTest;
44static volatile uint64_t g_kernel, g_user;
45
46
47static DECLCALLBACK(int) testThread(RTTHREAD hSelf, void *pvUser)
48{
49 RT_NOREF_PV(hSelf); RT_NOREF_PV(pvUser);
50
51 uint64_t u64Now = RTTimeMilliTS();
52 uint64_t kernel, kernelStart, user, userStart;
53 RTThreadGetExecutionTimeMilli(&kernelStart, &userStart);
54 while (RTTimeMilliTS() < u64Now + 1000)
55 ;
56 RTThreadGetExecutionTimeMilli(&kernel, &user);
57 RTPrintf("kernel = %4lldms, user = %4lldms\n", kernel - kernelStart, user - userStart);
58 ASMAtomicAddU64(&g_kernel, kernel);
59 ASMAtomicAddU64(&g_user, user);
60
61 return VINF_SUCCESS;
62}
63
64
65static void test1(void)
66{
67 RTTestSub(g_hTest, "Interrupt RTThreadSleep");
68 RTTHREAD hThread[16];
69 RTMSINTERVAL msWait = 1000;
70 for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
71 {
72 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread[i], testThread, NULL, 0, RTTHREADTYPE_DEFAULT,
73 RTTHREADFLAGS_WAITABLE, "test"), VINF_SUCCESS);
74 }
75 RTThreadSleep(500);
76 RTPrintf("Waiting for %dms ...\n", msWait);
77 RTThreadSleep(msWait);
78 for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
79 RTTESTI_CHECK_RC(RTThreadWait(hThread[i], RT_INDEFINITE_WAIT, NULL), VINF_SUCCESS);
80
81 RTPrintf("sum kernel = %lldms, sum user = %lldms\n", g_kernel, g_user);
82}
83
84
85int main()
86{
87 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTThreadExecutionTime", &g_hTest);
88 if (rcExit != RTEXITCODE_SUCCESS)
89 return rcExit;
90 test1();
91
92 return RTTestSummaryAndDestroy(g_hTest);
93}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette