https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e3531499c25d1ce48139fd600f0bba8cf1f3a46e

commit e3531499c25d1ce48139fd600f0bba8cf1f3a46e
Author:     Pierre Schweitzer <pie...@reactos.org>
AuthorDate: Sat Oct 13 19:13:07 2018 +0200
Commit:     Pierre Schweitzer <pie...@reactos.org>
CommitDate: Sat Oct 13 19:13:07 2018 +0200

    [KMTESTS:CC] Add more tests for CcPinMappedData()
---
 .../rostests/kmtests/ntos_cc/CcPinMappedData_drv.c | 100 ++++++++++++++++++++-
 .../kmtests/ntos_cc/CcPinMappedData_user.c         |   2 +-
 2 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/modules/rostests/kmtests/ntos_cc/CcPinMappedData_drv.c 
b/modules/rostests/kmtests/ntos_cc/CcPinMappedData_drv.c
index 06cbc95987..89b348fe71 100644
--- a/modules/rostests/kmtests/ntos_cc/CcPinMappedData_drv.c
+++ b/modules/rostests/kmtests/ntos_cc/CcPinMappedData_drv.c
@@ -23,7 +23,7 @@ typedef struct _TEST_FCB
 typedef struct _TEST_CONTEXT
 {
     PVOID Bcb;
-    PVOID Buffer;
+    PULONG Buffer;
     ULONG Length;
 } TEST_CONTEXT, *PTEST_CONTEXT;
 
@@ -144,6 +144,74 @@ MapAndLockUserBuffer(
     return MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
 }
 
+static
+VOID
+NTAPI
+PinInAnotherThreadExclusive(IN PVOID Context)
+{
+    BOOLEAN Ret;
+    PULONG Buffer;
+    PVOID Bcb, PinBcb;
+    LARGE_INTEGER Offset;
+    PTEST_CONTEXT TestContext;
+
+    ok(TestFileObject != NULL, "Called in invalid context!\n");
+    ok_eq_ulong(TestTestId, 2);
+
+    TestContext = Context;
+    ok(TestContext != NULL, "Called in invalid context!\n");
+    ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
+    ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
+    ok(TestContext->Length != 0, "Called in invalid context!\n");
+
+    Ret = FALSE;
+    Offset.QuadPart = 0;
+
+    KmtStartSeh();
+    Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, 
&Bcb, (PVOID *)&Buffer);
+    KmtEndSeh(STATUS_SUCCESS);
+
+    if (!skip(Ret == TRUE, "CcMapData failed\n"))
+    {
+        ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
+        ok_eq_pointer(Buffer, TestContext->Buffer);
+
+        Ret = FALSE;
+        PinBcb = Bcb;
+
+        KmtStartSeh();
+        Ret = CcPinMappedData(TestFileObject, &Offset, 
FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_EXCLUSIVE, &PinBcb);
+        KmtEndSeh(STATUS_SUCCESS);
+
+        if (!skip(Ret == FALSE, "CcPinMappedData succeed\n"))
+        {
+            ok_eq_pointer(PinBcb, Bcb);
+
+            Ret = FALSE;
+            PinBcb = Bcb;
+
+            KmtStartSeh();
+            Ret = CcPinMappedData(TestFileObject, &Offset, 
FileSizes.FileSize.QuadPart - Offset.QuadPart, 0, &PinBcb);
+            KmtEndSeh(STATUS_SUCCESS);
+
+            if (!skip(Ret == FALSE, "CcPinMappedData succeed\n"))
+            {
+                ok_eq_pointer(PinBcb, Bcb);
+            }
+            else
+            {
+                Bcb = PinBcb;
+            }
+        }
+        else
+        {
+            Bcb = PinBcb;
+        }
+
+        CcUnpinData(Bcb);
+    }
+}
+
 static
 VOID
 PerformTest(
@@ -255,6 +323,36 @@ PerformTest(
                         CcUnpinData(PinBcb);
                     }
                 }
+                else if (TestId == 2)
+                {
+                    PTEST_CONTEXT TestContext;
+
+                    TestContext = ExAllocatePool(NonPagedPool, 
sizeof(TEST_CONTEXT));
+                    if (!skip(TestContext != NULL, "ExAllocatePool failed\n"))
+                    {
+                        Ret = FALSE;
+                        Offset.QuadPart = 0;
+                        KmtStartSeh();
+                        Ret = CcPinRead(TestFileObject, &Offset, 
FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_EXCLUSIVE, 
&TestContext->Bcb, (PVOID *)&TestContext->Buffer);
+                        KmtEndSeh(STATUS_SUCCESS);
+
+                        if (!skip(Ret == TRUE, "CcPinRead failed\n"))
+                        {
+                            PKTHREAD ThreadHandle;
+
+                            ok(*(PUSHORT)TestContext->Bcb == 0x2FD, "Not a 
BCB: %x\n", *(PUSHORT)TestContext->Bcb);
+                            ok_eq_ulong(TestContext->Buffer[0x3000 / 
sizeof(ULONG)], 0xDEADBABE);
+
+                            TestContext->Length = FileSizes.FileSize.QuadPart 
- Offset.QuadPart;
+                            ThreadHandle = 
KmtStartThread(PinInAnotherThreadExclusive, TestContext);
+                            KmtFinishThread(ThreadHandle, NULL);
+
+                            CcUnpinData(TestContext->Bcb);
+                        }
+
+                        ExFreePool(TestContext);
+                    }
+                }
             }
         }
     }
diff --git a/modules/rostests/kmtests/ntos_cc/CcPinMappedData_user.c 
b/modules/rostests/kmtests/ntos_cc/CcPinMappedData_user.c
index 095d55ed1d..14bc2aa5e9 100644
--- a/modules/rostests/kmtests/ntos_cc/CcPinMappedData_user.c
+++ b/modules/rostests/kmtests/ntos_cc/CcPinMappedData_user.c
@@ -19,7 +19,7 @@ START_TEST(CcPinMappedData)
     KmtOpenDriver();
 
     /* 1 basic test */
-    for (TestId = 0; TestId < 2; ++TestId)
+    for (TestId = 0; TestId < 3; ++TestId)
     {
         Ret = KmtSendUlongToDriver(IOCTL_START_TEST, TestId);
         ok(Ret == ERROR_SUCCESS, "KmtSendUlongToDriver failed: %lx\n", Ret);

Reply via email to