[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    [PATCH v4 1/2] ntdll/tests: Test user_shared_data timestamp updates.
From:       Rémi Bernon <rbernon () codeweavers ! com>
Date:       2020-04-30 16:58:58
Message-ID: 20200430165859.2369340-1-rbernon () codeweavers ! com
[Download RAW message or body]

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
---

v4:

* New way to test timestamps, still some little variations after the
  updates are implemented, as we may miss a server update.

* Add checks for InterruptTime, including some weird offset on testbot
  w864.

* Use a single page for the whole system, initialized when wineboot.exe
  completes its creation, using its USD initial values.

* Use atomic writes if possible, or assume that reordering guarantees
  on volatile accesses will be enough. PROT_WRITE doesn't always implies
  PROT_READ and atomic exchange would probably need readable page. We
  could also be mmap RW on the server side.

* Address a race condition when receiving the usd fd by including it in
  the server call uninterruptible section.

* Use the same 0x10000 size in ntdll initial mapping, later remapping
  and for the server side page creation.

 dlls/ntdll/tests/time.c | 78 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/dlls/ntdll/tests/time.c b/dlls/ntdll/tests/time.c
index 5382a952d8d8..fe71d4458c0f 100644
--- a/dlls/ntdll/tests/time.c
+++ b/dlls/ntdll/tests/time.c
@@ -18,7 +18,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#define NONAMELESSUNION
 #include "ntdll_test.h"
+#include "ddk/wdm.h"
 
 #define TICKSPERSEC        10000000
 #define TICKSPERMSEC       10000
@@ -29,6 +31,7 @@ static VOID (WINAPI *pRtlTimeFieldsToTime)(  PTIME_FIELDS \
TimeFields,  PLARGE_IN  static NTSTATUS (WINAPI *pNtQueryPerformanceCounter)( \
LARGE_INTEGER *counter, LARGE_INTEGER *frequency );  static NTSTATUS (WINAPI \
*pRtlQueryTimeZoneInformation)( RTL_TIME_ZONE_INFORMATION *);  static NTSTATUS \
(WINAPI *pRtlQueryDynamicTimeZoneInformation)( RTL_DYNAMIC_TIME_ZONE_INFORMATION *); \
+static BOOL     (WINAPI *pRtlQueryUnbiasedInterruptTime)( ULONGLONG *time );  
 static const int MonthLengths[2][12] =
 {
@@ -153,6 +156,79 @@ static void test_RtlQueryTimeZoneInformation(void)
        wine_dbgstr_w(tzinfo.DaylightName));
 }
 
+static ULONGLONG read_ksystem_time(volatile KSYSTEM_TIME *time)
+{
+    ULONGLONG high, low;
+    do
+    {
+        high = time->High1Time;
+        low = time->LowPart;
+    }
+    while (high != time->High2Time);
+    return high << 32 | low;
+}
+
+static void test_user_shared_data_time(void)
+{
+    KSHARED_USER_DATA *user_shared_data = (void *)0x7ffe0000;
+    ULONGLONG t1, t2, t3;
+    int i = 0;
+
+    i = 0;
+    do
+    {
+        t1 = GetTickCount();
+        if (user_shared_data->NtMajorVersion <= 5 && \
user_shared_data->NtMinorVersion <= 1) +            t2 = \
((ULONG64)user_shared_data->TickCountLowDeprecated * \
user_shared_data->TickCountMultiplier) >> 24; +        else
+            t2 = (read_ksystem_time(&user_shared_data->u.TickCount) * \
user_shared_data->TickCountMultiplier) >> 24; +        t3 = GetTickCount();
+    } while(t3 < t1 && i++ < 1); /* allow for wrap, but only once */
+
+    ok(t1 <= t2, "USD TickCount / GetTickCount are out of order: %s %s\n",
+       wine_dbgstr_longlong(t1), wine_dbgstr_longlong(t2));
+    todo_wine
+    ok(t2 <= t3, "USD TickCount / GetTickCount are out of order: %s %s\n",
+       wine_dbgstr_longlong(t2), wine_dbgstr_longlong(t3));
+
+    i = 0;
+    do
+    {
+        LARGE_INTEGER system_time;
+        NtQuerySystemTime(&system_time);
+        t1 = system_time.QuadPart;
+        t2 = read_ksystem_time(&user_shared_data->SystemTime);
+        NtQuerySystemTime(&system_time);
+        t3 = system_time.QuadPart;
+    } while(t3 < t1 && i++ < 1); /* allow for wrap, but only once */
+
+    todo_wine
+    ok(t1 <= t2, "USD SystemTime / NtQuerySystemTime are out of order %s %s\n",
+       wine_dbgstr_longlong(t1), wine_dbgstr_longlong(t2));
+    ok(t2 <= t3, "USD SystemTime / NtQuerySystemTime are out of order %s %s\n",
+       wine_dbgstr_longlong(t2), wine_dbgstr_longlong(t3));
+
+    if (!pRtlQueryUnbiasedInterruptTime)
+        win_skip("skipping RtlQueryUnbiasedInterruptTime tests\n");
+    else
+    {
+        i = 0;
+        do
+        {
+            pRtlQueryUnbiasedInterruptTime(&t1);
+            t2 = read_ksystem_time(&user_shared_data->InterruptTime);
+            pRtlQueryUnbiasedInterruptTime(&t3);
+        } while(t3 < t1 && i++ < 1); /* allow for wrap, but only once */
+
+        todo_wine
+        ok(t1 <= t2, "USD InterruptTime / RtlQueryUnbiasedInterruptTime are out of \
order %s %s\n", +           wine_dbgstr_longlong(t1), wine_dbgstr_longlong(t2));
+        ok(t2 <= t3 || broken(t2 == t3 + 82410089070) /* w864 has some weird offset \
on testbot */, +           "USD InterruptTime / RtlQueryUnbiasedInterruptTime are out \
of order %s %s\n", +           wine_dbgstr_longlong(t2), wine_dbgstr_longlong(t3));
+    }
+}
+
 START_TEST(time)
 {
     HMODULE mod = GetModuleHandleA("ntdll.dll");
@@ -163,6 +239,7 @@ START_TEST(time)
         (void *)GetProcAddress(mod, "RtlQueryTimeZoneInformation");
     pRtlQueryDynamicTimeZoneInformation =
         (void *)GetProcAddress(mod, "RtlQueryDynamicTimeZoneInformation");
+    pRtlQueryUnbiasedInterruptTime = (void *)GetProcAddress(mod, \
"RtlQueryUnbiasedInterruptTime");  
     if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
         test_pRtlTimeToTimeFields();
@@ -170,4 +247,5 @@ START_TEST(time)
         win_skip("Required time conversion functions are not available\n");
     test_NtQueryPerformanceCounter();
     test_RtlQueryTimeZoneInformation();
+    test_user_shared_data_time();
 }
-- 
2.26.1


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic