+static void test_query_logicalproc(void)
+{
+ NTSTATUS status;
+ ULONG len, i, proc_no;
+ SYSTEM_LOGICAL_PROCESSOR_INFORMATION *slpi;
+ SYSTEM_INFO si;
+
+ GetSystemInfo(&si);
+
+ status = pNtQuerySystemInformation(SystemLogicalProcessorInformation, NULL, 0, &len);
+ if(status == STATUS_INVALID_INFO_CLASS)
+ {
+ win_skip("SystemLogicalProcessorInformation is not supported\n");
+ return;
+ }
+ if(status == STATUS_NOT_IMPLEMENTED)
+ {
+ todo_wine ok(0, "SystemLogicalProcessorInformation is not implemented\n");
+ return;
+ }
+ ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
+ ok(len%sizeof(*slpi) == 0, "Incorrect length %d\n", len);
+
+ slpi = HeapAlloc(GetProcessHeap(), 0, len);
+ status = pNtQuerySystemInformation(SystemLogicalProcessorInformation, slpi, len, &len);
+ ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
+
+ proc_no = 0;
+ for(i=0; i<len/sizeof(*slpi); i++) {
+ switch(slpi[i].Relationship) {
+ case RelationProcessorCore:
+ /* Get number of logical processors */
+ for(; slpi[i].ProcessorMask; slpi[i].ProcessorMask /= 2)
+ proc_no += slpi[i].ProcessorMask%2;
+ break;
+ default:
+ break;
+ }
+ }
+ ok(proc_no > 0, "No processors were found\n");
+ if(si.dwNumberOfProcessors <= 32)
+ ok(proc_no == si.dwNumberOfProcessors, "Incorrect number of logical processors: %d, expected %d\n",
+ proc_no, si.dwNumberOfProcessors);
+
+ HeapFree(GetProcessHeap(), 0, slpi);
+}
+
+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_SUCCESS || status == STATUS_INVALID_PARAMETER, "Got %08x\n", status);
+
+ status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, 0);
+ ok( status == STATUS_BUFFER_TOO_SMALL || status == 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);
+}
+