[USP10_WINETEST] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / rostests / kmtests / ntos_mm / MmMapLockedPagesSpecifyCache_user.c
index d67e8e4..e935ccb 100644 (file)
 
 #include "MmMapLockedPagesSpecifyCache.h"
 
+#define SET_BUFFER_LENGTH(Var, Length)         \
+{                                              \
+    C_ASSERT(((Length) % sizeof(ULONG)) == 0); \
+    Var = (Length);                            \
+}
+
 START_TEST(MmMapLockedPagesSpecifyCache)
 {
     QUERY_BUFFER QueryBuffer;
     READ_BUFFER ReadBuffer;
     DWORD Length;
     USHORT i;
-    PUSHORT Buffer;
+    PULONG Buffer;
+    USHORT BufferLength;
 
     KmtLoadDriver(L"MmMapLockedPagesSpecifyCache", FALSE);
     KmtOpenDriver();
 
-    QueryBuffer.Length = 0x100;
+    // Less than a page
+    SET_BUFFER_LENGTH(BufferLength, 2048);
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = FALSE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok_eq_pointer(QueryBuffer.Buffer, NULL);
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = TRUE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
+    {
+        ReadBuffer.Pattern = WRITE_PATTERN;
+        ReadBuffer.Length = QueryBuffer.Length;
+        Buffer = QueryBuffer.Buffer;
+        for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
+        {
+            Buffer[i] = ReadBuffer.Pattern;
+        }
+    }
+
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    // 1 page
+    SET_BUFFER_LENGTH(BufferLength, 4096);
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = FALSE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok_eq_pointer(QueryBuffer.Buffer, NULL);
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = TRUE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
+    {
+        ReadBuffer.Pattern = WRITE_PATTERN;
+        ReadBuffer.Length = QueryBuffer.Length;
+        Buffer = QueryBuffer.Buffer;
+        for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
+        {
+            Buffer[i] = ReadBuffer.Pattern;
+        }
+    }
+
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    // more than 1 page
+    SET_BUFFER_LENGTH(BufferLength, 4096 + 2048);
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = FALSE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok_eq_pointer(QueryBuffer.Buffer, NULL);
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = TRUE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
+    {
+        ReadBuffer.Pattern = WRITE_PATTERN;
+        ReadBuffer.Length = QueryBuffer.Length;
+        Buffer = QueryBuffer.Buffer;
+        for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
+        {
+            Buffer[i] = ReadBuffer.Pattern;
+        }
+    }
+
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    // 2 pages
+    SET_BUFFER_LENGTH(BufferLength, 2 * 4096);
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = FALSE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok_eq_pointer(QueryBuffer.Buffer, NULL);
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    QueryBuffer.Length = BufferLength;
+    QueryBuffer.Buffer = NULL;
+    QueryBuffer.Cached = TRUE;
+    Length = sizeof(QUERY_BUFFER);
+    ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+    ok_eq_int(QueryBuffer.Length, BufferLength);
+    ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
+
+    ReadBuffer.Buffer = QueryBuffer.Buffer;
+    if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
+    {
+        ReadBuffer.Pattern = WRITE_PATTERN;
+        ReadBuffer.Length = QueryBuffer.Length;
+        Buffer = QueryBuffer.Buffer;
+        for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
+        {
+            Buffer[i] = ReadBuffer.Pattern;
+        }
+    }
+
+    Length = 0;
+    ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
+
+    // more than 2 pages
+    SET_BUFFER_LENGTH(BufferLength, 2 * 4096 + 2048);
+    QueryBuffer.Length = BufferLength;
     QueryBuffer.Buffer = NULL;
     QueryBuffer.Cached = FALSE;
     Length = sizeof(QUERY_BUFFER);
     ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
-    ok_eq_int(QueryBuffer.Length, 0x100);
+    ok_eq_int(QueryBuffer.Length, BufferLength);
     ok_eq_pointer(QueryBuffer.Buffer, NULL);
 
     ReadBuffer.Buffer = QueryBuffer.Buffer;
     Length = 0;
     ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
 
-    QueryBuffer.Length = 0x100;
+    QueryBuffer.Length = BufferLength;
     QueryBuffer.Buffer = NULL;
     QueryBuffer.Cached = TRUE;
     Length = sizeof(QUERY_BUFFER);
     ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
-    ok_eq_int(QueryBuffer.Length, 0x100);
+    ok_eq_int(QueryBuffer.Length, BufferLength);
     ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
 
     ReadBuffer.Buffer = QueryBuffer.Buffer;
     if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
     {
-        ReadBuffer.Pattern = 0xA7;
+        ReadBuffer.Pattern = WRITE_PATTERN;
         ReadBuffer.Length = QueryBuffer.Length;
         Buffer = QueryBuffer.Buffer;
-        for (i = 0; i < ReadBuffer.Length / sizeof(USHORT); ++i)
+        for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
         {
             Buffer[i] = ReadBuffer.Pattern;
         }