Followed Casper's advice to use macros to simplify regression tests
authorJason Filby <jason.filby@gmail.com>
Tue, 27 Apr 2004 20:31:32 +0000 (20:31 +0000)
committerJason Filby <jason.filby@gmail.com>
Tue, 27 Apr 2004 20:31:32 +0000 (20:31 +0000)
svn path=/trunk/; revision=9233

reactos/regtests/kmregtests/tests/mdl-1.c
reactos/regtests/kmregtests/tests/mdl-2.c
reactos/regtests/kmregtests/tests/mm-1.c
reactos/regtests/shared/regtests.h

index 7db8986..753c488 100644 (file)
@@ -16,33 +16,18 @@ static int RunTest(char *Buffer)
 
   /* MmSizeOfMdl test */
   MdlSize = 0;
-  MdlSize = MmSizeOfMdl(pmem1,
-                        AllocSize);
-  if (MdlSize <= sizeof(MDL))
-  {
-    strcpy(Buffer, "MmSizeOfMdl() failed\n");
-    return TS_FAILED;
-  }
+  MdlSize = MmSizeOfMdl(pmem1, AllocSize);
+  FAIL_IF_LESS_EQUAL(MdlSize, sizeof(MDL), "MmSizeOfMdl() failed");
 
   /* MmCreateMdl test */
   Mdl = NULL;
-  Mdl = MmCreateMdl(NULL,
-                    pmem1,
-                    AllocSize);
-  if (Mdl == NULL)
-  {
-    strcpy(Buffer, "MmCreateMdl() failed for Mdl\n");
-    return TS_FAILED;
-  }
+  Mdl = MmCreateMdl(NULL, pmem1, AllocSize);
+  FAIL_IF_NULL(Mdl, "MmCreateMdl() failed for Mdl");
 
   /* MmGetMdlByteCount test */
   MdlSize = 0;
   MdlSize = MmGetMdlByteCount(Mdl);
