Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tstpoint.c
  5. Abstract:
  6. Implementation of cluster test points
  7. Author:
  8. John Vert (jvert) 11/25/1996
  9. Revision History:
  10. --*/
  11. #define CLUSTER_TESTPOINT 1
  12. #include "windows.h"
  13. #include "stdlib.h"
  14. #include "stdio.h"
  15. #include "string.h"
  16. #include "tstpoint.h"
  17. VOID
  18. Usage(
  19. VOID
  20. )
  21. {
  22. fprintf(stderr,"tstpoint [dump|N] [TRIGGER [ACTION]]\n");
  23. fprintf(stderr," dump - dumps all the testpoints\n");
  24. fprintf(stderr," N - testpoint number\n");
  25. fprintf(stderr," TRIGGER - 'never' disable testpoint\n");
  26. fprintf(stderr," 'always' enable testpoint\n");
  27. fprintf(stderr," 'once' enable testpoint for single shot\n");
  28. fprintf(stderr," 'target X' enable testpoint once every X calls\n");
  29. fprintf(stderr," ACTION - 'true' return TRUE\n");
  30. fprintf(stderr," 'exit' terminate process\n");
  31. fprintf(stderr," 'break' break to debugger\n");
  32. exit(0);
  33. }
  34. PTESTPOINT_ENTRY
  35. GetTestpoints(
  36. VOID
  37. )
  38. {
  39. HANDLE FileMapping;
  40. PTESTPOINT_ENTRY TestArray;
  41. DWORD Status;
  42. FileMapping = OpenFileMappingW(FILE_MAP_READ | FILE_MAP_WRITE,
  43. FALSE,
  44. L"Cluster_Testpoints");
  45. if (FileMapping == NULL) {
  46. Status = GetLastError();
  47. fprintf(stderr, "Testpoint filemapping could not be opened, error %d\n",Status);
  48. if (Status == ERROR_FILE_NOT_FOUND) {
  49. fprintf(stderr, "Make sure the testpoint-enabled cluster service is running\n");
  50. }
  51. exit(Status);
  52. }
  53. TestArray = MapViewOfFile(FileMapping,
  54. FILE_MAP_READ | FILE_MAP_WRITE,
  55. 0,0,
  56. 0);
  57. if (TestArray == NULL) {
  58. Status = GetLastError();
  59. fprintf(stderr, "Testpoint filemapping could not be mapped, error %d\n", Status);
  60. exit(Status);
  61. }
  62. CloseHandle(FileMapping);
  63. return(TestArray);
  64. }
  65. VOID
  66. DumpTestpoint(
  67. IN PTESTPOINT_ENTRY Entry
  68. )
  69. {
  70. PCHAR Trigger;
  71. printf("%ws ", Entry->TestPointName);
  72. switch (Entry->Trigger) {
  73. case TestTriggerNever:
  74. printf("disabled ");
  75. break;
  76. case TestTriggerAlways:
  77. printf("enabled permanently ");
  78. break;
  79. case TestTriggerOnce:
  80. printf("enabled once ");
  81. break;
  82. case TestTriggerTargetCount:
  83. printf("enabled on hit %d (currently %d) ",
  84. Entry->TargetCount,
  85. Entry->HitCount);
  86. break;
  87. default:
  88. printf("unknown trigger %d ", Entry->Trigger);
  89. break;
  90. }
  91. switch (Entry->Action) {
  92. case TestActionTrue:
  93. printf("default action ");
  94. break;
  95. case TestActionExit:
  96. printf("exit process ");
  97. break;
  98. case TestActionDebugBreak:
  99. printf("break to debugger ");
  100. break;
  101. default:
  102. printf("unknown action %d ", Entry->Trigger);
  103. break;
  104. }
  105. printf("\n");
  106. }
  107. int
  108. _cdecl
  109. main (argc, argv)
  110. int argc;
  111. char *argv[];
  112. {
  113. DWORD Number;
  114. PTESTPOINT_ENTRY EntryArray;
  115. TESTPOINT_ACTION Action;
  116. TESTPOINT_TRIGGER Trigger;
  117. PCHAR *Arg;
  118. DWORD ArgsLeft;
  119. int i;
  120. ArgsLeft = argc-1;
  121. if (ArgsLeft == 0) {
  122. Usage();
  123. }
  124. //
  125. // Open the file mapping to get at the testpoint entries
  126. //
  127. EntryArray = GetTestpoints();
  128. if (!lstrcmpi(argv[1], "dump"))
  129. {
  130. for (i=0; i<TestpointMax; i++)
  131. {
  132. printf("Testpoint %d ",i);
  133. DumpTestpoint(&EntryArray[i]);
  134. }
  135. return(0);
  136. }
  137. //
  138. // First argument is the testpoint number, make sure it is in range.
  139. //
  140. Number = atoi(argv[1]);
  141. if (Number >= TestpointMax) {
  142. fprintf(stderr,
  143. "testpoint %d is beyond maximum %d\n",
  144. Number,
  145. TestpointMax-1);
  146. exit(1);
  147. }
  148. --ArgsLeft;
  149. //
  150. // Just print out the current state of the testpoint
  151. //
  152. printf("Testpoint %d\n",Number);
  153. printf(" Current state: ");
  154. DumpTestpoint(&EntryArray[Number]);
  155. if (ArgsLeft == 0) {
  156. //
  157. // No change in the testpoint state, just exit.
  158. //
  159. exit(0);
  160. }
  161. Action = TestActionTrue;
  162. Arg = &argv[2];
  163. --ArgsLeft;
  164. if (_stricmp(*Arg, "never") == 0) {
  165. Trigger = TestTriggerNever;
  166. } else if (_stricmp(*Arg, "always") == 0) {
  167. Trigger = TestTriggerAlways;
  168. } else if (_stricmp(*Arg, "once") == 0) {
  169. Trigger = TestTriggerOnce;
  170. } else if (_stricmp(*Arg, "target") == 0) {
  171. if (ArgsLeft == 0) {
  172. Usage();
  173. }
  174. Trigger = TestTriggerTargetCount;
  175. EntryArray[Number].TargetCount = atoi(*(++Arg));
  176. --ArgsLeft;
  177. } else {
  178. Usage();
  179. }
  180. ++Arg;
  181. if (ArgsLeft > 0) {
  182. if (_stricmp(*Arg, "exit") == 0) {
  183. Action = TestActionExit;
  184. } else if (_stricmp(*Arg, "break") == 0) {
  185. Action = TestActionDebugBreak;
  186. } else if (_stricmp(*Arg, "true") == 0) {
  187. Action = TestActionTrue;
  188. } else {
  189. Usage();
  190. }
  191. --ArgsLeft;
  192. ++Arg;
  193. }
  194. EntryArray[Number].Action = Action;
  195. EntryArray[Number].Trigger = Trigger;
  196. printf(" New state: ");
  197. DumpTestpoint(&EntryArray[Number]);
  198. return(0);
  199. }