ntdll/tests: Add test for ProcessorInformation case of NtPowerInformation.

This commit is contained in:
James Eder 2012-09-12 13:16:31 -06:00 committed by Alexandre Julliard
parent 7f9dfe273a
commit fbd5a9aaff
1 changed files with 81 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include <stdio.h>
static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
static NTSTATUS (WINAPI * pNtPowerInformation)(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG);
static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
static NTSTATUS (WINAPI * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
static NTSTATUS (WINAPI * pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
@ -62,6 +63,7 @@ static BOOL InitFunctionPtrs(void)
}
NTDLL_GET_PROC(NtQuerySystemInformation);
NTDLL_GET_PROC(NtPowerInformation);
NTDLL_GET_PROC(NtQueryInformationProcess);
NTDLL_GET_PROC(NtQueryInformationThread);
NTDLL_GET_PROC(NtSetInformationProcess);
@ -621,6 +623,79 @@ static void test_query_logicalproc(void)
proc_no, si.dwNumberOfProcessors);
}
static void test_query_processor_power_info(void)
{
NTSTATUS status;
PROCESSOR_POWER_INFORMATION* ppi;
ULONG size;
SYSTEM_INFO si;
int i;
GetSystemInfo(&si);
size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
ppi = HeapAlloc(GetProcessHeap(), 0, size);
/* If size < (sizeof(PROCESSOR_POWER_INFORMATION) * NumberOfProcessors), Win7 returns
* STATUS_BUFFER_TOO_SMALL. WinXP returns STATUS_SUCCESS for any value of size. It copies as
* many whole PROCESSOR_POWER_INFORMATION structures that there is room for. Even if there is
* not enough room for one structure, WinXP still returns STATUS_SUCCESS having done nothing.
*
* If ppi == NULL, Win7 returns STATUS_INVALID_PARAMETER while WinXP returns STATUS_SUCCESS
* and does nothing.
*
* The same behavior is seen with CallNtPowerInformation (in powrprof.dll).
*/
if (si.dwNumberOfProcessors > 1)
{
for(i = 0; i < si.dwNumberOfProcessors; i++)
ppi[i].Number = 0xDEADBEEF;
/* Call with a buffer size that is large enough to hold at least one but not large
* enough to hold them all. This will be STATUS_SUCCESS on WinXP but not on Win7 */
status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, size - sizeof(PROCESSOR_POWER_INFORMATION));
if (status == STATUS_SUCCESS)
{
/* lax version found on older Windows like WinXP */
ok( (ppi[si.dwNumberOfProcessors - 2].Number != 0xDEADBEEF) &&
(ppi[si.dwNumberOfProcessors - 1].Number == 0xDEADBEEF),
"Expected all but the last record to be overwritten.\n");
status = pNtPowerInformation(ProcessorInformation, 0, 0, 0, size);
ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
for(i = 0; i < si.dwNumberOfProcessors; i++)
ppi[i].Number = 0xDEADBEEF;
status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, sizeof(PROCESSOR_POWER_INFORMATION) - 1);
ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
for(i = 0; i < si.dwNumberOfProcessors; i++)
if (ppi[i].Number != 0xDEADBEEF) break;
ok( i == si.dwNumberOfProcessors, "Expected untouched buffer\n");
}
else
{
/* picky version found on newer Windows like Win7 */
ok( ppi[1].Number == 0xDEADBEEF, "Expected untouched buffer.\n");
ok( status == STATUS_BUFFER_TOO_SMALL, "Expected STATUS_BUFFER_TOO_SMALL, got %08x\n", status);
status = pNtPowerInformation(ProcessorInformation, 0, 0, 0, size);
ok( status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, 0);
ok( status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
}
}
else
{
skip("Test needs more than one processor.\n");
}
status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, size);
ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
HeapFree(GetProcessHeap(), 0, ppi);
}
static void test_query_process_basic(void)
{
NTSTATUS status;
@ -1496,7 +1571,6 @@ static void test_NtGetCurrentProcessorNumber(void)
ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
}
START_TEST(info)
{
char **argv;
@ -1562,6 +1636,12 @@ START_TEST(info)
trace("Starting test_query_logicalproc()\n");
test_query_logicalproc();
/* NtPowerInformation */
/* 0xb ProcessorInformation */
trace("Starting test_query_processor_power_info()\n");
test_query_processor_power_info();
/* NtQueryInformationProcess */
/* 0x0 ProcessBasicInformation */