VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.5 KB
Line 
1/* $Id: ntGetTimerResolution.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - Win32 (NT) testcase for getting the timer resolution.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define _WIN32_WINNT 0x0500
42#include <iprt/win/windows.h>
43#include <iprt/types.h>
44#include <stdio.h>
45
46extern "C" {
47/* from sysinternals. */
48NTSYSAPI LONG NTAPI NtQueryTimerResolution(OUT PULONG MaximumResolution, OUT PULONG MinimumResolution, OUT PULONG CurrentResolution);
49}
50
51
52int main()
53{
54 ULONG Min = UINT32_MAX;
55 ULONG Max = UINT32_MAX;
56 ULONG Cur = UINT32_MAX;
57 NtQueryTimerResolution(&Max, &Min, &Cur);
58 printf("NtQueryTimerResolution -> Max=%08luns Min=%08luns Cur=%08luns\n", Min * 100, Max * 100, Cur * 100);
59
60#if 0
61 /* figure out the 100ns relative to the 1970 epoc. */
62 SYSTEMTIME st;
63 st.wYear = 1970;
64 st.wMonth = 1;
65 st.wDayOfWeek = 4; /* Thor's day. */
66 st.wDay = 1;
67 st.wHour = 0;
68 st.wMinute = 0;
69 st.wSecond = 0;
70 st.wMilliseconds = 0;
71
72 FILETIME ft;
73 if (SystemTimeToFileTime(&st, &ft))
74 {
75 printf("epoc is %I64u (0x%08x%08x)\n", ft, ft.dwHighDateTime, ft.dwLowDateTime);
76 if (FileTimeToSystemTime(&ft, &st))
77 printf("unix epoc: %d-%02d-%02d %02d:%02d:%02d.%03d (week day %d)\n",
78 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wDayOfWeek);
79 else
80 printf("FileTimeToSystemTime failed, lasterr=%d\n", GetLastError());
81 }
82 else
83 printf("SystemTimeToFileTime failed, lasterr=%d\n", GetLastError());
84
85 ft.dwHighDateTime = 0;
86 ft.dwLowDateTime = 0;
87 if (FileTimeToSystemTime(&ft, &st))
88 printf("nt time start: %d-%02d-%02d %02d:%02d:%02d.%03d (week day %d)\n",
89 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wDayOfWeek);
90 else
91 printf("FileTimeToSystemTime failed, lasterr=%d\n", GetLastError());
92#endif
93 return 0;
94}
95
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