[KMTESTS]
[reactos.git] / rostests / kmtests / ntos_ex / ExPools.c
index c635720..6263faa 100644 (file)
@@ -5,8 +5,6 @@
  * PROGRAMMER:      Aleksey Bragin <aleksey@reactos.org>
  */
 
-/* TODO: PoolsCorruption tests fail because accessing invalid memory doesn't necessarily cause an access violation */
-
 #include <kmt_test.h>
 
 #define NDEBUG
@@ -101,9 +99,8 @@ static VOID PoolsTest(VOID)
 
 static VOID PoolsCorruption(VOID)
 {
-    PULONG Ptr, TestPtr;
+    PULONG Ptr;
     ULONG AllocSize;
-    NTSTATUS Status = STATUS_SUCCESS;
 
     // start with non-paged pool
     AllocSize = 4096 + 0x10;
@@ -112,6 +109,9 @@ static VOID PoolsCorruption(VOID)
     // touch all bytes, it shouldn't cause an exception
     RtlZeroMemory(Ptr, AllocSize);
 
+/* TODO: These fail because accessing invalid memory doesn't necessarily
+         cause an access violation */
+#ifdef THIS_DOESNT_WORK
     // test buffer overrun, right after our allocation ends
     _SEH2_TRY
     {
@@ -139,13 +139,42 @@ static VOID PoolsCorruption(VOID)
     } _SEH2_END;
 
     ok(Status == STATUS_ACCESS_VIOLATION, "Exception should occur, but got Status 0x%08lX\n", Status);
+#endif
 
     // free the pool
     ExFreePoolWithTag(Ptr, TAG_POOLTEST);
 }
 
+static
+VOID
+TestPoolTags(VOID)
+{
+    PVOID Memory;
+
+    Memory = ExAllocatePoolWithTag(PagedPool, 8, 'MyTa');
+    ok_eq_tag(KmtGetPoolTag(Memory), 'MyTa');
+    ExFreePoolWithTag(Memory, 'MyTa');
+
+    Memory = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, 'MyTa');
+    ok_eq_tag(KmtGetPoolTag(Memory), 'TooL');
+    ExFreePoolWithTag(Memory, 'MyTa');
+
+    Memory = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE - 3 * sizeof(PVOID), 'MyTa');
+    ok_eq_tag(KmtGetPoolTag(Memory), 'TooL');
+    ExFreePoolWithTag(Memory, 'MyTa');
+
+    Memory = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE - 4 * sizeof(PVOID) + 1, 'MyTa');
+    ok_eq_tag(KmtGetPoolTag(Memory), 'TooL');
+    ExFreePoolWithTag(Memory, 'MyTa');
+
+    Memory = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE - 4 * sizeof(PVOID), 'MyTa');
+    ok_eq_tag(KmtGetPoolTag(Memory), 'MyTa');
+    ExFreePoolWithTag(Memory, 'MyTa');
+}
+
 START_TEST(ExPools)
 {
     PoolsTest();
     PoolsCorruption();
+    TestPoolTags();
 }