1 /* Unit test suite for *Information* Registry API functions
3 * Copyright 2005 Paul Vriens
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "ntdll_test.h"
23 static NTSTATUS (WINAPI
* pNtQuerySystemInformation
)(SYSTEM_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
24 static NTSTATUS (WINAPI
* pNtQueryInformationProcess
)(HANDLE
, PROCESSINFOCLASS
, PVOID
, ULONG
, PULONG
);
26 static HMODULE hntdll
= 0;
28 /* one_before_last_pid is used to be able to compare values of a still running process
29 with the output of the test_query_process_times and test_query_process_handlecount tests.
31 static DWORD one_before_last_pid
= 0;
33 #define NTDLL_GET_PROC(func) \
34 p ## func = (void*)GetProcAddress(hntdll, #func); \
36 trace("GetProcAddress(%s) failed\n", #func); \
37 FreeLibrary(hntdll); \
41 static BOOL
InitFunctionPtrs(void)
43 hntdll
= LoadLibraryA("ntdll.dll");
45 trace("Could not load ntdll.dll\n");
50 NTDLL_GET_PROC(NtQuerySystemInformation
)
51 NTDLL_GET_PROC(NtQueryInformationProcess
)
56 static void test_query_basic(void)
60 SYSTEM_BASIC_INFORMATION sbi
;
62 /* This test also covers some basic parameter testing that should be the same for
63 * every information class
66 /* Use a nonexistent info class */
67 trace("Check nonexistent info class\n");
68 status
= pNtQuerySystemInformation(-1, NULL
, 0, NULL
);
69 ok( status
== STATUS_INVALID_INFO_CLASS
, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status
);
71 /* Use an existing class but with a zero-length buffer */
72 trace("Check zero-length buffer\n");
73 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, 0, NULL
);
74 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
76 /* Use an existing class, correct length but no SystemInformation buffer */
77 trace("Check no SystemInformation buffer\n");
78 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, sizeof(sbi
), NULL
);
79 ok( status
== STATUS_ACCESS_VIOLATION
, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status
);
81 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
82 trace("Check no ReturnLength pointer\n");
83 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), NULL
);
84 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
86 /* Check a too large buffer size */
87 trace("Check a too large buffer size\n");
88 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
) * 2, &ReturnLength
);
89 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
91 /* Finally some correct calls */
92 trace("Check with correct parameters\n");
93 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
94 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
95 ok( sizeof(sbi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sbi
), ReturnLength
);
97 /* Check if we have some return values */
98 trace("Number of Processors : %d\n", sbi
.NumberOfProcessors
);
99 ok( sbi
.NumberOfProcessors
> 0, "Expected more than 0 processors, got %d\n", sbi
.NumberOfProcessors
);
102 static void test_query_cpu(void)
106 SYSTEM_CPU_INFORMATION sci
;
108 status
= pNtQuerySystemInformation(SystemCpuInformation
, &sci
, sizeof(sci
), &ReturnLength
);
109 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
110 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci
), ReturnLength
);
112 /* Check if we have some return values */
113 trace("Processor FeatureSet : %08lx\n", sci
.FeatureSet
);
114 ok( sci
.FeatureSet
!= 0, "Expected some features for this processor, got %08lx\n", sci
.FeatureSet
);
117 static void test_query_performance(void)
121 SYSTEM_PERFORMANCE_INFORMATION spi
;
123 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, 0, &ReturnLength
);
124 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
126 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, sizeof(spi
), &ReturnLength
);
127 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
128 ok( sizeof(spi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spi
), ReturnLength
);
130 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, sizeof(spi
) + 2, &ReturnLength
);
131 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
132 ok( sizeof(spi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spi
), ReturnLength
);
134 /* Not return values yet, as struct members are unknown */
137 static void test_query_timeofday(void)
142 /* Copy of our winternl.h structure turned into a private one */
143 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
{
144 LARGE_INTEGER liKeBootTime
;
145 LARGE_INTEGER liKeSystemTime
;
146 LARGE_INTEGER liExpTimeZoneBias
;
147 ULONG uCurrentTimeZoneId
;
149 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
;
151 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti
;
153 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
155 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
156 * then 48 and 0 otherwise
157 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
160 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
161 * NT only fills the buffer if the return code is STATUS_SUCCESS
165 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
167 if (status
== STATUS_INFO_LENGTH_MISMATCH
)
169 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
171 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
172 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
173 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
175 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
176 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 28, &ReturnLength
);
177 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
179 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
180 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
181 ok( 32 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
185 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
186 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
187 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
189 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
190 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 24, &ReturnLength
);
191 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
192 ok( 24 == ReturnLength
, "ReturnLength should be 24, it is (%ld)\n", ReturnLength
);
193 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
195 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
196 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
197 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
198 ok( 32 == ReturnLength
, "ReturnLength should be 32, it is (%ld)\n", ReturnLength
);
199 ok( 0xdeadbeef != sti
.uCurrentTimeZoneId
, "Buffer should have been partially filled\n");
201 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 49, &ReturnLength
);
202 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
203 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
205 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
206 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
207 ok( sizeof(sti
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sti
), ReturnLength
);
210 /* Check if we have some return values */
211 trace("uCurrentTimeZoneId : (%ld)\n", sti
.uCurrentTimeZoneId
);
214 static void test_query_process(void)
221 SYSTEM_BASIC_INFORMATION sbi
;
223 /* Copy of our winternl.h structure turned into a private one */
224 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE
{
228 FILETIME ftCreationTime
;
230 FILETIME ftKernelTime
;
231 UNICODE_STRING ProcessName
;
232 DWORD dwBasePriority
;
234 DWORD dwParentProcessID
;
238 VM_COUNTERS vmCounters
;
239 IO_COUNTERS ioCounters
;
240 SYSTEM_THREAD_INFORMATION ti
[1];
241 } SYSTEM_PROCESS_INFORMATION_PRIVATE
, *PSYSTEM_PROCESS_INFORMATION_PRIVATE
;
243 ULONG SystemInformationLength
= sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE
);
244 SYSTEM_PROCESS_INFORMATION_PRIVATE
* spi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
246 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
250 status
= pNtQuerySystemInformation(SystemProcessInformation
, spi
, SystemInformationLength
, &ReturnLength
);
252 if (status
!= STATUS_INFO_LENGTH_MISMATCH
) break;
254 spi
= HeapReAlloc(GetProcessHeap(), 0, spi
, SystemInformationLength
*= 2);
257 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
259 /* Get the first dwOffset, from this we can deduce the OS version we're running
262 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
264 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
265 * Wine (with every windows version):
266 * dwOffset for a process is 0 if just this test is running
267 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
268 * ProcessName.MaximumLength
269 * if more wine processes are running
271 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
274 pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
276 is_nt
= ( spi
->dwOffset
- (sbi
.NumberOfProcessors
* sizeof(SYSTEM_THREAD_INFORMATION
)) == 136);
278 if (is_nt
) trace("Windows version is NT, we will skip thread tests\n");
280 /* Check if we have some return values
282 * On windows there will be several processes running (Including the always present Idle and System)
283 * On wine we only have one (if this test is the only wine process running)
286 /* Loop through the processes */
292 last_pid
= spi
->dwProcessID
;
294 ok( spi
->dwThreadCount
> 0, "Expected some threads for this process, got 0\n");
296 /* Loop through the threads, skip NT4 for now */
301 for ( j
= 0; j
< spi
->dwThreadCount
; j
++)
304 ok ( spi
->ti
[j
].dwOwningPID
== spi
->dwProcessID
,
305 "The owning pid of the thread (%ld) doesn't equal the pid (%ld) of the process\n",
306 spi
->ti
[j
].dwOwningPID
, spi
->dwProcessID
);
310 if (!spi
->dwOffset
) break;
312 one_before_last_pid
= last_pid
;
314 spi
= (SYSTEM_PROCESS_INFORMATION_PRIVATE
*)((char*)spi
+ spi
->dwOffset
);
316 trace("Total number of running processes : %d\n", i
);
317 if (!is_nt
) trace("Total number of running threads : %d\n", k
);
319 if (one_before_last_pid
== 0) one_before_last_pid
= last_pid
;
321 HeapFree( GetProcessHeap(), 0, spi
);
324 static void test_query_procperf(void)
329 SYSTEM_BASIC_INFORMATION sbi
;
330 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
* sppi
;
332 /* Find out the number of processors */
333 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
334 NeededLength
= sbi
.NumberOfProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
336 sppi
= HeapAlloc(GetProcessHeap(), 0, NeededLength
);
338 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, 0, &ReturnLength
);
339 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
341 /* Try it for 1 processor */
342 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
,
343 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
), &ReturnLength
);
344 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
345 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) == ReturnLength
,
346 "Inconsistent length (%d) <-> (%ld)\n", sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
), ReturnLength
);
348 /* Try it for all processors */
349 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, NeededLength
, &ReturnLength
);
350 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
351 ok( NeededLength
== ReturnLength
, "Inconsistent length (%ld) <-> (%ld)\n", NeededLength
, ReturnLength
);
353 /* A too large given buffer size */
354 sppi
= HeapReAlloc(GetProcessHeap(), 0, sppi
, NeededLength
+ 2);
355 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, NeededLength
+ 2, &ReturnLength
);
356 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
357 ok( NeededLength
== ReturnLength
, "Inconsistent length (%ld) <-> (%ld)\n", NeededLength
, ReturnLength
);
359 HeapFree( GetProcessHeap(), 0, sppi
);
362 static void test_query_module(void)
366 ULONG ModuleCount
, i
;
368 ULONG SystemInformationLength
= sizeof(SYSTEM_MODULE_INFORMATION
);
369 SYSTEM_MODULE_INFORMATION
* smi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
372 /* Request the needed length */
373 status
= pNtQuerySystemInformation(SystemModuleInformation
, smi
, 0, &ReturnLength
);
374 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
375 ok( ReturnLength
> 0, "Expected a ReturnLength to show the needed length\n");
377 SystemInformationLength
= ReturnLength
;
378 smi
= HeapReAlloc(GetProcessHeap(), 0, smi
, SystemInformationLength
);
379 status
= pNtQuerySystemInformation(SystemModuleInformation
, smi
, SystemInformationLength
, &ReturnLength
);
380 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
382 ModuleCount
= smi
->ModulesCount
;
383 sm
= &smi
->Modules
[0];
385 /* our implementation is a stub for now */
386 ok( ModuleCount
> 0, "Expected some modules to be loaded\n");
389 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
390 for (i
= 0; i
< ModuleCount
; i
++)
392 ok( i
== sm
->Id
, "Id (%d) should have matched %lu\n", sm
->Id
, i
);
396 HeapFree( GetProcessHeap(), 0, smi
);
399 static void test_query_handle(void)
403 ULONG SystemInformationLength
= sizeof(SYSTEM_HANDLE_INFORMATION
);
404 SYSTEM_HANDLE_INFORMATION
* shi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
406 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
407 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
409 /* The following check assumes more than one handle on any given system */
412 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
414 ok( ReturnLength
> 0, "Expected ReturnLength to be > 0, it was %ld\n", ReturnLength
);
416 SystemInformationLength
= ReturnLength
;
417 shi
= HeapReAlloc(GetProcessHeap(), 0, shi
, SystemInformationLength
);
418 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
419 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
421 /* Check if we have some return values */
422 trace("Number of Handles : %ld\n", shi
->Count
);
425 /* our implementation is a stub for now */
426 ok( shi
->Count
> 1, "Expected more than 1 handles, got (%ld)\n", shi
->Count
);
429 HeapFree( GetProcessHeap(), 0, shi
);
432 static void test_query_cache(void)
436 SYSTEM_CACHE_INFORMATION sci
;
438 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, 0, &ReturnLength
);
439 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
441 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, sizeof(sci
), &ReturnLength
);
442 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
443 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci
), ReturnLength
);
445 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, sizeof(sci
) + 2, &ReturnLength
);
446 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
447 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci
), ReturnLength
);
450 static void test_query_interrupt(void)
455 SYSTEM_BASIC_INFORMATION sbi
;
456 SYSTEM_INTERRUPT_INFORMATION
* sii
;
458 /* Find out the number of processors */
459 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
460 NeededLength
= sbi
.NumberOfProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
);
462 sii
= HeapAlloc(GetProcessHeap(), 0, NeededLength
);
464 status
= pNtQuerySystemInformation(SystemInterruptInformation
, sii
, 0, &ReturnLength
);
465 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
467 /* Try it for all processors */
468 status
= pNtQuerySystemInformation(SystemInterruptInformation
, sii
, NeededLength
, &ReturnLength
);
469 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
471 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
472 * No test added for this as it's highly unlikely that an app depends on this
475 HeapFree( GetProcessHeap(), 0, sii
);
478 static void test_query_kerndebug(void)
482 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
484 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, 0, &ReturnLength
);
485 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
487 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, sizeof(skdi
), &ReturnLength
);
488 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
489 ok( sizeof(skdi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(skdi
), ReturnLength
);
491 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, sizeof(skdi
) + 2, &ReturnLength
);
492 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
493 ok( sizeof(skdi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(skdi
), ReturnLength
);
496 static void test_query_regquota(void)
500 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
502 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, 0, &ReturnLength
);
503 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
505 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, sizeof(srqi
), &ReturnLength
);
506 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
507 ok( sizeof(srqi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(srqi
), ReturnLength
);
509 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, sizeof(srqi
) + 2, &ReturnLength
);
510 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
511 ok( sizeof(srqi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(srqi
), ReturnLength
);
514 static void test_query_process_basic(void)
519 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE
{
521 DWORD PebBaseAddress
;
524 ULONG UniqueProcessId
;
525 ULONG InheritedFromUniqueProcessId
;
526 } PROCESS_BASIC_INFORMATION_PRIVATE
, *PPROCESS_BASIC_INFORMATION_PRIVATE
;
528 PROCESS_BASIC_INFORMATION_PRIVATE pbi
;
530 /* This test also covers some basic parameter testing that should be the same for
531 * every information class
534 /* Use a nonexistent info class */
535 trace("Check nonexistent info class\n");
536 status
= pNtQueryInformationProcess(NULL
, -1, NULL
, 0, NULL
);
537 ok( status
== STATUS_INVALID_INFO_CLASS
, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status
);
539 /* Do not give a handle and buffer */
540 trace("Check NULL handle and buffer and zero-length buffersize\n");
541 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, 0, NULL
);
542 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
544 /* Use a correct info class and buffer size, but still no handle and buffer */
545 trace("Check NULL handle and buffer\n");
546 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, sizeof(pbi
), NULL
);
547 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
548 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
550 /* Use a correct info class and buffer size, but still no handle */
551 trace("Check NULL handle\n");
552 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
553 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
555 /* Use a greater buffer size */
556 trace("Check NULL handle and too large buffersize\n");
557 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, NULL
);
558 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
560 /* Use no ReturnLength */
561 trace("Check NULL ReturnLength\n");
562 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
563 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
565 /* Finally some correct calls */
566 trace("Check with correct parameters\n");
567 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), &ReturnLength
);
568 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
569 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi
), ReturnLength
);
571 /* Everything is correct except a too large buffersize */
572 trace("Too large buffersize\n");
573 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, &ReturnLength
);
574 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
575 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi
), ReturnLength
);
577 /* Check if we have some return values */
578 trace("ProcessID : %ld\n", pbi
.UniqueProcessId
);
579 ok( pbi
.UniqueProcessId
> 0, "Expected a ProcessID > 0, got 0\n");
582 static void test_query_process_vm(void)
588 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, NULL
, sizeof(pvi
), NULL
);
589 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
590 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
592 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, &pvi
, sizeof(pvi
), NULL
);
593 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
595 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
596 Windows W2K will only report success for 44.
597 For now we only care for 44, which is sizeof(VM_COUNTERS)
598 If an app depends on it, we have to implement this in ntdll/process.c
601 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 24, &ReturnLength
);
602 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
604 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, sizeof(pvi
), &ReturnLength
);
605 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
606 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pvi
), ReturnLength
);
608 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 46, &ReturnLength
);
609 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
610 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pvi
), ReturnLength
);
612 /* Check if we have some return values */
613 trace("WorkingSetSize : %ld\n", pvi
.WorkingSetSize
);
616 ok( pvi
.WorkingSetSize
> 0, "Expected a WorkingSetSize > 0\n");
620 static void test_query_process_io(void)
626 /* NT4 doesn't support this information class, so check for it */
627 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
628 if (status
== STATUS_NOT_SUPPORTED
)
630 trace("ProcessIoCounters information class not supported, skipping tests\n");
634 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, NULL
, sizeof(pii
), NULL
);
635 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
636 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
638 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, &pii
, sizeof(pii
), NULL
);
639 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
641 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, 24, &ReturnLength
);
642 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
644 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
645 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
646 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pii
), ReturnLength
);
648 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
) * 2, &ReturnLength
);
649 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
650 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pii
), ReturnLength
);
652 /* Check if we have some return values */
653 trace("OtherOperationCount : %lld\n", pii
.OtherOperationCount
);
656 ok( pii
.OtherOperationCount
> 0, "Expected an OtherOperationCount > 0\n");
660 static void test_query_process_times(void)
665 SYSTEMTIME UTC
, Local
;
666 KERNEL_USER_TIMES spti
;
668 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, NULL
, sizeof(spti
), NULL
);
669 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
670 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
672 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, &spti
, sizeof(spti
), NULL
);
673 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
675 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, 24, &ReturnLength
);
676 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
678 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
681 trace("Could not open process with ID : %ld, error : %08lx. Going to use current one.\n", one_before_last_pid
, GetLastError());
682 process
= GetCurrentProcess();
683 trace("ProcessTimes for current process\n");
686 trace("ProcessTimes for process with ID : %ld\n", one_before_last_pid
);
688 status
= pNtQueryInformationProcess( process
, ProcessTimes
, &spti
, sizeof(spti
), &ReturnLength
);
689 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
690 ok( sizeof(spti
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spti
), ReturnLength
);
691 CloseHandle(process
);
693 FileTimeToSystemTime((const FILETIME
*)&spti
.CreateTime
, &UTC
);
694 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
695 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
696 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
698 FileTimeToSystemTime((const FILETIME
*)&spti
.ExitTime
, &UTC
);
699 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
700 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
701 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
703 FileTimeToSystemTime((const FILETIME
*)&spti
.KernelTime
, &Local
);
704 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
706 FileTimeToSystemTime((const FILETIME
*)&spti
.UserTime
, &Local
);
707 trace("UserTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
709 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, sizeof(spti
) * 2, &ReturnLength
);
710 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
711 ok( sizeof(spti
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spti
), ReturnLength
);
714 static void test_query_process_handlecount(void)
721 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, NULL
, sizeof(handlecount
), NULL
);
722 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
723 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
725 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), NULL
);
726 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
728 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, 2, &ReturnLength
);
729 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
731 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
732 trace("Handlecount for process with ID : %ld\n", one_before_last_pid
);
733 status
= pNtQueryInformationProcess( process
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), &ReturnLength
);
734 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
735 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(handlecount
), ReturnLength
);
736 CloseHandle(process
);
738 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, sizeof(handlecount
) * 2, &ReturnLength
);
739 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
740 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(handlecount
), ReturnLength
);
742 /* Check if we have some return values */
743 trace("HandleCount : %ld\n", handlecount
);
746 ok( handlecount
> 0, "Expected some handles, got 0\n");
752 if(!InitFunctionPtrs())
755 /* NtQuerySystemInformation */
757 /* 0x0 SystemBasicInformation */
758 trace("Starting test_query_basic()\n");
761 /* 0x1 SystemCpuInformation */
762 trace("Starting test_query_cpu()\n");
765 /* 0x2 SystemPerformanceInformation */
766 trace("Starting test_query_performance()\n");
767 test_query_performance();
769 /* 0x3 SystemTimeOfDayInformation */
770 trace("Starting test_query_timeofday()\n");
771 test_query_timeofday();
773 /* 0x5 SystemProcessInformation */
774 trace("Starting test_query_process()\n");
775 test_query_process();
777 /* 0x8 SystemProcessorPerformanceInformation */
778 trace("Starting test_query_procperf()\n");
779 test_query_procperf();
781 /* 0xb SystemModuleInformation */
782 trace("Starting test_query_module()\n");
785 /* 0x10 SystemHandleInformation */
786 trace("Starting test_query_handle()\n");
789 /* 0x15 SystemCacheInformation */
790 trace("Starting test_query_cache()\n");
793 /* 0x17 SystemInterruptInformation */
794 trace("Starting test_query_interrupt()\n");
795 test_query_interrupt();
797 /* 0x23 SystemKernelDebuggerInformation */
798 trace("Starting test_query_kerndebug()\n");
799 test_query_kerndebug();
801 /* 0x25 SystemRegistryQuotaInformation */
802 trace("Starting test_query_regquota()\n");
803 test_query_regquota();
805 /* NtQueryInformationProcess */
807 /* 0x0 ProcessBasicInformation */
808 trace("Starting test_query_process_basic()\n");
809 test_query_process_basic();
811 /* 0x2 ProcessIoCounters */
812 trace("Starting test_query_process_io()\n");
813 test_query_process_io();
815 /* 0x3 ProcessVmCounters */
816 trace("Starting test_query_process_vm()\n");
817 test_query_process_vm();
819 /* 0x4 ProcessTimes */
820 trace("Starting test_query_process_times()\n");
821 test_query_process_times();
823 /* 0x14 ProcessHandleCount */
824 trace("Starting test_query_process_handlecount()\n");
825 test_query_process_handlecount();