VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/ntGetTimerResolution.cpp@ 79325

Last change on this file since 79325 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.2 KB
Line 
1/* $Id: ntGetTimerResolution.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT - Win32 (NT) testcase for getting the timer resolution.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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#define _WIN32_WINNT 0x0500
32#include <iprt/win/windows.h>
33#include <iprt/types.h>
34#include <stdio.h>
35
36extern "C" {
37/* from sysinternals. */
38NTSYSAPI LONG NTAPI NtQueryTimerResolution(OUT PULONG MaximumResolution, OUT PULONG MinimumResolution, OUT PULONG CurrentResolution);
39}
40
41
42int main()
43{
44 ULONG Min = UINT32_MAX;
45 ULONG Max = UINT32_MAX;
46 ULONG Cur = UINT32_MAX;
47 NtQueryTimerResolution(&Max, &Min, &Cur);
48 printf("NtQueryTimerResolution -> Max=%08luns Min=%08luns Cur=%08luns\n", Min * 100, Max * 100, Cur * 100);
49
50#if 0
51 /* figure out the 100ns relative to the 1970 epoc. */
52 SYSTEMTIME st;
53 st.wYear = 1970;
54 st.wMonth = 1;
55 st.wDayOfWeek = 4; /* Thor's day. */
56 st.wDay = 1;
57 st.wHour = 0;
58 st.wMinute = 0;
59 st.wSecond = 0;
60 st.wMilliseconds = 0;
61
62 FILETIME ft;
63 if (SystemTimeToFileTime(&st, &ft))
64 {
65 printf("epoc is %I64u (0x%08x%08x)\n", ft, ft.dwHighDateTime, ft.dwLowDateTime);
66 if (FileTimeToSystemTime(&ft, &st))
67 printf("unix epoc: %d-%02d-%02d %02d:%02d:%02d.%03d (week day %d)\n",
68 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wDayOfWeek);
69 else
70 printf("FileTimeToSystemTime failed, lasterr=%d\n", GetLastError());
71 }
72 else
73 printf("SystemTimeToFileTime failed, lasterr=%d\n", GetLastError());
74
75 ft.dwHighDateTime = 0;
76 ft.dwLowDateTime = 0;
77 if (FileTimeToSystemTime(&ft, &st))
78 printf("nt time start: %d-%02d-%02d %02d:%02d:%02d.%03d (week day %d)\n",
79 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wDayOfWeek);
80 else
81 printf("FileTimeToSystemTime failed, lasterr=%d\n", GetLastError());
82#endif
83 return 0;
84}
85
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