[KMTESTS:MM]
authorThomas Faber <thomas.faber@reactos.org>
Fri, 26 Jun 2015 07:31:01 +0000 (07:31 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Fri, 26 Jun 2015 07:31:01 +0000 (07:31 +0000)
- Add a test for MmAllocatePagesForMdl

svn path=/trunk/; revision=68271

rostests/kmtests/CMakeLists.txt
rostests/kmtests/kmtest_drv/testlist.c
rostests/kmtests/ntos_mm/MmMdl.c [new file with mode: 0644]

index 7053d90..02c6b23 100644 (file)
@@ -64,6 +64,7 @@ list(APPEND KMTEST_DRV_SOURCE
     ntos_ke/KeProcessor.c
     ntos_ke/KeSpinLock.c
     ntos_ke/KeTimer.c
+    ntos_mm/MmMdl.c
     ntos_mm/MmSection.c
     ntos_mm/ZwAllocateVirtualMemory.c
     ntos_mm/ZwCreateSection.c
index aac1ced..23fc3fb 100644 (file)
@@ -39,6 +39,7 @@ KMT_TESTFUNC Test_KeProcessor;
 KMT_TESTFUNC Test_KeSpinLock;
 KMT_TESTFUNC Test_KeTimer;
 KMT_TESTFUNC Test_KernelType;
+KMT_TESTFUNC Test_MmMdl;
 KMT_TESTFUNC Test_MmSection;
 KMT_TESTFUNC Test_NpfsConnect;
 KMT_TESTFUNC Test_NpfsCreate;
@@ -98,6 +99,7 @@ const KMT_TEST TestList[] =
     { "KeSpinLock",                         Test_KeSpinLock },
     { "KeTimer",                            Test_KeTimer },
     { "-KernelType",                        Test_KernelType },
+    { "MmMdl",                              Test_MmMdl },
     { "MmSection",                          Test_MmSection },
     { "NpfsConnect",                        Test_NpfsConnect },
     { "NpfsCreate",                         Test_NpfsCreate },
diff --git a/rostests/kmtests/ntos_mm/MmMdl.c b/rostests/kmtests/ntos_mm/MmMdl.c
new file mode 100644 (file)
index 0000000..85dd3fc
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * PROJECT:         ReactOS kernel-mode tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Kernel-Mode Test Suite MDL test
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ */
+
+#include <kmt_test.h>
+
+static
+VOID
+TestMmAllocatePagesForMdl(VOID)
+{
+    PMDL Mdl;
+    PHYSICAL_ADDRESS LowAddress;
+    PHYSICAL_ADDRESS HighAddress;
+    PHYSICAL_ADDRESS SkipBytes;
+    PVOID SystemVa;
+    PMDL Mdls[32];
+    PVOID SystemVas[32];
+    ULONG i;
+
+    LowAddress.QuadPart = 0;
+    HighAddress.QuadPart = -1;
+    SkipBytes.QuadPart = 0;
+    /* simple allocate/free */
+    Mdl = MmAllocatePagesForMdl(LowAddress,
+                                HighAddress,
+                                SkipBytes,
+                                2 * 1024 * 1024);
+    ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
+    if (skip(Mdl != NULL, "No Mdl\n"))
+        return;
+    ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+    ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+    ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+    MmFreePagesFromMdl(Mdl);
+
+    /* Now map/unmap it */
+    Mdl = MmAllocatePagesForMdl(LowAddress,
+                                HighAddress,
+                                SkipBytes,
+                                2 * 1024 * 1024);
+    ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
+    if (skip(Mdl != NULL, "No Mdl\n"))
+        return;
+    ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+    ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+    ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+    SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
+                                            KernelMode,
+                                            MmCached,
+                                            NULL,
+                                            FALSE,
+                                            NormalPagePriority);
+    ok(SystemVa != NULL, "MmMapLockedPagesSpecifyCache failed\n");
+    if (!skip(SystemVa != NULL, "No system VA\n"))
+    {
+        ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+        ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdl), SystemVa);
+        ok(Mdl->MappedSystemVa == SystemVa, "MappedSystemVa: %p, System VA: %p\n", Mdl->MappedSystemVa, SystemVa);
+        ok((Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+        MmUnmapLockedPages(SystemVa, Mdl);
+    }
+    ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+    ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+    ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+    MmFreePagesFromMdl(Mdl);
+
+    /* Now map it, and free without unmapping */
+    Mdl = MmAllocatePagesForMdl(LowAddress,
+                                HighAddress,
+                                SkipBytes,
+                                2 * 1024 * 1024);
+    ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
+    if (skip(Mdl != NULL, "No Mdl\n"))
+        return;
+    ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+    ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+    ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+    SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
+                                            KernelMode,
+                                            MmCached,
+                                            NULL,
+                                            FALSE,
+                                            NormalPagePriority);
+    ok(SystemVa != NULL, "MmMapLockedPagesSpecifyCache failed\n");
+    ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+    ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdl), SystemVa);
+    ok(Mdl->MappedSystemVa == SystemVa, "MappedSystemVa: %p, System VA: %p\n", Mdl->MappedSystemVa, SystemVa);
+    ok((Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+    MmFreePagesFromMdl(Mdl);
+
+    /* try to allocate 2 GB -- should succeed but not map */
+    Mdl = MmAllocatePagesForMdl(LowAddress,
+                                HighAddress,
+                                SkipBytes,
+                                2UL * 1024 * 1024 * 1024);
+    ok(Mdl != NULL, "MmAllocatePagesForMdl failed for 2 GB\n");
+    if (Mdl != NULL)
+    {
+        ok(MmGetMdlByteCount(Mdl) != 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+        ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+        ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+        SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
+                                                KernelMode,
+                                                MmCached,
+                                                NULL,
+                                                FALSE,
+                                                NormalPagePriority);
+        ok(SystemVa == NULL, "MmMapLockedPagesSpecifyCache succeeded for 2 GB\n");
+        if (SystemVa != NULL)
+            MmUnmapLockedPages(SystemVa, Mdl);
+        ok(MmGetMdlByteCount(Mdl) != 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
+        ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
+        ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
+        MmFreePagesFromMdl(Mdl);
+    }
+
+    /* now allocate and map 32 MB Mdls until we fail */
+    for (i = 0; i < sizeof(Mdls) / sizeof(Mdls[0]); i++)
+    {
+        Mdls[i] = MmAllocatePagesForMdl(LowAddress,
+                                        HighAddress,
+                                        SkipBytes,
+                                        32 * 1024 * 1024);
+        if (Mdls[i] == NULL)
+        {
+            trace("MmAllocatePagesForMdl failed with i = %lu\n", i);
+            break;
+        }
+        ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdls[i]));
+        ok(!(Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
+        SystemVas[i] = MmMapLockedPagesSpecifyCache(Mdls[i],
+                                                    KernelMode,
+                                                    MmCached,
+                                                    NULL,
+                                                    FALSE,
+                                                    NormalPagePriority);
+        if (SystemVas[i] == NULL)
+        {
+            ok(MmGetMdlByteCount(Mdls[i]) <= 32 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdls[i]));
+            ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdls[i]));
+            ok(!(Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
+            trace("MmMapLockedPagesSpecifyCache failed with i = %lu\n", i);
+            break;
+        }
+        ok(MmGetMdlByteCount(Mdls[i]) == 32 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdls[i]));
+        ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdls[i]), SystemVas[i]);
+        ok(Mdls[i]->MappedSystemVa == SystemVas[i], "MappedSystemVa: %p\n", Mdls[i]->MappedSystemVa, SystemVas[i]);
+        ok((Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
+    }
+    for (i = 0; i < sizeof(Mdls) / sizeof(Mdls[0]); i++)
+    {
+        if (Mdls[i] == NULL)
+            break;
+        if (SystemVas[i] != NULL)
+            MmUnmapLockedPages(SystemVas[i], Mdls[i]);
+        MmFreePagesFromMdl(Mdls[i]);
+        if (SystemVas[i] == NULL)
+            break;
+    }
+}
+
+START_TEST(MmMdl)
+{
+    TestMmAllocatePagesForMdl();
+}