ReactOS 0.4.15-dev-7968-g24a56f8
time.c
Go to the documentation of this file.
1/*
2 * Unit test suite for ntdll time functions
3 *
4 * Copyright 2004 Rein Klazes
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#ifndef __REACTOS__
22#define NONAMELESSUNION
23#endif
24#include "ntdll_test.h"
25#ifndef __REACTOS__
26#include "ddk/wdm.h"
27#else /* FIXME: Inspect */
28
29typedef struct _KSYSTEM_TIME {
34
35typedef enum _NT_PRODUCT_TYPE {
40
41#define PROCESSOR_FEATURE_MAX 64
42
44{
49
50#define MAX_WOW64_SHARED_ENTRIES 16
51
52typedef struct _KUSER_SHARED_DATA {
56 volatile KSYSTEM_TIME SystemTime;
73 volatile ULONG TimeSlip;
79 volatile ULONG ActiveConsoleId;
80 volatile ULONG DismountCount;
85 ULONG TraceLogging;
90 union {
91 volatile KSYSTEM_TIME TickCount;
92 volatile ULONG64 TickCountQuad;
96} KSHARED_USER_DATA, *PKSHARED_USER_DATA;
97
98#endif /* !__REACTOS__ */
99
100#define TICKSPERSEC 10000000
101#define TICKSPERMSEC 10000
102#define SECSPERDAY 86400
103
104static VOID (WINAPI *pRtlTimeToTimeFields)( const LARGE_INTEGER *liTime, PTIME_FIELDS TimeFields) ;
105static VOID (WINAPI *pRtlTimeFieldsToTime)( PTIME_FIELDS TimeFields, PLARGE_INTEGER Time) ;
106static NTSTATUS (WINAPI *pNtQueryPerformanceCounter)( LARGE_INTEGER *counter, LARGE_INTEGER *frequency );
107static NTSTATUS (WINAPI *pRtlQueryTimeZoneInformation)( RTL_TIME_ZONE_INFORMATION *);
108static NTSTATUS (WINAPI *pRtlQueryDynamicTimeZoneInformation)( RTL_DYNAMIC_TIME_ZONE_INFORMATION *);
109static ULONG (WINAPI *pNtGetTickCount)(void);
110
111static const int MonthLengths[2][12] =
112{
113 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
114 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
115};
116
117static inline BOOL IsLeapYear(int Year)
118{
119 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
120}
121
122/* start time of the tests */
123static TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0};
124
126{
127 LARGE_INTEGER litime , liresult;
128 TIME_FIELDS tfresult;
129 int i=0;
130 litime.QuadPart = ((ULONGLONG)0x0144017a << 32) | 0xf0b0a980;
131 while( tftest.Year < 2110 ) {
132 /* test at the last second of the month */
133 pRtlTimeToTimeFields( &litime, &tfresult);
134 ok( tfresult.Year == tftest.Year && tfresult.Month == tftest.Month &&
135 tfresult.Day == tftest.Day && tfresult.Hour == tftest.Hour &&
136 tfresult.Minute == tftest.Minute && tfresult.Second == tftest.Second,
137 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
140 tfresult.Year, tfresult.Month, tfresult.Day,
141 tfresult.Hour, tfresult.Minute, tfresult.Second);
142 /* test the inverse */
143 pRtlTimeFieldsToTime( &tfresult, &liresult);
144 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
145 tfresult.Year, tfresult.Month, tfresult.Day,
146 tfresult.Hour, tfresult.Minute, tfresult.Second,
147 (int) (liresult.QuadPart - litime.QuadPart) );
148 /* one second later is beginning of next month */
149 litime.QuadPart += TICKSPERSEC ;
150 pRtlTimeToTimeFields( &litime, &tfresult);
151 ok( tfresult.Year == tftest.Year + (tftest.Month ==12) &&
152 tfresult.Month == tftest.Month % 12 + 1 &&
153 tfresult.Day == 1 && tfresult.Hour == 0 &&
154 tfresult.Minute == 0 && tfresult.Second == 0,
155 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
156 tftest.Year + (tftest.Month ==12),
157 tftest.Month % 12 + 1, 1, 0, 0, 0,
158 tfresult.Year, tfresult.Month, tfresult.Day,
159 tfresult.Hour, tfresult.Minute, tfresult.Second);
160 /* test the inverse */
161 pRtlTimeFieldsToTime( &tfresult, &liresult);
162 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
163 tfresult.Year, tfresult.Month, tfresult.Day,
164 tfresult.Hour, tfresult.Minute, tfresult.Second,
165 (int) (liresult.QuadPart - litime.QuadPart) );
166 /* advance to the end of the month */
167 litime.QuadPart -= TICKSPERSEC ;
168 if( tftest.Month == 12) {
169 tftest.Month = 1;
170 tftest.Year += 1;
171 } else
172 tftest.Month += 1;
175 }
176}
177
179{
182
183 status = pNtQueryPerformanceCounter(NULL, NULL);
184 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
185 status = pNtQueryPerformanceCounter(NULL, &frequency);
186 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
187 status = pNtQueryPerformanceCounter(&counter, (void *)0xdeadbee0);
188 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
189 status = pNtQueryPerformanceCounter((void *)0xdeadbee0, &frequency);
190 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
191
192 status = pNtQueryPerformanceCounter(&counter, NULL);
193 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
194 status = pNtQueryPerformanceCounter(&counter, &frequency);
195 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
196}
197
199{
202
203 /* test RtlQueryTimeZoneInformation returns an indirect string,
204 e.g. @tzres.dll,-32 (Vista or later) */
205 if (!pRtlQueryTimeZoneInformation || !pRtlQueryDynamicTimeZoneInformation)
206 {
207 win_skip("Time zone name tests requires Vista or later\n");
208 return;
209 }
210
211 memset(&tzinfo, 0, sizeof(tzinfo));
212 status = pRtlQueryDynamicTimeZoneInformation(&tzinfo);
214 "RtlQueryDynamicTimeZoneInformation failed, got %08x\n", status);
215 todo_wine ok(tzinfo.StandardName[0] == '@',
216 "standard time zone name isn't an indirect string, got %s\n",
218 todo_wine ok(tzinfo.DaylightName[0] == '@',
219 "daylight time zone name isn't an indirect string, got %s\n",
221
222 memset(&tzinfo, 0, sizeof(tzinfo));
223 status = pRtlQueryTimeZoneInformation((RTL_TIME_ZONE_INFORMATION *)&tzinfo);
225 "RtlQueryTimeZoneInformation failed, got %08x\n", status);
226 todo_wine ok(tzinfo.StandardName[0] == '@',
227 "standard time zone name isn't an indirect string, got %s\n",
229 todo_wine ok(tzinfo.DaylightName[0] == '@',
230 "daylight time zone name isn't an indirect string, got %s\n",
232}
233
234static void test_NtGetTickCount(void)
235{
236#ifndef _WIN64
237 KSHARED_USER_DATA *user_shared_data = (void *)0x7ffe0000;
238 LONG diff;
239 int i;
240
241 if (!pNtGetTickCount)
242 {
243 win_skip("NtGetTickCount is not available\n");
244 return;
245 }
246
247 for (i = 0; i < 5; ++i)
248 {
249 diff = (user_shared_data->TickCountQuad * user_shared_data->TickCountMultiplier) >> 24;
250 diff = pNtGetTickCount() - diff;
251 ok(diff < 32, "NtGetTickCount - TickCountQuad too high, expected < 32 got %d\n", diff);
252 Sleep(50);
253 }
254#endif
255}
256
258{
259 HMODULE mod = GetModuleHandleA("ntdll.dll");
260 pRtlTimeToTimeFields = (void *)GetProcAddress(mod,"RtlTimeToTimeFields");
261 pRtlTimeFieldsToTime = (void *)GetProcAddress(mod,"RtlTimeFieldsToTime");
262 pNtQueryPerformanceCounter = (void *)GetProcAddress(mod, "NtQueryPerformanceCounter");
263 pNtGetTickCount = (void *)GetProcAddress(mod,"NtGetTickCount");
264 pRtlQueryTimeZoneInformation =
265 (void *)GetProcAddress(mod, "RtlQueryTimeZoneInformation");
266 pRtlQueryDynamicTimeZoneInformation =
267 (void *)GetProcAddress(mod, "RtlQueryDynamicTimeZoneInformation");
268
269 if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
271 else
272 win_skip("Required time conversion functions are not available\n");
276}
unsigned char BOOLEAN
#define VOID
Definition: acefi.h:82
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NTSTATUS
Definition: precomp.h:21
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
enum _NT_PRODUCT_TYPE * PNT_PRODUCT_TYPE
_NT_PRODUCT_TYPE
Definition: shellpath.c:63
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductLanManNt
Definition: shellpath.c:65
@ NtProductServer
Definition: shellpath.c:66
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int mod
Definition: i386-dis.c:1288
#define wine_dbgstr_w
Definition: kernel32.h:34
__u16 time
Definition: mkdosfs.c:8
unsigned __int64 ULONG64
Definition: imports.h:198
#define TICKSPERSEC
Definition: time.c:40
#define todo_wine
Definition: custom.c:79
#define SECSPERDAY
Definition: time.c:33
static void test_NtQueryPerformanceCounter(void)
Definition: time.c:178
static void test_pRtlTimeToTimeFields(void)
Definition: time.c:125
static PLARGE_INTEGER Time
Definition: time.c:105
static LARGE_INTEGER * frequency
Definition: time.c:106
static TIME_FIELDS tftest
Definition: time.c:123
static void test_NtGetTickCount(void)
Definition: time.c:234
static const int MonthLengths[2][12]
Definition: time.c:111
static PTIME_FIELDS TimeFields
Definition: time.c:104
static void test_RtlQueryTimeZoneInformation(void)
Definition: time.c:198
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define win_skip
Definition: test.h:160
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
LONG High1Time
Definition: ketypes.h:930
LONG High2Time
Definition: ketypes.h:931
ULONG LowPart
Definition: ketypes.h:929
BOOLEAN ProductTypeIsValid
Definition: ketypes.h:1286
volatile KSYSTEM_TIME SystemTime
Definition: ketypes.h:1275
ULONG TickCountLowDeprecated
Definition: ketypes.h:1272
NT_PRODUCT_TYPE NtProductType
Definition: ketypes.h:1285
ULONG SystemCallReturn
Definition: ketypes.h:1342
ULONGLONG TestRetInstruction
Definition: ketypes.h:1340
volatile ULONG ActiveConsoleId
Definition: ketypes.h:1301
BOOLEAN KdDebuggerEnabled
Definition: ketypes.h:1297
ULONG NtMajorVersion
Definition: ketypes.h:1287
ULONG TickCountMultiplier
Definition: ketypes.h:1273
ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES]
Definition: ketypes.h:1360
UCHAR NXSupportPolicy
Definition: ketypes.h:1299
BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX]
Definition: ketypes.h:1289
ULONG LastSystemRITEventTickCount
Definition: ketypes.h:1304
ULONG NumberOfPhysicalPages
Definition: ketypes.h:1305
volatile ULONG64 TickCountQuad
Definition: ketypes.h:1347
volatile KSYSTEM_TIME TickCount
Definition: ketypes.h:1346
ULONG LargePageMinimum
Definition: ketypes.h:1283
volatile KSYSTEM_TIME InterruptTime
Definition: ketypes.h:1274
ULONG CryptoExponent
Definition: ketypes.h:1281
BOOLEAN SafeBootMode
Definition: ketypes.h:1306
volatile ULONG TimeSlip
Definition: ketypes.h:1292
LARGE_INTEGER SystemExpirationDate
Definition: ketypes.h:1295
ULONG NtMinorVersion
Definition: ketypes.h:1288
WCHAR NtSystemRoot[260]
Definition: ketypes.h:1279
USHORT ImageNumberHigh
Definition: ketypes.h:1278
ULONG MaxStackTraceDepth
Definition: ketypes.h:1280
ULONG Reserved2[7]
Definition: ketypes.h:1284
ULONG ComPlusPackage
Definition: ketypes.h:1303
ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture
Definition: ketypes.h:1293
volatile ULONG DismountCount
Definition: ketypes.h:1302
volatile KSYSTEM_TIME TimeZoneBias
Definition: ketypes.h:1276
union _KUSER_SHARED_DATA::@4131 DUMMYUNIONNAME
ULONGLONG SystemCallPad[3]
Definition: ketypes.h:1343
USHORT ImageNumberLow
Definition: ketypes.h:1277
Definition: ps.c:97
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
int64_t LONGLONG
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
#define IsLeapYear(y)
Definition: variant.c:1048
#define WINAPI
Definition: msvc.h:6
#define PROCESSOR_FEATURE_MAX
struct _KSYSTEM_TIME KSYSTEM_TIME
#define MAX_WOW64_SHARED_ENTRIES
Definition: ketypes.h:1254
_ALTERNATIVE_ARCHITECTURE_TYPE
Definition: ketypes.h:901
@ EndAlternatives
Definition: ketypes.h:904
@ StandardDesign
Definition: ketypes.h:902
@ NEC98x86
Definition: ketypes.h:903
struct _KSYSTEM_TIME * PKSYSTEM_TIME
enum _ALTERNATIVE_ARCHITECTURE_TYPE ALTERNATIVE_ARCHITECTURE_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180