Commit e9e8561f authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

kernelbase/tests: Fix the Sleep() test for non-default timer resolutions.

Also defend against timer resolution changes during the test. Reduce the test duration a bit. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51533Signed-off-by: 's avatarFrancois Gouget <fgouget@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 8fed1c68
...@@ -19,10 +19,14 @@ ...@@ -19,10 +19,14 @@
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h>
#include <ntstatus.h>
#define WIN32_NO_STATUS
#include <windef.h> #include <windef.h>
#include <winbase.h> #include <winbase.h>
#include <stdlib.h>
#include <winerror.h> #include <winerror.h>
#include <winternl.h>
#include "wine/test.h" #include "wine/test.h"
...@@ -176,7 +180,9 @@ static void test_Sleep(void) ...@@ -176,7 +180,9 @@ static void test_Sleep(void)
{ {
LARGE_INTEGER frequency; LARGE_INTEGER frequency;
LARGE_INTEGER t1, t2; LARGE_INTEGER t1, t2;
double elapsed_time; double elapsed_time, min, max;
ULONG dummy, r1, r2;
NTSTATUS status;
BOOL ret; BOOL ret;
int i; int i;
...@@ -186,15 +192,30 @@ static void test_Sleep(void) ...@@ -186,15 +192,30 @@ static void test_Sleep(void)
ret = QueryPerformanceCounter(&t1); ret = QueryPerformanceCounter(&t1);
ok(ret, "QueryPerformanceCounter failed\n"); ok(ret, "QueryPerformanceCounter failed\n");
for (i = 0; i < 100; i++) { /* Get the timer resolution before... */
r1 = 156250;
status = NtQueryTimerResolution(&dummy, &dummy, &r1);
todo_wine ok(status == STATUS_SUCCESS, "NtQueryTimerResolution() failed (%x)\n", status);
for (i = 0; i < 50; i++) {
Sleep(1); Sleep(1);
} }
ret = QueryPerformanceCounter(&t2); ret = QueryPerformanceCounter(&t2);
ok(ret, "QueryPerformanceCounter failed\n"); ok(ret, "QueryPerformanceCounter failed\n");
/* ...and after in case some other process changes it during this test */
r2 = 156250;
status = NtQueryTimerResolution(&dummy, &dummy, &r2);
todo_wine ok(status == STATUS_SUCCESS, "NtQueryTimerResolution() failed (%x)\n", status);
elapsed_time = (t2.QuadPart - t1.QuadPart) / (double)frequency.QuadPart; elapsed_time = (t2.QuadPart - t1.QuadPart) / (double)frequency.QuadPart;
todo_wine ok(elapsed_time >= 1.5 && elapsed_time <= 4.0, "got %f\n", elapsed_time); min = 50.0 * (r1 < r2 ? r1 : r2) / 10000000.0;
max = 50.0 * (r1 < r2 ? r2 : r1) / 10000000.0;
/* Add an extra 1s to account for potential scheduling delays */
todo_wine ok(0.9 * min <= elapsed_time && elapsed_time <= 1.0 + max,
"got %f, expected between %f and %f\n", elapsed_time, min, max);
} }
START_TEST(sync) START_TEST(sync)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment