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 /* Finally some correct calls */
82 trace("Check with correct parameters\n");
83 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
84 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
85 ok( sizeof(sbi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sbi), ReturnLength);
87 /* Check if we have some return values */
88 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
89 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
92 static void test_query_cpu()
96 SYSTEM_CPU_INFORMATION sci;
98 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
99 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
100 ok( sizeof(sci) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci), ReturnLength);
102 /* Check if we have some return values */
103 trace("Processor FeatureSet : %08lx\n", sci.FeatureSet);
104 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08lx\n", sci.FeatureSet);
107 static void test_query_timeofday()
113 /* Copy of our winternl.h structure turned into a private one */
114 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
115 LARGE_INTEGER liKeBootTime;
116 LARGE_INTEGER liKeSystemTime;
117 LARGE_INTEGER liExpTimeZoneBias;
118 ULONG uCurrentTimeZoneId;
120 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
122 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
124 /* The structsize for NT (32 bytes) and Win2K/XP (48 bytes) differ.
126 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
127 * then 48 and 0 otherwise
128 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
131 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
132 * NT only fills the buffer if the return code is STATUS_SUCCESS
136 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
137 isnt = ( status == STATUS_INFO_LENGTH_MISMATCH);
141 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
143 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
144 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
145 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
147 sti.uCurrentTimeZoneId = 0xdeadbeef;
148 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
149 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
151 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
152 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
153 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
158 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
159 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
160 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
162 sti.uCurrentTimeZoneId = 0xdeadbeef;
163 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
164 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
165 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%ld)\n", ReturnLength);
166 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
168 sti.uCurrentTimeZoneId = 0xdeadbeef;
169 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
170 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
171 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%ld)\n", ReturnLength);
172 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
174 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
175 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
176 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
178 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
179 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
180 ok( sizeof(sti) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sti), ReturnLength);
183 /* Check if we have some return values */
184 trace("uCurrentTimeZoneId : (%ld)\n", sti.uCurrentTimeZoneId);
187 static void test_query_process()
191 int i = 0, j = 0, k = 0;
193 SYSTEM_BASIC_INFORMATION sbi;
195 /* Copy of our winternl.h structure turned into a private one */
196 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
200 FILETIME ftCreationTime;
202 FILETIME ftKernelTime;
203 UNICODE_STRING ProcessName;
204 DWORD dwBasePriority;
206 DWORD dwParentProcessID;
210 VM_COUNTERS vmCounters;
211 IO_COUNTERS ioCounters;
212 SYSTEM_THREAD_INFORMATION ti[1];
213 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
215 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
216 SYSTEM_PROCESS_INFORMATION_PRIVATE* spi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
218 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
222 status = pNtQuerySystemInformation(SystemProcessInformation, spi, SystemInformationLength, &ReturnLength);
224 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
226 spi = HeapReAlloc(GetProcessHeap(), 0, spi , SystemInformationLength *= 2);
229 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
231 /* Get the first dwOffset, from this we can deduce the OS version we're running
234 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
236 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
237 * Wine (with every windows version):
238 * dwOffset for a process is 0 if just this test is running
239 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
240 * ProcessName.MaximumLength
241 * if more wine processes are running
243 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
246 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
248 isnt = ( spi->dwOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
250 if (isnt) trace("Windows version is NT, we will skip thread tests\n");
252 /* Check if we have some return values
254 * On windows there will be several processes running (Including the always present Idle and System)
255 * On wine we only have one (if this test is the only wine process running)
258 /* Loop through the processes */
264 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\"");
266 /* Loop through the threads, skip NT4 for now */
270 for ( j = 0; j < spi->dwThreadCount; j++)
273 ok ( spi->ti[j].dwOwningPID == spi->dwProcessID,
274 "The owning pid of the thread (%ld) doesn't equal the pid (%ld) of the process\n",
275 spi->ti[j].dwOwningPID, spi->dwProcessID);
279 if (!spi->dwOffset) break;
281 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->dwOffset);
283 trace("Total number of running processes : %d\n", i);
284 if (!isnt) trace("Total number of running threads : %d\n", k);
286 HeapFree( GetProcessHeap(), 0, spi);
289 static void test_query_handle()
293 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
294 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
296 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
297 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
299 /* The following check assumes more than one handle on any given system */
302 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
304 ok( ReturnLength > 0, "Expected ReturnLength to be > 0, it was %ld\n", ReturnLength);
306 SystemInformationLength = ReturnLength;
307 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
308 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
309 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
311 /* Check if we have some return values */
312 trace("Number of Handles : %ld\n", shi->Count);
315 /* our implementation is a stub for now */
316 ok( shi->Count > 1, "Expected more than 1 handles, got (%ld)\n", shi->Count);
319 HeapFree( GetProcessHeap(), 0, shi);
322 static void test_query_process_basic()
327 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
329 DWORD PebBaseAddress;
332 ULONG UniqueProcessId;
333 ULONG InheritedFromUniqueProcessId;
334 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
336 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
338 /* This test also covers some basic parameter testing that should be the same for
339 * every information class
342 /* Use a nonexistent info class */
343 trace("Check nonexistent info class\n");
344 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
345 ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status);
347 /* Do not give a handle and buffer */
348 trace("Check NULL handle and buffer and zero-length buffersize\n");
349 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
350 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
352 /* Use a correct info class and buffer size, but still no handle and buffer */
353 trace("Check NULL handle and buffer\n");
354 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
355 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
357 /* Use a correct info class and buffer size, but still no handle */
358 trace("Check NULL handle\n");
359 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
360 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
362 /* Use a greater buffer size */
363 trace("Check NULL handle and too large buffersize\n");
364 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
365 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
367 /* Use no ReturnLength */
368 trace("Check NULL ReturnLength\n");
369 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
370 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
372 /* Finally some correct calls */
373 trace("Check with correct parameters\n");
374 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
375 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
376 ok( sizeof(pbi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi), ReturnLength);
378 /* Check if we have some return values */
379 trace("ProcessID : %ld\n", pbi.UniqueProcessId);
380 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0, got %ld\n", pbi.UniqueProcessId);
385 if(!InitFunctionPtrs())
388 /* NtQuerySystemInformation */
390 /* 0x0 SystemBasicInformation */
391 trace("Starting test_query_basic()\n");
394 /* 0x1 SystemCpuInformation */
395 trace("Starting test_query_cpu()\n");
398 /* 0x3 SystemCpuInformation */
399 trace("Starting test_query_timeofday()\n");
400 test_query_timeofday();
402 /* 0x5 SystemProcessInformation */
403 trace("Starting test_query_process()\n");
404 test_query_process();
406 /* 0x10 SystemHandleInformation */
407 trace("Starting test_query_handle()\n");
410 /* NtQueryInformationProcess */
412 trace("Starting test_query_process_basic()\n");
413 test_query_process_basic();