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 #define NTDLL_GET_PROC(func) \
29 p ## func = (void*)GetProcAddress(hntdll, #func); \
31 trace("GetProcAddress(%s) failed\n", #func); \
32 FreeLibrary(hntdll); \
36 static BOOL
InitFunctionPtrs(void)
38 hntdll
= LoadLibraryA("ntdll.dll");
40 trace("Could not load ntdll.dll\n");
45 NTDLL_GET_PROC(NtQuerySystemInformation
)
46 NTDLL_GET_PROC(NtQueryInformationProcess
)
51 static void test_query_basic()
55 SYSTEM_BASIC_INFORMATION sbi
;
57 /* This test also covers some basic parameter testing that should be the same for
58 * every information class
61 /* Use a nonexistent info class */
62 trace("Check nonexistent info class\n");
63 status
= pNtQuerySystemInformation(-1, NULL
, 0, NULL
);
64 ok( status
== STATUS_INVALID_INFO_CLASS
, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status
);
66 /* Use an existing class but with a zero-length buffer */
67 trace("Check zero-length buffer\n");
68 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, 0, NULL
);
69 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
71 /* Use an existing class, correct length but no SystemInformation buffer */
72 trace("Check no SystemInformation buffer\n");
73 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, sizeof(sbi
), NULL
);
74 ok( status
== STATUS_ACCESS_VIOLATION
, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status
);
76 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
77 trace("Check no ReturnLength pointer\n");
78 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), NULL
);
79 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
81 /* Check a too large buffer size */
82 trace("Check a too large buffer size\n");
83 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
) * 2, &ReturnLength
);
84 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
86 /* Finally some correct calls */
87 trace("Check with correct parameters\n");
88 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
89 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
90 ok( sizeof(sbi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sbi
), ReturnLength
);
92 /* Check if we have some return values */
93 trace("Number of Processors : %d\n", sbi
.NumberOfProcessors
);
94 ok( sbi
.NumberOfProcessors
> 0, "Expected more than 0 processors, got %d\n", sbi
.NumberOfProcessors
);
97 static void test_query_cpu()
101 SYSTEM_CPU_INFORMATION sci
;
103 status
= pNtQuerySystemInformation(SystemCpuInformation
, &sci
, sizeof(sci
), &ReturnLength
);
104 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
105 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci
), ReturnLength
);
107 /* Check if we have some return values */
108 trace("Processor FeatureSet : %08lx\n", sci
.FeatureSet
);
109 ok( sci
.FeatureSet
!= 0, "Expected some features for this processor, got %08lx\n", sci
.FeatureSet
);
112 static void test_query_timeofday()
118 /* Copy of our winternl.h structure turned into a private one */
119 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
{
120 LARGE_INTEGER liKeBootTime
;
121 LARGE_INTEGER liKeSystemTime
;
122 LARGE_INTEGER liExpTimeZoneBias
;
123 ULONG uCurrentTimeZoneId
;
125 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
;
127 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti
;
129 /* The structsize for NT (32 bytes) and Win2K/XP (48 bytes) differ.
131 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
132 * then 48 and 0 otherwise
133 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
136 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
137 * NT only fills the buffer if the return code is STATUS_SUCCESS
141 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
142 isnt
= ( status
== STATUS_INFO_LENGTH_MISMATCH
);
146 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
148 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
149 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
150 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
152 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
153 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 28, &ReturnLength
);
154 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
156 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
157 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
158 ok( 32 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
163 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
164 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
165 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
167 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
168 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 24, &ReturnLength
);
169 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
170 ok( 24 == ReturnLength
, "ReturnLength should be 24, it is (%ld)\n", ReturnLength
);
171 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
173 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
174 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
175 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
176 ok( 32 == ReturnLength
, "ReturnLength should be 32, it is (%ld)\n", ReturnLength
);
177 ok( 0xdeadbeef != sti
.uCurrentTimeZoneId
, "Buffer should have been partially filled\n");
179 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 49, &ReturnLength
);
180 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
181 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%ld)\n", ReturnLength
);
183 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
184 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
185 ok( sizeof(sti
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sti
), ReturnLength
);
188 /* Check if we have some return values */
189 trace("uCurrentTimeZoneId : (%ld)\n", sti
.uCurrentTimeZoneId
);
192 static void test_query_process()
196 int i
= 0, j
= 0, k
= 0;
198 SYSTEM_BASIC_INFORMATION sbi
;
200 /* Copy of our winternl.h structure turned into a private one */
201 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE
{
205 FILETIME ftCreationTime
;
207 FILETIME ftKernelTime
;
208 UNICODE_STRING ProcessName
;
209 DWORD dwBasePriority
;
211 DWORD dwParentProcessID
;
215 VM_COUNTERS vmCounters
;
216 IO_COUNTERS ioCounters
;
217 SYSTEM_THREAD_INFORMATION ti
[1];
218 } SYSTEM_PROCESS_INFORMATION_PRIVATE
, *PSYSTEM_PROCESS_INFORMATION_PRIVATE
;
220 ULONG SystemInformationLength
= sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE
);
221 SYSTEM_PROCESS_INFORMATION_PRIVATE
* spi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
223 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
227 status
= pNtQuerySystemInformation(SystemProcessInformation
, spi
, SystemInformationLength
, &ReturnLength
);
229 if (status
!= STATUS_INFO_LENGTH_MISMATCH
) break;
231 spi
= HeapReAlloc(GetProcessHeap(), 0, spi
, SystemInformationLength
*= 2);
234 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
236 /* Get the first dwOffset, from this we can deduce the OS version we're running
239 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
241 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
242 * Wine (with every windows version):
243 * dwOffset for a process is 0 if just this test is running
244 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
245 * ProcessName.MaximumLength
246 * if more wine processes are running
248 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
251 pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
253 isnt
= ( spi
->dwOffset
- (sbi
.NumberOfProcessors
* sizeof(SYSTEM_THREAD_INFORMATION
)) == 136);
255 if (isnt
) trace("Windows version is NT, we will skip thread tests\n");
257 /* Check if we have some return values
259 * On windows there will be several processes running (Including the always present Idle and System)
260 * On wine we only have one (if this test is the only wine process running)
263 /* Loop through the processes */
269 ok( spi
->dwThreadCount
> 0, "Expected some threads for this process, got 0\"");
271 /* Loop through the threads, skip NT4 for now */
275 for ( j
= 0; j
< spi
->dwThreadCount
; j
++)
278 ok ( spi
->ti
[j
].dwOwningPID
== spi
->dwProcessID
,
279 "The owning pid of the thread (%ld) doesn't equal the pid (%ld) of the process\n",
280 spi
->ti
[j
].dwOwningPID
, spi
->dwProcessID
);
284 if (!spi
->dwOffset
) break;
286 spi
= (SYSTEM_PROCESS_INFORMATION_PRIVATE
*)((char*)spi
+ spi
->dwOffset
);
288 trace("Total number of running processes : %d\n", i
);
289 if (!isnt
) trace("Total number of running threads : %d\n", k
);
291 HeapFree( GetProcessHeap(), 0, spi
);
294 static void test_query_handle()
298 ULONG SystemInformationLength
= sizeof(SYSTEM_HANDLE_INFORMATION
);
299 SYSTEM_HANDLE_INFORMATION
* shi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
301 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
302 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
304 /* The following check assumes more than one handle on any given system */
307 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
309 ok( ReturnLength
> 0, "Expected ReturnLength to be > 0, it was %ld\n", ReturnLength
);
311 SystemInformationLength
= ReturnLength
;
312 shi
= HeapReAlloc(GetProcessHeap(), 0, shi
, SystemInformationLength
);
313 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
314 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
316 /* Check if we have some return values */
317 trace("Number of Handles : %ld\n", shi
->Count
);
320 /* our implementation is a stub for now */
321 ok( shi
->Count
> 1, "Expected more than 1 handles, got (%ld)\n", shi
->Count
);
324 HeapFree( GetProcessHeap(), 0, shi
);
327 static void test_query_process_basic()
332 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE
{
334 DWORD PebBaseAddress
;
337 ULONG UniqueProcessId
;
338 ULONG InheritedFromUniqueProcessId
;
339 } PROCESS_BASIC_INFORMATION_PRIVATE
, *PPROCESS_BASIC_INFORMATION_PRIVATE
;
341 PROCESS_BASIC_INFORMATION_PRIVATE pbi
;
343 /* This test also covers some basic parameter testing that should be the same for
344 * every information class
347 /* Use a nonexistent info class */
348 trace("Check nonexistent info class\n");
349 status
= pNtQueryInformationProcess(NULL
, -1, NULL
, 0, NULL
);
350 ok( status
== STATUS_INVALID_INFO_CLASS
, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status
);
352 /* Do not give a handle and buffer */
353 trace("Check NULL handle and buffer and zero-length buffersize\n");
354 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, 0, NULL
);
355 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
357 /* Use a correct info class and buffer size, but still no handle and buffer */
358 trace("Check NULL handle and buffer\n");
359 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, sizeof(pbi
), NULL
);
360 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
361 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status
);
363 /* Use a correct info class and buffer size, but still no handle */
364 trace("Check NULL handle\n");
365 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
366 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status
);
368 /* Use a greater buffer size */
369 trace("Check NULL handle and too large buffersize\n");
370 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, NULL
);
371 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status
);
373 /* Use no ReturnLength */
374 trace("Check NULL ReturnLength\n");
375 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
376 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
378 /* Finally some correct calls */
379 trace("Check with correct parameters\n");
380 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), &ReturnLength
);
381 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08lx\n", status
);
382 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi
), ReturnLength
);
384 /* Check if we have some return values */
385 trace("ProcessID : %ld\n", pbi
.UniqueProcessId
);
386 ok( pbi
.UniqueProcessId
> 0, "Expected a ProcessID > 0, got 0, got %ld\n", pbi
.UniqueProcessId
);
391 if(!InitFunctionPtrs())
394 /* NtQuerySystemInformation */
396 /* 0x0 SystemBasicInformation */
397 trace("Starting test_query_basic()\n");
400 /* 0x1 SystemCpuInformation */
401 trace("Starting test_query_cpu()\n");
404 /* 0x3 SystemCpuInformation */
405 trace("Starting test_query_timeofday()\n");
406 test_query_timeofday();
408 /* 0x5 SystemProcessInformation */
409 trace("Starting test_query_process()\n");
410 test_query_process();
412 /* 0x10 SystemHandleInformation */
413 trace("Starting test_query_handle()\n");
416 /* NtQueryInformationProcess */
418 trace("Starting test_query_process_basic()\n");
419 test_query_process_basic();