On 23.07.2015 22:50, André Hentschel wrote:
> ---
> dlls/psapi/tests/psapi_main.c | 59 +++++++++++++------------------------------
> 1 file changed, 17 insertions(+), 42 deletions(-)
>
> diff --git a/dlls/psapi/tests/psapi_main.c b/dlls/psapi/tests/psapi_main.c
> index cebfc5f..1ee30d2 100644
> --- a/dlls/psapi/tests/psapi_main.c
> +++ b/dlls/psapi/tests/psapi_main.c
> @@ -194,6 +194,11 @@ static void test_GetModuleInformation(void)
> ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod);
> }
>
> +#define ADMITTED_ERROR (64)
> +#define CHECK_MARGIN(perf, sys) \
> + ok(perf >= max(sys, ADMITTED_ERROR) - ADMITTED_ERROR && perf <= sys + ADMITTED_ERROR, \
> + "expected approximately " #perf "=%u but got %u\n", sys, (ULONG)perf)
> +
> static void test_GetPerformanceInfo(void)
> {
> PERFORMANCE_INFORMATION info;
> @@ -227,36 +232,16 @@ static void test_GetPerformanceInfo(void)
> ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
> ok(size >= sizeof(SYSTEM_PERFORMANCE_INFORMATION), "incorrect length %d\n", size);
>
> - ok(info.CommitTotal == sys_performance_info->TotalCommittedPages,
> - "expected info.CommitTotal=%u but got %u\n",
> - sys_performance_info->TotalCommittedPages, (ULONG)info.CommitTotal);
> -
> - ok(info.CommitLimit == sys_performance_info->TotalCommitLimit,
> - "expected info.CommitLimit=%u but got %u\n",
> - sys_performance_info->TotalCommitLimit, (ULONG)info.CommitLimit);
> -
> - ok(info.CommitPeak == sys_performance_info->PeakCommitment,
> - "expected info.CommitPeak=%u but got %u\n",
> - sys_performance_info->PeakCommitment, (ULONG)info.CommitPeak);
> -
> - ok(info.PhysicalAvailable >= max(sys_performance_info->AvailablePages, 25) - 25 &&
> - info.PhysicalAvailable <= sys_performance_info->AvailablePages + 25,
> - "expected approximately info.PhysicalAvailable=%u but got %u\n",
> - sys_performance_info->AvailablePages, (ULONG)info.PhysicalAvailable);
> + CHECK_MARGIN(info.CommitTotal, sys_performance_info->TotalCommittedPages);
> + CHECK_MARGIN(info.CommitLimit, sys_performance_info->TotalCommitLimit);
> + CHECK_MARGIN(info.CommitPeak, sys_performance_info->PeakCommitment);
> + CHECK_MARGIN(info.PhysicalAvailable, sys_performance_info->AvailablePages);
>
> /* TODO: info.SystemCache not checked yet - to which field(s) does this value correspond to? */
>
> - ok(info.KernelTotal == sys_performance_info->PagedPoolUsage + sys_performance_info->NonPagedPoolUsage,
> - "expected info.KernelTotal=%u but got %u\n",
> - sys_performance_info->PagedPoolUsage + sys_performance_info->NonPagedPoolUsage, (ULONG)info.KernelTotal);
> -
> - ok(info.KernelPaged == sys_performance_info->PagedPoolUsage,
> - "expected info.KernelPaged=%u but got %u\n",
> - sys_performance_info->PagedPoolUsage, (ULONG)info.KernelPaged);
> -
> - ok(info.KernelNonpaged == sys_performance_info->NonPagedPoolUsage,
> - "expected info.KernelNonpaged=%u but got %u\n",
> - sys_performance_info->NonPagedPoolUsage, (ULONG)info.KernelNonpaged);
> + CHECK_MARGIN(info.KernelTotal, sys_performance_info->PagedPoolUsage + sys_performance_info->NonPagedPoolUsage);
> + CHECK_MARGIN(info.KernelPaged, sys_performance_info->PagedPoolUsage);
> + CHECK_MARGIN(info.KernelNonpaged, sys_performance_info->NonPagedPoolUsage);
>
> /* compare with values from SYSTEM_BASIC_INFORMATION */
> size = 0;
> @@ -264,13 +249,8 @@ static void test_GetPerformanceInfo(void)
> ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
> ok(size >= sizeof(SYSTEM_BASIC_INFORMATION), "incorrect length %d\n", size);
>
> - ok(info.PhysicalTotal == sys_basic_info.MmNumberOfPhysicalPages,
> - "expected info.PhysicalTotal=%u but got %u\n",
> - sys_basic_info.MmNumberOfPhysicalPages, (ULONG)info.PhysicalTotal);
> -
> - ok(info.PageSize == sys_basic_info.PageSize,
> - "expected info.PageSize=%u but got %u\n",
> - sys_basic_info.PageSize, (ULONG)info.PageSize);
> + CHECK_MARGIN(info.PhysicalTotal, sys_basic_info.MmNumberOfPhysicalPages);
I think we can safely assume that the total physical memory does not change between two calls.
> + CHECK_MARGIN(info.PageSize, sys_basic_info.PageSize);
The pagesize should usually also match exactly.
>
> /* compare with values from SYSTEM_PROCESS_INFORMATION */
> size = 0;
> @@ -297,14 +277,9 @@ static void test_GetPerformanceInfo(void)
> }
> HeapFree(GetProcessHeap(), 0, sys_process_info);
>
> - ok(info.HandleCount == handle_count,
> - "expected info.HandleCount=%u but got %u\n", handle_count, info.HandleCount);
> -
> - ok(info.ProcessCount == process_count,
> - "expected info.ProcessCount=%u but got %u\n", process_count, info.ProcessCount);
> -
> - ok(info.ThreadCount == thread_count,
> - "expected info.ThreadCount=%u but got %u\n", thread_count, info.ThreadCount);
> + CHECK_MARGIN(info.HandleCount, handle_count);
> + CHECK_MARGIN(info.ProcessCount, process_count);
> + CHECK_MARGIN(info.ThreadCount, thread_count);
A tolerance of 64 (especially for process/threads) basically disables these tests. A smaller
tolerance would already be sufficient to avoid random test failures.
> }
> }
>
>