-  if (MdlSize != AllocSize)
-  {
-    strcpy(Buffer, "MmGetMdlByteCount() failed for Mdl\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_NOT_EQUAL(MdlSize, AllocSize, "MmGetMdlByteCount() failed for Mdl");
 
   /* MmGetMdlByteOffset test */
   MdlOffset = MmGetMdlByteOffset(Mdl);
@@ -50,20 +35,12 @@ static int RunTest(char *Buffer)
   /* MmGetMdlPfnArray test */
   MdlPfnArray = NULL;
   MdlPfnArray = MmGetMdlPfnArray(Mdl);
-  if (MdlPfnArray == NULL)
-  {
-    strcpy(Buffer, "MmGetMdlPfnArray() failed for Mdl\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_NULL(MdlPfnArray, "MmGetMdlPfnArray() failed for Mdl");
 
   /* MmGetMdlVirtualAddress test */
   MdlVirtAddr = NULL;
   MdlVirtAddr = MmGetMdlVirtualAddress(Mdl);
-  if (MdlVirtAddr == NULL)
-  {
-    strcpy(Buffer, "MmGetMdlVirtualAddress() failed for Mdl\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_NULL(MdlVirtAddr, "MmGetMdlVirtualAddress() failed for Mdl");
 
   /* Free memory used in test */
   ExFreePool(pmem1);
@@ -74,15 +51,5 @@ static int RunTest(char *Buffer)
 int
 Mdl_1Test(int Command, char *Buffer)
 {
-  switch (Command)
-    {
-      case TESTCMD_RUN:
-        return RunTest(Buffer);
-      case TESTCMD_TESTNAME:
-        strcpy(Buffer, "Kernel Memory MDL API (1)");
-        return TS_OK;
-      default:
-        break;
-    }
-  return TS_FAILED;
+  DISPATCHER("Kernel Memory MDL API (1)");
 }
index 75624b3..2f4418e 100644 (file)
@@ -7,56 +7,36 @@ static int RunTest(char *Buffer)
 {
   VOID *pmem1, *sysaddr1, *sysaddr2;
   ULONG AllocSize;
+  BOOLEAN BoolVal;
   PMDL Mdl;
 
   /* Allocate memory for use in testing */
   AllocSize = 1024;
-  pmem1 = ExAllocatePool(NonPagedPool,
-                         AllocSize);
+  pmem1 = ExAllocatePool(NonPagedPool, AllocSize);
 
   /* MmCreateMdl test */
   Mdl = NULL;
-  Mdl = MmCreateMdl(NULL,
-                    pmem1,
-                    AllocSize);
-  if (Mdl == NULL)
-  {
-    strcpy(Buffer, "MmCreateMdl() failed for Mdl\n");
-    return TS_FAILED;
-  }
+  Mdl = MmCreateMdl(NULL, pmem1, AllocSize);
+  FAIL_IF_NULL(Mdl, "MmCreateMdl() failed for Mdl");
 
   /* MmBuildMdlForNonPagedPool test */
   MmBuildMdlForNonPagedPool(Mdl);
 
   /* MmGetSystemAddressForMdl test for buffer built by MmBuildMdlForNonPagedPool */
   sysaddr1 = MmGetSystemAddressForMdl(Mdl);
-  if (sysaddr1 == NULL)
-  {
-    strcpy(Buffer, "MmGetSystemAddressForMdl() failed for Mdl after MmBuildMdlForNonPagedPool\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_NULL(sysaddr1, "MmGetSystemAddressForMdl() failed for Mdl after MmBuildMdlForNonPagedPool");
 
   /* MmIsNonPagedSystemAddressValid test */
-  if (MmIsNonPagedSystemAddressValid(sysaddr1) == FALSE)
-  {
-    strcpy(Buffer, "MmIsNonPagedSystemAddressValid() failed for Mdl for sysaddr1\n");
-    return TS_FAILED;
-  }
+  BoolVal = MmIsNonPagedSystemAddressValid(sysaddr1);
+  FAIL_IF_FALSE(BoolVal, "MmIsNonPagedSystemAddressValid() failed for Mdl for sysaddr1");
 
   /* MmGetSystemAddressForMdlSafe test */
   sysaddr2 = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority);
-  if (sysaddr2 == NULL)
-  {
-    strcpy(Buffer, "MmGetSystemAddressForMdlSafe() failed for Mdl after MmBuildMdlForNonPagedPool\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_NULL(sysaddr2, "MmGetSystemAddressForMdlSafe() failed for Mdl after MmBuildMdlForNonPagedPool");
 
   /* MmIsNonPagedSystemAddressValid test */
-  if (MmIsNonPagedSystemAddressValid(sysaddr2) == FALSE)
-  {
-    strcpy(Buffer, "MmIsNonPagedSystemAddressValid() failed for Mdl for sysaddr2\n");
-    return TS_FAILED;
-  }
+  BoolVal = MmIsNonPagedSystemAddressValid(sysaddr2);
+  FAIL_IF_FALSE(BoolVal, "MmIsNonPagedSystemAddressValid() failed for Mdl for sysaddr2");
 
   /* Free memory used in test */
   ExFreePool(pmem1);
@@ -67,15 +47,5 @@ static int RunTest(char *Buffer)
 int
 Mdl_2Test(int Command, char *Buffer)
 {
-  switch (Command)
-    {
-      case TESTCMD_RUN:
-        return RunTest(Buffer);
-      case TESTCMD_TESTNAME:
-        strcpy(Buffer, "Kernel Memory MDL API (2)");
-        return TS_OK;
-      default:
-        break;
-    }
-  return TS_FAILED;
+  DISPATCHER("Kernel Memory MDL API (2)");
 }
index 3d7e94d..c69a77f 100644 (file)
@@ -9,19 +9,14 @@ static int RunTest(char *Buffer)
   PHYSICAL_ADDRESS LowestAcceptableAddress, HighestAcceptableAddress, BoundryAddressMultiple,
                    PhysicalAddress;
   ULONG AllocSize1, AllocSize2, AllocSize3, AllocSize4, AllocSize5, MemSize;
-  BOOL Server;
+  BOOL Server, BoolVal;
 
   /* Various ways to allocate memory */
   HighestAcceptableAddress.QuadPart = 0x00000000FFFFFF; /* 16MB */
   AllocSize1 = 512;
   pmem1 = 0;
-  pmem1 = MmAllocateContiguousMemory(AllocSize1,
-                                     HighestAcceptableAddress);
-  if (pmem1 == 0)
-  {
-    strcpy(Buffer, "MmAllocateContiguousMemory() for pmem1 failed\n");
-    return TS_FAILED;
-  }
+  pmem1 = MmAllocateContiguousMemory(AllocSize1, HighestAcceptableAddress);
+  FAIL_IF_EQUAL(pmem1, 0, "MmAllocateContiguousMemory() for pmem1 failed");
 
   LowestAcceptableAddress.QuadPart = 0x00000000F00000; /* 15MB */
   HighestAcceptableAddress.QuadPart = 0x00000000FFFFFF; /* 16MB */
@@ -29,15 +24,9 @@ static int RunTest(char *Buffer)
   AllocSize2 = 512;
   pmem2 = 0;
   pmem2 = MmAllocateContiguousMemorySpecifyCache(AllocSize2,
-                                                 LowestAcceptableAddress,
-                                                 HighestAcceptableAddress,
-                                                 BoundryAddressMultiple,
-                                                 MmNonCached);
-  if (pmem2 == 0)
-  {
-    strcpy(Buffer, "MmAllocateContiguousMemorySpecifyCache() for pmem2 failed\n");
-    return TS_FAILED;
-  }
+                                                 LowestAcceptableAddress, HighestAcceptableAddress,
+                                                 BoundryAddressMultiple, MmNonCached);
+  FAIL_IF_EQUAL(pmem2, 0, "MmAllocateContiguousMemorySpecifyCache() for pmem2 failed");
 
   LowestAcceptableAddress.QuadPart = 0x00000000000000; /* 15MB */
   HighestAcceptableAddress.QuadPart = 0x0000000F000000; /* 250MB */
@@ -45,16 +34,9 @@ static int RunTest(char *Buffer)
   AllocSize3 = 512;
   pmem3 = 0;
   pmem3 = MmAllocateContiguousMemorySpecifyCache(AllocSize3,
-                                                 LowestAcceptableAddress,
-                                                 HighestAcceptableAddress,
-                                                 BoundryAddressMultiple,
-                                                 MmCached);
-  if (pmem3 == 0)
-  {
-    strcpy(Buffer, "MmAllocateContiguousMemorySpecifyCache() for pmem3 failed\n");
-    return TS_FAILED;
-  }
-
+                                                 LowestAcceptableAddress, HighestAcceptableAddress,
+                                                 BoundryAddressMultiple, MmCached);
+  FAIL_IF_EQUAL(pmem3, 0, "MmAllocateContiguousMemorySpecifyCache() for pmem3 failed");
 
   LowestAcceptableAddress.QuadPart = 0x00000000000000; /* 0MB */
   HighestAcceptableAddress.QuadPart = 0x00000000FFFFFF; /* 16MB */
@@ -62,85 +44,49 @@ static int RunTest(char *Buffer)
   AllocSize4 = 512;
   pmem4 = 0;
   pmem4 = MmAllocateContiguousMemorySpecifyCache(AllocSize4,
-                                                 LowestAcceptableAddress,
-                                                 HighestAcceptableAddress,
-                                                 BoundryAddressMultiple,
-                                                 MmWriteCombined);
-  if (pmem4 == 0)
-  {
-    strcpy(Buffer, "MmAllocateContiguousMemorySpecifyCache() for pmem4 failed\n");
-    return TS_FAILED;
-  }
+                                                 LowestAcceptableAddress, HighestAcceptableAddress,
+                                                 BoundryAddressMultiple, MmWriteCombined);
+  FAIL_IF_EQUAL(pmem4, 0, "MmAllocateContiguousMemorySpecifyCache() for pmem4 failed");
 
   AllocSize5 = 1048576; /* 1MB */
   pmem5 = 0;
   pmem5 = MmAllocateNonCachedMemory(AllocSize5);
-  if (pmem5 == 0)
-  {
-    strcpy(Buffer, "MmAllocateNonCachedMemory() for pmem5 failed\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_EQUAL(pmem5, 0, "MmAllocateNonCachedMemory() for pmem5 failed");
 
   /* Memory checking functions */
   PhysicalAddress.QuadPart = 0;
   PhysicalAddress = MmGetPhysicalAddress(pmem1);
-  if (PhysicalAddress.QuadPart == 0)
-  {
-    strcpy(Buffer, "MmGetPhysicalAddress() failed\n");
-    return TS_FAILED;
-  }
+  FAIL_IF_EQUAL(PhysicalAddress.QuadPart, 0, "MmGetPhysicalAddress() failed");
 
-  if (MmIsAddressValid(pmem1) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem1\n");
-    return TS_FAILED;
-  }
-  if (MmIsAddressValid(pmem2) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem2\n");
-    return TS_FAILED;
-  }
-  if (MmIsAddressValid(pmem3) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem3\n");
-    return TS_FAILED;
-  }
-  if (MmIsAddressValid(pmem4) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem4\n");
-    return TS_FAILED;
-  }
-  if (MmIsAddressValid(pmem5) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem5\n");
-    return TS_FAILED;
-  }
+  BoolVal = MmIsAddressValid(pmem1);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem1");
 
-  if (MmIsNonPagedSystemAddressValid(pmem1) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem1\n");
-    return TS_FAILED;
-  }
-  if (MmIsNonPagedSystemAddressValid(pmem2) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem2\n");
-    return TS_FAILED;
-  }
-  if (MmIsNonPagedSystemAddressValid(pmem3) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem3\n");
-    return TS_FAILED;
-  }
-  if (MmIsNonPagedSystemAddressValid(pmem4) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem4\n");
-    return TS_FAILED;
-  }
-  if (MmIsNonPagedSystemAddressValid(pmem5) == FALSE)
-  {
-    strcpy(Buffer, "MmIsAddressValid() failed for pmem5\n");
-    return TS_FAILED;
-  }
+  BoolVal = MmIsAddressValid(pmem2);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem2");
+
+  BoolVal = MmIsAddressValid(pmem3);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem3");
+
+  BoolVal = MmIsAddressValid(pmem4);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem4");
+
+  BoolVal = MmIsAddressValid(pmem5);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem5");
+
+  BoolVal = MmIsNonPagedSystemAddressValid(pmem1);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem1");
+
+  BoolVal = MmIsNonPagedSystemAddressValid(pmem2);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem2");
+
+  BoolVal = MmIsNonPagedSystemAddressValid(pmem3);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem3");
+
+  BoolVal = MmIsNonPagedSystemAddressValid(pmem4);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem4");
+
+  BoolVal = MmIsNonPagedSystemAddressValid(pmem5);
+  FAIL_IF_FALSE(BoolVal, "MmIsAddressValid() failed for pmem5");
 
   /* Misc functions */
   Server = MmIsThisAnNtAsSystem();
@@ -174,15 +120,5 @@ static int RunTest(char *Buffer)
 int
 Mm_1Test(int Command, char *Buffer)
 {
-  switch (Command)
-    {
-      case TESTCMD_RUN:
-        return RunTest(Buffer);
-      case TESTCMD_TESTNAME:
-        strcpy(Buffer, "Kernel Core Memory API");
-        return TS_OK;
-      default:
-        break;
-    }
-  return TS_FAILED;
+  DISPATCHER("Kernel Core Memory API");
 }
index 96572c4..1595a57 100755 (executable)
 #define TS_OK             0
 #define TS_FAILED         1
 
+/* Macros to simplify tests */
+#define DISPATCHER(TestName)    \
+  switch (Command)              \
+  {                             \
+    case TESTCMD_RUN:           \
+      return RunTest(Buffer);   \
+    case TESTCMD_TESTNAME:      \
+      strcpy(Buffer, TestName); \
+      return TS_OK;             \
+    default:                    \
+      break;                    \
+  }                             \
+  return TS_FAILED;
+
+#define FAIL(ErrorMessage) \
+  sprintf(Buffer, "%s\n", ErrorMessage); \
+  return TS_FAILED;
+
+#define FAIL_IF_NULL(GivenValue, ErrorMessage)                     if (GivenValue == NULL) { FAIL(ErrorMessage); }
+#define FAIL_IF_TRUE(GivenValue, ErrorMessage)                     if (GivenValue == TRUE) { FAIL(ErrorMessage); }
+#define FAIL_IF_FALSE(GivenValue, ErrorMessage)                    if (GivenValue == FALSE) { FAIL(ErrorMessage); }
+#define FAIL_IF_EQUAL(GivenValue, FailValue, ErrorMessage)         if (GivenValue == FailValue) { FAIL(ErrorMessage); }
+#define FAIL_IF_NOT_EQUAL(GivenValue, FailValue, ErrorMessage)     if (GivenValue != FailValue) { FAIL(ErrorMessage); }
+#define FAIL_IF_LESS_EQUAL(GivenValue, FailValue, ErrorMessage)    if (GivenValue <= FailValue) { FAIL(ErrorMessage); }
+#define FAIL_IF_GREATER_EQUAL(GivenValue, FailValue, ErrorMessage) if (GivenValue >= FailValue) { FAIL(ErrorMessage); }
+
 /*
  * Test routine prototype
  * Command - The command to process