From: André Hentschel Subject: psapi/tests: Don't check for exact value (try 6) Message-Id: <55DCD211.1030207@dawncrow.de> Date: Tue, 25 Aug 2015 22:37:37 +0200 try 6: use int for margin, improved readability with indentation try 5: Use SIZE_T as type to avoid truncation and overflow; err->margin; finer adjustment of margins --- dlls/psapi/tests/psapi_main.c | 52 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/dlls/psapi/tests/psapi_main.c b/dlls/psapi/tests/psapi_main.c index cebfc5f..8760fe3 100644 --- a/dlls/psapi/tests/psapi_main.c +++ b/dlls/psapi/tests/psapi_main.c @@ -194,6 +194,12 @@ static void test_GetModuleInformation(void) ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod); } +static void check_with_margin(int line, SIZE_T perf, SIZE_T sysperf, int margin) +{ + ok_(__FILE__, line)(perf >= max(sysperf, margin) - margin && perf <= sysperf + margin, + "expected approximately %ld but got %ld\n", sysperf, perf); +} + static void test_GetPerformanceInfo(void) { PERFORMANCE_INFORMATION info; @@ -227,36 +233,17 @@ 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_with_margin(__LINE__, info.CommitTotal, sys_performance_info->TotalCommittedPages, 288); + check_with_margin(__LINE__, info.CommitLimit, sys_performance_info->TotalCommitLimit, 32); + check_with_margin(__LINE__, info.CommitPeak, sys_performance_info->PeakCommitment, 32); + check_with_margin(__LINE__, info.PhysicalAvailable, sys_performance_info->AvailablePages, 64); /* 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_with_margin(__LINE__, info.KernelTotal, sys_performance_info->PagedPoolUsage + + sys_performance_info->NonPagedPoolUsage, 64); + check_with_margin(__LINE__, info.KernelPaged, sys_performance_info->PagedPoolUsage, 64); + check_with_margin(__LINE__, info.KernelNonpaged, sys_performance_info->NonPagedPoolUsage, 8); /* compare with values from SYSTEM_BASIC_INFORMATION */ size = 0; @@ -297,14 +284,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_with_margin(__LINE__, info.HandleCount, handle_count, 8); + check_with_margin(__LINE__, info.ProcessCount, process_count, 4); + check_with_margin(__LINE__, info.ThreadCount, thread_count, 4); } } -- 1.9.1