Author: tfaber
Date: Wed Jun 13 21:56:54 2012
New Revision: 56730
URL: 
http://svn.reactos.org/svn/reactos?rev=56730&view=rev
Log:
[KMTESTS]
- Return a boolean from ok()
- Add KmtGetPoolTag function to allow verifying pool tags used for allocations
Modified:
    trunk/rostests/kmtests/include/kmt_test.h
    trunk/rostests/kmtests/ntos_ex/ExPools.c
Modified: trunk/rostests/kmtests/include/kmt_test.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/include/kmt_test.…
==============================================================================
--- trunk/rostests/kmtests/include/kmt_test.h [iso-8859-1] (original)
+++ trunk/rostests/kmtests/include/kmt_test.h [iso-8859-1] Wed Jun 13 21:56:54 2012
@@ -87,6 +87,7 @@
 VOID KmtSetIrql(IN KIRQL NewIrql);
 BOOLEAN KmtAreInterruptsEnabled(VOID);
+ULONG KmtGetPoolTag(PVOID Memory);
 #elif defined KMT_USER_MODE
 DWORD KmtRunKernelTest(IN PCSTR TestName);
@@ -124,8 +125,8 @@
 #define trace_(file, line, ...)      KmtTrace(     file ":"
KMT_STRINGIZE(line), __VA_ARGS__)
 #define skip_(test, file, line, ...) KmtSkip(test, file ":"
KMT_STRINGIZE(line), __VA_ARGS__)
-VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
KMT_FORMAT(ms_printf, 3, 0);
-VOID KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
KMT_FORMAT(ms_printf, 3, 4);
+BOOLEAN KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
KMT_FORMAT(ms_printf, 3, 0);
+BOOLEAN KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
KMT_FORMAT(ms_printf, 3, 4);
 VOID KmtVTrace(PCSTR FileAndLine, PCSTR Format, va_list Arguments)
KMT_FORMAT(ms_printf, 2, 0);
 VOID KmtTrace(PCSTR FileAndLine, PCSTR Format, ...)
KMT_FORMAT(ms_printf, 2, 3);
 BOOLEAN KmtVSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
KMT_FORMAT(ms_printf, 3, 0);
@@ -161,6 +162,7 @@
                                                 (expected) ? "TRUE" :
"FALSE")
 #define ok_eq_str(value, expected)          ok(!strcmp(value, expected), #value " =
\"%s\", expected \"%s\"\n", value, expected)
 #define ok_eq_wstr(value, expected)         ok(!wcscmp(value, expected), #value " =
\"%ls\", expected \"%ls\"\n", value, expected)
+#define ok_eq_tag(value, expected)          ok_eq_print(value, expected,
"0x%08lx")
 #define KMT_MAKE_CODE(ControlCode)  CTL_CODE(FILE_DEVICE_UNKNOWN,           \
                                              0xC00 + (ControlCode),         \
@@ -222,6 +224,58 @@
     return (__readeflags() & (1 << 9)) != 0;
 }
+typedef struct _POOL_HEADER
+{
+    union
+    {
+        struct
+        {
+#ifdef _M_AMD64
+            USHORT PreviousSize:8;
+            USHORT PoolIndex:8;
+            USHORT BlockSize:8;
+            USHORT PoolType:8;
+#else
+            USHORT PreviousSize:9;
+            USHORT PoolIndex:7;
+            USHORT BlockSize:9;
+            USHORT PoolType:7;
+#endif
+        };
+        ULONG Ulong1;
+    };
+#ifdef _M_AMD64
+    ULONG PoolTag;
+#endif
+    union
+    {
+#ifdef _M_AMD64
+        PEPROCESS ProcessBilled;
+#else
+        ULONG PoolTag;
+#endif
+        struct
+        {
+            USHORT AllocatorBackTraceIndex;
+            USHORT PoolTagHash;
+        };
+    };
+} POOL_HEADER, *PPOOL_HEADER;
+
+ULONG KmtGetPoolTag(PVOID Memory)
+{
+    PPOOL_HEADER Header;
+
+    /* it's not so easy for allocations of PAGE_SIZE */
+    if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
+        return 'TooL';
+
+    Header = Memory;
+    Header--;
+
+    return Header->PoolTag;
+}
+
 INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list
Arguments) KMT_FORMAT(ms_printf, 3, 0);
 #elif defined KMT_USER_MODE
 static PKMT_RESULTBUFFER KmtAllocateResultBuffer(SIZE_T ResultBufferSize)
@@ -335,13 +389,13 @@
     KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
 }
-VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
+BOOLEAN KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
 {
     CHAR MessageBuffer[512];
     SIZE_T MessageLength;
     if (!ResultBuffer)
-        return;
+        return Condition != 0;
     if (Condition)
     {
@@ -359,14 +413,18 @@
         MessageLength = KmtXVSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine,
": Test failed: ", Format, Arguments);
         KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
     }
-}
-
-VOID KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
-{
+
+    return Condition != 0;
+}
+
+BOOLEAN KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
+{
+    BOOLEAN Ret;
     va_list Arguments;
     va_start(Arguments, Format);
-    KmtVOk(Condition, FileAndLine, Format, Arguments);
+    Ret = KmtVOk(Condition, FileAndLine, Format, Arguments);
     va_end(Arguments);
+    return Ret;
 }
 VOID KmtVTrace(PCSTR FileAndLine, PCSTR Format, va_list Arguments)
Modified: trunk/rostests/kmtests/ntos_ex/ExPools.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/ntos_ex/ExPools.c…
==============================================================================
--- trunk/rostests/kmtests/ntos_ex/ExPools.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/ntos_ex/ExPools.c [iso-8859-1] Wed Jun 13 21:56:54 2012
@@ -145,8 +145,36 @@
     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();
 }