[PATCH v3 1/3] kernelbase/tests: Fix the Sleep() test for non-default timer resolutions.
Francois Gouget
fgouget at codeweavers.com
Thu Jul 29 10:24:12 CDT 2021
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=51533
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
v2: The timer resolution change and test duration.
v3: No change.
This should fix the failures on cw-rx460 when the Radeon driver sets
the timer resolution to 2 ms.
---
dlls/kernelbase/tests/sync.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/dlls/kernelbase/tests/sync.c b/dlls/kernelbase/tests/sync.c
index 50ce62602b0..8127b4238b9 100644
--- a/dlls/kernelbase/tests/sync.c
+++ b/dlls/kernelbase/tests/sync.c
@@ -19,10 +19,14 @@
*/
#include <stdarg.h>
+#include <stdlib.h>
+
+#include <ntstatus.h>
+#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
-#include <stdlib.h>
#include <winerror.h>
+#include <winternl.h>
#include "wine/test.h"
@@ -176,7 +180,9 @@ static void test_Sleep(void)
{
LARGE_INTEGER frequency;
LARGE_INTEGER t1, t2;
- double elapsed_time;
+ double elapsed_time, min, max;
+ ULONG dummy, r1, r2;
+ NTSTATUS status;
BOOL ret;
int i;
@@ -186,15 +192,30 @@ static void test_Sleep(void)
ret = QueryPerformanceCounter(&t1);
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);
}
ret = QueryPerformanceCounter(&t2);
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;
- 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)
--
2.20.1
More information about the wine-devel
mailing list