ReactOS  0.4.14-dev-115-g4576127
NtQueryInformationProcess.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Tests for the NtQueryInformationProcess API
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
11 
12 static
13 void
15 {
16 #define SPIN_TIME 1000000
18  KERNEL_USER_TIMES Times1;
19  KERNEL_USER_TIMES Times2;
20  ULONG Length;
21  LARGE_INTEGER Time1, Time2;
22 
23  /* Everything is NULL */
26  NULL,
27  0,
28  NULL);
30 
31  /* Right size, invalid process */
34  NULL,
35  sizeof(KERNEL_USER_TIMES),
36  NULL);
38 
39  /* Valid process, no buffer */
42  NULL,
43  0,
44  NULL);
46 
47  /* Unaligned buffer, wrong size */
50  (PVOID)2,
51  0,
52  NULL);
54 
55  /* Unaligned buffer, correct size */
58  (PVOID)2,
59  sizeof(KERNEL_USER_TIMES),
60  NULL);
62 
63  /* Buffer too small */
66  NULL,
67  sizeof(KERNEL_USER_TIMES) - 1,
68  NULL);
70 
71  /* Right buffer size but NULL pointer */
74  NULL,
75  sizeof(KERNEL_USER_TIMES),
76  NULL);
78 
79  /* Buffer too large */
82  NULL,
83  sizeof(KERNEL_USER_TIMES) + 1,
84  NULL);
86 
87  /* Buffer too small, ask for length */
88  Length = 0x55555555;
91  NULL,
92  sizeof(KERNEL_USER_TIMES) - 1,
93  &Length);
95  ok_dec(Length, 0x55555555);
96 
97  Status = NtQuerySystemTime(&Time1);
99 
100  /* Do some busy waiting to increase UserTime */
101  do
102  {
103  Status = NtQuerySystemTime(&Time2);
104  if (!NT_SUCCESS(Status))
105  {
106  ok(0, "NtQuerySystemTime failed with %lx\n", Status);
107  break;
108  }
109  } while (Time2.QuadPart - Time1.QuadPart < SPIN_TIME);
110 
111  /* Valid parameters, no return length */
112  Status = NtQuerySystemTime(&Time1);
114 
115  RtlFillMemory(&Times1, sizeof(Times1), 0x55);
117  ProcessTimes,
118  &Times1,
119  sizeof(KERNEL_USER_TIMES),
120  NULL);
123  "CreateTime is %I64u, expected < %I64u\n", Times1.CreateTime.QuadPart, TestStartTime.QuadPart);
124  ok(Times1.CreateTime.QuadPart > TestStartTime.QuadPart - 100000000LL,
125  "CreateTime is %I64u, expected > %I64u\n", Times1.CreateTime.QuadPart, TestStartTime.QuadPart - 100000000LL);
126  ok(Times1.ExitTime.QuadPart == 0,
127  "ExitTime is %I64u, expected 0\n", Times1.ExitTime.QuadPart);
128  ok(Times1.KernelTime.QuadPart != 0, "KernelTime is 0\n");
129  ok(Times1.UserTime.QuadPart != 0, "UserTime is 0\n");
130 
131  /* Do some busy waiting to increase UserTime */
132  do
133  {
134  Status = NtQuerySystemTime(&Time2);
135  if (!NT_SUCCESS(Status))
136  {
137  ok(0, "NtQuerySystemTime failed with %lx\n", Status);
138  break;
139  }
140  } while (Time2.QuadPart - Time1.QuadPart < SPIN_TIME);
141 
142  /* Again, this time with a return length */
143  Length = 0x55555555;
144  RtlFillMemory(&Times2, sizeof(Times2), 0x55);
146  ProcessTimes,
147  &Times2,
148  sizeof(KERNEL_USER_TIMES),
149  &Length);
151  ok_dec(Length, sizeof(KERNEL_USER_TIMES));
152  ok(Times1.CreateTime.QuadPart == Times2.CreateTime.QuadPart,
153  "CreateTimes not equal: %I64u != %I64u\n", Times1.CreateTime.QuadPart, Times2.CreateTime.QuadPart);
154  ok(Times2.ExitTime.QuadPart == 0,
155  "ExitTime is %I64u, expected 0\n", Times2.ExitTime.QuadPart);
156  ok(Times2.KernelTime.QuadPart != 0, "KernelTime is 0\n");
157  ok(Times2.UserTime.QuadPart != 0, "UserTime is 0\n");
158 
159  /* Compare the two sets of KernelTime/UserTime values */
160  Status = NtQuerySystemTime(&Time2);
162  /* Time values must have increased */
163  ok(Times2.KernelTime.QuadPart > Times1.KernelTime.QuadPart,
164  "KernelTime values inconsistent. Expected %I64u > %I64u\n", Times2.KernelTime.QuadPart, Times1.KernelTime.QuadPart);
165  ok(Times2.UserTime.QuadPart > Times1.UserTime.QuadPart,
166  "UserTime values inconsistent. Expected %I64u > %I64u\n", Times2.UserTime.QuadPart, Times1.UserTime.QuadPart);
167  /* They can't have increased by more than wall clock time difference (we only have one thread) */
168  ok(Times2.KernelTime.QuadPart - Times1.KernelTime.QuadPart < Time2.QuadPart - Time1.QuadPart,
169  "KernelTime values inconsistent. Expected %I64u - %I64u < %I64u\n",
170  Times2.KernelTime.QuadPart, Times1.KernelTime.QuadPart, Time2.QuadPart - Time1.QuadPart);
171  ok(Times2.UserTime.QuadPart - Times1.UserTime.QuadPart < Time2.QuadPart - Time1.QuadPart,
172  "UserTime values inconsistent. Expected %I64u - %I64u < %I64u\n",
173  Times2.UserTime.QuadPart, Times1.UserTime.QuadPart, Time2.QuadPart - Time1.QuadPart);
174 
175  trace("KernelTime1 = %I64u\n", Times1.KernelTime.QuadPart);
176  trace("KernelTime2 = %I64u\n", Times2.KernelTime.QuadPart);
177  trace("UserTime1 = %I64u\n", Times1.UserTime.QuadPart);
178  trace("UserTime2 = %I64u\n", Times2.UserTime.QuadPart);
179 
180  /* TODO: Test ExitTime on a terminated process */
181 #undef SPIN_TIME
182 }
183 
185 {
187 
190 
192 }
#define LL
Definition: tui.h:85
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
START_TEST(NtQueryInformationProcess)
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER UserTime
Definition: winternl.h:1063
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
#define ok_hex(expression, result)
Definition: atltest.h:94
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
static void Test_ProcessTimes(void)
#define trace
Definition: atltest.h:70
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: atltest.h:57
static LARGE_INTEGER TestStartTime
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:417
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define ok_dec(expression, result)
Definition: atltest.h:101
LARGE_INTEGER KernelTime
Definition: winternl.h:1062
#define SPIN_TIME
LONGLONG QuadPart
Definition: typedefs.h:112