ReactOS  0.4.14-dev-583-g2a1ba2c
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 
29 typedef struct _KSYSTEM_TIME {
30  ULONG LowPart;
34 
35 typedef enum _NT_PRODUCT_TYPE {
36  NtProductWinNt = 1,
40 
41 #define PROCESSOR_FEATURE_MAX 64
42 
44 {
46  NEC98x86,
49 
50 #define MAX_WOW64_SHARED_ENTRIES 16
51 
52 typedef struct _KUSER_SHARED_DATA {
55  volatile KSYSTEM_TIME InterruptTime;
56  volatile KSYSTEM_TIME SystemTime;
57  volatile KSYSTEM_TIME TimeZoneBias;
60  WCHAR NtSystemRoot[260];
65  ULONG Reserved2[7];
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;
94  ULONG Cookie;
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 
104 static VOID (WINAPI *pRtlTimeToTimeFields)( const LARGE_INTEGER *liTime, PTIME_FIELDS TimeFields) ;
105 static VOID (WINAPI *pRtlTimeFieldsToTime)( PTIME_FIELDS TimeFields, PLARGE_INTEGER Time) ;
106 static NTSTATUS (WINAPI *pNtQueryPerformanceCounter)( LARGE_INTEGER *counter, LARGE_INTEGER *frequency );
107 static NTSTATUS (WINAPI *pRtlQueryTimeZoneInformation)( RTL_TIME_ZONE_INFORMATION *);
108 static NTSTATUS (WINAPI *pRtlQueryDynamicTimeZoneInformation)( RTL_DYNAMIC_TIME_ZONE_INFORMATION *);
109 static ULONG (WINAPI *pNtGetTickCount)(void);
110 
111 static 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 
117 static 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 */
123 static TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0};
124 
125 static void test_pRtlTimeToTimeFields(void)
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",
217  wine_dbgstr_w(tzinfo.StandardName));
218  todo_wine ok(tzinfo.DaylightName[0] == '@',
219  "daylight time zone name isn't an indirect string, got %s\n",
220  wine_dbgstr_w(tzinfo.DaylightName));
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",
228  wine_dbgstr_w(tzinfo.StandardName));
229  todo_wine ok(tzinfo.DaylightName[0] == '@',
230  "daylight time zone name isn't an indirect string, got %s\n",
231  wine_dbgstr_w(tzinfo.DaylightName));
232 }
233 
234 static 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 }
ULONG LargePageMinimum
Definition: ketypes.h:1155
ULONG LowPart
Definition: ketypes.h:910
ULONG NtMinorVersion
Definition: ketypes.h:1160
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
ULONG Reserved2[7]
Definition: ketypes.h:1156
_ALTERNATIVE_ARCHITECTURE_TYPE
Definition: ketypes.h:883
static void test_NtGetTickCount(void)
Definition: time.c:234
LARGE_INTEGER SystemExpirationDate
Definition: ketypes.h:1167
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
_ANONYMOUS_UNION union _KUSER_SHARED_DATA::@3759 DUMMYUNIONNAME
LONG NTSTATUS
Definition: precomp.h:26
ULONGLONG TestRetInstruction
Definition: ketypes.h:1208
ULONG MaxStackTraceDepth
Definition: ketypes.h:1152
ULONG CryptoExponent
Definition: ketypes.h:1153
volatile ULONG TimeSlip
Definition: ketypes.h:1164
__u16 time
Definition: mkdosfs.c:366
volatile KSYSTEM_TIME InterruptTime
Definition: ketypes.h:1146
ULONG SystemCallReturn
Definition: ketypes.h:1210
START_TEST(time)
Definition: time.c:43
BOOLEAN SafeBootMode
Definition: ketypes.h:1178
enum _NT_PRODUCT_TYPE * PNT_PRODUCT_TYPE
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
ULONG NtMajorVersion
Definition: ketypes.h:1159
volatile KSYSTEM_TIME SystemTime
Definition: ketypes.h:1147
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
NT_PRODUCT_TYPE NtProductType
Definition: ketypes.h:1157
BOOLEAN KdDebuggerEnabled
Definition: ketypes.h:1169
ULONG TickCountMultiplier
Definition: ketypes.h:1145
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
ULONG TickCountLowDeprecated
Definition: ketypes.h:1144
static VOID(WINAPI *pRtlTimeToTimeFields)(const LARGE_INTEGER *liTime
USHORT ImageNumberHigh
Definition: ketypes.h:1150
GLuint counter
Definition: glext.h:11116
struct _KSYSTEM_TIME KSYSTEM_TIME
#define MAX_WOW64_SHARED_ENTRIES
Definition: ketypes.h:1141
struct _KSYSTEM_TIME * PKSYSTEM_TIME
static void test_NtQueryPerformanceCounter(void)
Definition: time.c:178
USHORT ImageNumberLow
Definition: ketypes.h:1149
#define TICKSPERSEC
Definition: time.c:100
volatile KSYSTEM_TIME TickCount
Definition: ketypes.h:1213
int64_t LONGLONG
Definition: typedefs.h:66
LONG High1Time
Definition: ketypes.h:911
#define PROCESSOR_FEATURE_MAX
__wchar_t WCHAR
Definition: xmlstorage.h:180
ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture
Definition: ketypes.h:1165
static NTSTATUS(WINAPI *pNtQueryPerformanceCounter)(LARGE_INTEGER *counter
uint64_t ULONGLONG
Definition: typedefs.h:65
#define WINAPI
Definition: msvc.h:6
ULONG NumberOfPhysicalPages
Definition: ketypes.h:1177
static const int MonthLengths[2][12]
Definition: time.c:111
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned char UCHAR
Definition: xmlstorage.h:181
#define todo_wine
Definition: test.h:163
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define SECSPERDAY
Definition: time.c:102
volatile ULONG ActiveConsoleId
Definition: ketypes.h:1173
volatile KSYSTEM_TIME TimeZoneBias
Definition: ketypes.h:1148
static BOOL IsLeapYear(int Year)
Definition: time.c:117
static LARGE_INTEGER * frequency
Definition: time.c:106
static TIME_FIELDS tftest
Definition: time.c:123
LONG High2Time
Definition: ketypes.h:912
static void test_pRtlTimeToTimeFields(void)
Definition: time.c:125
WCHAR NtSystemRoot[260]
Definition: ketypes.h:1151
_NT_PRODUCT_TYPE
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned short USHORT
Definition: pedump.c:61
volatile ULONG64 TickCountQuad
Definition: ketypes.h:1214
static ULONG(WINAPI *pNtGetTickCount)(void)
#define ok(value,...)
Definition: atltest.h:57
static void(WINAPI *pGetSystemTimePreciseAsFileTime)(LPFILETIME)
enum _ALTERNATIVE_ARCHITECTURE_TYPE ALTERNATIVE_ARCHITECTURE_TYPE
ULONGLONG SystemCallPad[3]
Definition: ketypes.h:1211
UCHAR NXSupportPolicy
Definition: ketypes.h:1171
ULONG LastSystemRITEventTickCount
Definition: ketypes.h:1176
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
static void test_RtlQueryTimeZoneInformation(void)
Definition: time.c:198
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:418
static PTIME_FIELDS TimeFields
Definition: time.c:104
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
static SERVICE_STATUS status
Definition: service.c:31
#define win_skip
Definition: test.h:150
static PLARGE_INTEGER Time
Definition: time.c:105
ULONG ComPlusPackage
Definition: ketypes.h:1175
BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX]
Definition: ketypes.h:1161
LONGLONG QuadPart
Definition: typedefs.h:112
volatile ULONG DismountCount
Definition: ketypes.h:1174
static int mod
Definition: i386-dis.c:1273
BOOLEAN ProductTypeIsValid
Definition: ketypes.h:1158
ULONG Wow64SharedInformation[MAX_WOW64_SHARED_ENTRIES]
Definition: ketypes.h:1224
Definition: ps.c:97