Author: tfaber
Date: Fri Sep 23 11:43:02 2011
New Revision: 53810
URL: 
http://svn.reactos.org/svn/reactos?rev=53810&view=rev
Log:
[KMTESTS/MM]
- Extend MmSection test to include passing different files and mapping a view
Modified:
    trunk/rostests/kmtests/ntos_mm/MmSection.c
Modified: trunk/rostests/kmtests/ntos_mm/MmSection.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/ntos_mm/MmSection…
==============================================================================
--- trunk/rostests/kmtests/ntos_mm/MmSection.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/ntos_mm/MmSection.c [iso-8859-1] Fri Sep 23 11:43:02 2011
@@ -18,6 +18,57 @@
     ok_eq_hex(Status, STATUS_SUCCESS);                              \
     ok_eq_ulong(ObjectInfo.PointerCount, Pointers);                 \
     ok_eq_ulong(ObjectInfo.HandleCount, Handles);                   \
+} while (0)
+
+#define CheckSection(SectionObject, SectionFlag) do                     \
+{                                                                       \
+    SECTION_BASIC_INFORMATION Sbi;                                      \
+    HANDLE SectionHandle = NULL;                                        \
+    NTSTATUS Status;                                                    \
+    if (skip(SectionObject != NULL &&                                   \
+             SectionObject != (PVOID)0x5555555555555555ULL,             \
+             "blah\n"))                                                 \
+        break;                                                          \
+    Status = ObOpenObjectByPointer(SectionObject, OBJ_KERNEL_HANDLE,    \
+                                   NULL, 0, MmSectionObjectType,        \
+                                   KernelMode, &SectionHandle);         \
+    ok_eq_hex(Status, STATUS_SUCCESS);                                  \
+    ok(SectionHandle != NULL, "Section handle null\n");                 \
+    if (!skip(NT_SUCCESS(Status) && SectionHandle,                      \
+              "No section handle\n"))                                   \
+    {                                                                   \
+        Status = ZwQuerySection(SectionHandle, SectionBasicInformation, \
+                                &Sbi, sizeof Sbi, NULL);                \
+        ok_eq_hex(Status, STATUS_SUCCESS);                              \
+        ok_eq_pointer(Sbi.BaseAddress, NULL);                           \
+        ok_eq_longlong(Sbi.Size.QuadPart, 1LL);                         \
+        ok_eq_hex(Sbi.Attributes, SectionFlag | SEC_FILE);              \
+        ZwClose(SectionHandle);                                         \
+    }                                                                   \
+} while (0)
+
+#define TestMapView(SectionObject, ExpectAtBase, ExpectM) do                    \
+{                                                                               \
+    NTSTATUS Status;                                                            \
+    PVOID BaseAddress = NULL;                                                   \
+    SIZE_T ViewSize = 0;                                                        \
+    LARGE_INTEGER SectionOffset;                                                \
+    if (skip(SectionObject != NULL &&                                           \
+             SectionObject != (PVOID)0x5555555555555555ULL,                     \
+             "No section object\n"))
\
+        break;                                                                  \
+                                                                                \
+    SectionOffset.QuadPart = 0;                                                 \
+    Status = MmMapViewOfSection(SectionObject, PsGetCurrentProcess(),           \
+                                &BaseAddress, 0, 1, &SectionOffset,             \
+                                &ViewSize, ViewUnmap, 0, PAGE_READONLY);        \
+    ok_eq_hex(Status, ExpectAtBase ? STATUS_SUCCESS : STATUS_IMAGE_NOT_AT_BASE);\
+    if (!skip(NT_SUCCESS(Status), "Section not mapped\n"))
\
+    {                                                                           \
+        ok_eq_uint(*(PUCHAR)BaseAddress, ExpectM ? 'M' : 0);                    \
+        Status = MmUnmapViewOfSection(PsGetCurrentProcess(), BaseAddress);      \
+        ok_eq_hex(Status, STATUS_SUCCESS);                                      \
+    }                                                                           \
 } while (0)
 static
@@ -149,6 +200,8 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle2, PointerCount2, 1L);
+        CheckSection(SectionObject, SEC_IMAGE);
+        TestMapView(SectionObject, FALSE, TRUE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -165,6 +218,8 @@
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         ++PointerCount2;
         CheckObject(FileHandle2, PointerCount2, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, TRUE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -181,6 +236,8 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle2, PointerCount2, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, TRUE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -212,6 +269,8 @@
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         ++PointerCount1;
         CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -228,6 +287,45 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
+
+        if (SectionObject && SectionObject != InvalidPointer)
+            ObDereferenceObject(SectionObject);
+
+        /* image section with two different files */
+        CheckObject(FileHandle1, PointerCount1, 1L);
+        SectionObject = InvalidPointer;
+        MaximumSize.QuadPart = 1;
+        StartSeh()
+            Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize,
PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
+        EndSeh(STATUS_SUCCESS);
+        ok_eq_hex(Status, STATUS_SUCCESS);
+        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
+        ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
+        ok(SectionObject != NULL, "Section object pointer NULL\n");
+        CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckObject(FileHandle2, PointerCount2, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, TRUE);
+
+        if (SectionObject && SectionObject != InvalidPointer)
+            ObDereferenceObject(SectionObject);
+
+        CheckObject(FileHandle1, PointerCount1, 1L);
+        SectionObject = InvalidPointer;
+        MaximumSize.QuadPart = 1;
+        StartSeh()
+            Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize,
PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
+        EndSeh(STATUS_SUCCESS);
+        ok_eq_hex(Status, STATUS_SUCCESS);
+        ok_eq_longlong(MaximumSize.QuadPart, 1LL);
+        ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
+        ok(SectionObject != NULL, "Section object pointer NULL\n");
+        CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckObject(FileHandle2, PointerCount2, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -244,6 +342,8 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -259,6 +359,8 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -274,6 +376,8 @@
         ok(SectionObject != InvalidPointer, "Section object pointer
untouched\n");
         ok(SectionObject != NULL, "Section object pointer NULL\n");
         CheckObject(FileHandle1, PointerCount1, 1L);
+        CheckSection(SectionObject, 0);
+        TestMapView(SectionObject, TRUE, FALSE);
         if (SectionObject && SectionObject != InvalidPointer)
             ObDereferenceObject(SectionObject);
@@ -294,6 +398,7 @@
     LARGE_INTEGER FileOffset;
     UCHAR FileData = 0;
+    ok(ExGetPreviousMode() == UserMode, "Previous mode is kernel mode\n");
     /* create a one-byte file that we can use */
     InitializeObjectAttributes(&ObjectAttributes, &FileName1,
OBJ_CASE_INSENSITIVE, NULL, NULL);
     Status = ZwCreateFile(&FileHandle1, GENERIC_ALL, &ObjectAttributes,
&IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_SUPERSEDE,
FILE_NON_DIRECTORY_FILE, NULL, 0);