[KMTESTS]
authorThomas Faber <thomas.faber@reactos.org>
Wed, 10 Aug 2011 22:26:14 +0000 (22:26 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Wed, 10 Aug 2011 22:26:14 +0000 (22:26 +0000)
- Remove breakpoint on buffer overflow
- Use a compromise for ok_* macros for SIZE_T and [U]LONG_PTR values

svn path=/branches/GSoC_2011/KMTestSuite/; revision=53167

kmtests/include/kmt_test.h
kmtests/ntos_ex/ExResource.c
kmtests/ntos_ke/KeSpinLock.c
kmtests/rtl/RtlMemory.c

index 2f33ccf..838d397 100644 (file)
@@ -100,10 +100,6 @@ DWORD KmtSendBufferToDriver(IN DWORD ControlCode, IN OUT PVOID Buffer OPTIONAL,
 
 extern PKMT_RESULTBUFFER ResultBuffer;
 
-#define MICROSECOND     10
-#define MILLISECOND     (1000 * MICROSECOND)
-#define SECOND          (1000 * MILLISECOND)
-
 #ifdef __GNUC__
 #define KMT_FORMAT(type, fmt, first) __attribute__((__format__(type, fmt, first)))
 #elif !defined __GNUC__
@@ -141,7 +137,15 @@ BOOLEAN KmtSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
 #define ok_eq_ulong(value, expected)        ok_eq_print(value, expected, "%lu")
 #define ok_eq_longlong(value, expected)     ok_eq_print(value, expected, "%I64d")
 #define ok_eq_ulonglong(value, expected)    ok_eq_print(value, expected, "%I64u")
-#define ok_eq_size(value, expected)         ok_eq_ulonglong((ULONGLONG)(value), (ULONGLONG)(expected))
+#ifndef _WIN64
+#define ok_eq_size(value, expected)         ok_eq_print(value, (SIZE_T)(expected), "%lu")
+#define ok_eq_longptr(value, expected)      ok_eq_print(value, (LONG_PTR)(expected), "%ld")
+#define ok_eq_ulongptr(value, expected)     ok_eq_print(value, (ULONG_PTR)(expected), "%lu")
+#elif defined _WIN64
+#define ok_eq_size(value, expected)         ok_eq_print(value, (SIZE_T)(expected), "%I64u")
+#define ok_eq_longptr(value, expected)      ok_eq_print(value, (LONG_PTR)(expected), "%I64d")
+#define ok_eq_ulongptr(value, expected)     ok_eq_print(value, (ULONG_PTR)(expected), "%I64u")
+#endif /* defined _WIN64 */
 #define ok_eq_hex(value, expected)          ok_eq_print(value, expected, "0x%08lx")
 #define ok_bool_true(value, desc)           ok((value) == TRUE, desc " FALSE, expected TRUE\n")
 #define ok_bool_false(value, desc)          ok((value) == FALSE, desc " TRUE, expected FALSE\n")
@@ -156,6 +160,10 @@ BOOLEAN KmtSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
                                              METHOD_BUFFERED,               \
                                              FILE_ANY_ACCESS)
 
+#define MICROSECOND     10
+#define MILLISECOND     (1000 * MICROSECOND)
+#define SECOND          (1000 * MILLISECOND)
+
 #if defined KMT_DEFINE_TEST_FUNCTIONS
 
 #if defined KMT_KERNEL_MODE
@@ -216,11 +224,7 @@ static VOID KmtAddToLogBuffer(PKMT_RESULTBUFFER Buffer, PCSTR String, SIZE_T Len
         OldLength = Buffer->LogBufferLength;
         NewLength = OldLength + Length;
         if (NewLength > Buffer->LogBufferMaxLength)
-        {
-            /* TODO: indicate failure somehow */
-            __debugbreak();
             return;
-        }
     } while (InterlockedCompareExchange(&Buffer->LogBufferLength, NewLength, OldLength) != OldLength);
 
     memcpy(&Buffer->LogBuffer[OldLength], String, Length);
index 80bcfa9..b8b7147 100644 (file)
@@ -44,16 +44,16 @@ typedef struct _ERESOURCE_2K3 {
     ok_eq_uint((Res)->Flag, 0);                                                                                 \
     if (!Reinit) ok_eq_pointer((Res)->SharedWaiters, NULL);                                                     \
     if (!Reinit) ok_eq_pointer((Res)->ExclusiveWaiters, NULL);                                                  \
-    ok_eq_pointer((PVOID)(Res)->OwnerThreads[0].OwnerThread, NULL);                                             \
+    ok_eq_ulongptr((Res)->OwnerThreads[0].OwnerThread, 0);                                                      \
     ok_eq_ulong((Res)->OwnerThreads[0].TableSize, 0LU);                                                         \
-    ok_eq_pointer((PVOID)(Res)->OwnerThreads[1].OwnerThread, NULL);                                             \
+    ok_eq_ulongptr((Res)->OwnerThreads[1].OwnerThread, 0);                                                      \
     ok_eq_ulong((Res)->OwnerThreads[1].TableSize, 0LU);                                                         \
     ok_eq_ulong((Res)->ContentionCount, 0LU);                                                                   \
     ok_eq_uint((Res)->NumberOfSharedWaiters, 0);                                                                \
     ok_eq_uint((Res)->NumberOfExclusiveWaiters, 0);                                                             \
     /* ok_eq_pointer((Res)->Reserved2, NULL); */                                                                \
     ok_eq_pointer((Res)->Address, NULL);                                                                        \
-    ok_eq_pointer((PVOID)(Res)->SpinLock, NULL);                                                                \
+    ok_eq_ulongptr((Res)->SpinLock, 0);                                                                         \
 } while (0)
 
 #define CheckResourceStatus(Res, Exclusive, Shared, ExclusiveWaiters, SharedWaiters) do                         \
index 542053f..b03e0ea 100644 (file)
@@ -140,14 +140,14 @@ BOOLEAN TryNoRaise(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) {
     {                                                                               \
         ok_eq_bool(Ret, (Value) == 0);                                              \
         if (SpinLock)                                                               \
-            ok_eq_pointer((PVOID)*(SpinLock),                                       \
-                        (Value) ? (PVOID)((ULONG_PTR)Thread | 1) : 0);              \
+            ok_eq_ulongptr(*(SpinLock),                                             \
+                        (Value) ? (ULONG_PTR)Thread | 1 : 0);                       \
     }                                                                               \
     else                                                                            \
     {                                                                               \
         ok_bool_true(Ret, "KeTestSpinLock returned");                               \
         if (SpinLock)                                                               \
-            ok_eq_pointer((PVOID)*(SpinLock), NULL);                                \
+            ok_eq_ulongptr(*(SpinLock), 0);                                         \
     }                                                                               \
     ok_eq_uint((CheckData)->Irql, (CheckData)->OriginalIrql);                       \
 } while (0)
@@ -165,7 +165,7 @@ BOOLEAN TryNoRaise(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) {
     {                                                                               \
         ok_eq_bool(Ret, (Value) == 0);                                              \
         if (SpinLock)                                                               \
-            ok_eq_pointer((PVOID)*(SpinLock),                                       \
+            ok_eq_ulongptr(*(SpinLock),                                             \
                         (Value) ? &(CheckData)->QueueHandle : 0);                   \
         ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Next, NULL);               \
         ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Lock,                      \
@@ -175,7 +175,7 @@ BOOLEAN TryNoRaise(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) {
     {                                                                               \
         ok_bool_true(Ret, "KeTestSpinLock returned");                               \
         if (SpinLock)                                                               \
-            ok_eq_pointer((PVOID)*(SpinLock), NULL);                                \
+            ok_eq_ulongptr(*(SpinLock), 0);                                         \
         ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Next, (CheckData)->UntouchedValue);                \
         ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Lock, (CheckData)->UntouchedValue);                \
     }                                                                               \
@@ -219,7 +219,7 @@ TestSpinLock(
     ok_irql(CheckData->OriginalIrql);
 
     if (SpinLock)
-        ok_eq_pointer((PVOID)*SpinLock, NULL);
+        ok_eq_ulongptr(*SpinLock, 0);
     CheckData->Acquire(SpinLock, CheckData);
     CheckSpinLock(SpinLock, CheckData, 1);
     CheckData->Release(SpinLock, CheckData);
@@ -312,7 +312,7 @@ START_TEST(KeSpinLock)
     /* KeInitializeSpinLock */
     memset(&SpinLock, 0x55, sizeof SpinLock);
     KeInitializeSpinLock(&SpinLock);
-    ok_eq_pointer((PVOID)SpinLock, NULL);
+    ok_eq_ulongptr(SpinLock, 0);
 
     /* KeTestSpinLock */
     ok_bool_true(KeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
index 43043b6..49dcf3e 100644 (file)
@@ -156,11 +156,11 @@ START_TEST(RtlMemory)
 {
     NTSTATUS Status;
     UCHAR Buffer[513];
-    const INT Size = 512;
-    const INT HalfSize = Size / 2;
+    const SIZE_T Size = 512;
+    const SIZE_T HalfSize = Size / 2;
     SIZE_T RetSize;
     KIRQL Irql;
-    INT i;
+    ULONG i;
 
     KeRaiseIrql(HIGH_LEVEL, &Irql);
     /* zero everything behind 'Size'. Tests will check that this wasn't changed.
@@ -308,7 +308,7 @@ START_TEST(RtlMemory)
         RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, SIZE_MAX);
         ok_eq_size(RetSize, HalfSize - 8 + 1);
         RetSize = RtlCompareMemory(NULL, NULL, 0);
-        ok_eq_size(RetSize, 0LU);
+        ok_eq_size(RetSize, 0);
     } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
         Status = _SEH2_GetExceptionCode();
     } _SEH2_END;
@@ -318,31 +318,31 @@ START_TEST(RtlMemory)
     /* RtlCompareMemoryUlong */
     MakeBuffer(Buffer, 8, 0x55, Size - 4, 0, 0);
     RetSize = RtlCompareMemoryUlong(Buffer, sizeof(ULONG), 0x55555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
     RetSize = RtlCompareMemoryUlong(Buffer + 1, sizeof(ULONG), 0x55555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
     RetSize = RtlCompareMemoryUlong(Buffer + 2, sizeof(ULONG), 0x55555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
     RetSize = RtlCompareMemoryUlong(Buffer + 3, sizeof(ULONG), 0x55555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
     RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x55555555LU);
-    ok_eq_size(RetSize, 0LU);
+    ok_eq_size(RetSize, 0);
     RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x00555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
     RetSize = RtlCompareMemoryUlong(Buffer, 1, 0x55555555LU);
-    ok_eq_size(RetSize, 0LU);
+    ok_eq_size(RetSize, 0);
     RetSize = RtlCompareMemoryUlong(Buffer, 2, 0x55555555LU);
-    ok_eq_size(RetSize, 0LU);
+    ok_eq_size(RetSize, 0);
     RetSize = RtlCompareMemoryUlong(Buffer, 3, 0x55555555LU);
-    ok_eq_size(RetSize, 0LU);
+    ok_eq_size(RetSize, 0);
     RetSize = RtlCompareMemoryUlong(Buffer, 5, 0x55555555LU);
-    ok_eq_size(RetSize, 4LU);
+    ok_eq_size(RetSize, 4);
 
     KeLowerIrql(Irql);
     Status = STATUS_SUCCESS;
     _SEH2_TRY {
         RetSize = RtlCompareMemoryUlong(NULL, 0, 0x55555555LU);
-        ok_eq_size(RetSize, 0LU);
+        ok_eq_size(RetSize, 0);
     } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
         Status = _SEH2_GetExceptionCode();
     } _SEH2_END;