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.

284 lines
7.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1994 - 1999
  3. Module Name:
  4. client.c
  5. Abstract:
  6. Client of post message performance test.
  7. Author:
  8. Mario Goertzel (mariogo) 31-Mar-1994
  9. Revision History:
  10. --*/
  11. #include <rpcperf.h>
  12. #include <pmsgtest.h>
  13. const char *USAGE ="-n case -n size -i iterations\n"
  14. " Cases:\n"
  15. " 1: Oneway PostMessage/GetMessage (in process)\n"
  16. " 2: Oneway PostMessage/GetMessage (process to process)\n"
  17. " 3: Oneway PostMessage/MsgWaitForMultipleObjects (in process)\n"
  18. " 4: Oneway PostMessage/MsgWaitForMultipleObjects (process to process)\n"
  19. " 5: SendMessage/GetMessage (in process)\n"
  20. " 6: SendMessage/GetMessage (process to process)\n"
  21. " 7: Post/GetMessage and WSO (in process)\n"
  22. " 8: Post/GetMessage and WSO (process to process)\n"
  23. " 9: PostMessage/MsgWMO and WSO (in process)\n"
  24. " 10: PostMessage/MsgWMO and WSO (process to process)\n"
  25. " 11: SetEvent/MsgWMO and WSO (in process)\n"
  26. " 12: SetEvent/MsgWMO and WSO (process to process)\n"
  27. " 13: PostMessage (WM_COPYDATA of size) and WSO\n";
  28. int __cdecl
  29. main(int argc, char **argv)
  30. {
  31. HWND hwndServer;
  32. HANDLE hReplyEvent;
  33. HANDLE hRequestEvent;
  34. ULONG i;
  35. ULONG lTestCase;
  36. ULONG lSize;
  37. char *string;
  38. ULONG Status;
  39. ParseArgv(argc, argv);
  40. if ( (Options[0] < 0) || (Options[0] > 13) )
  41. {
  42. printf("Usage: %s : %s\n",
  43. argv[0],
  44. USAGE);
  45. return 1;
  46. }
  47. lTestCase = Options[0];
  48. lSize = Options[1];
  49. if (lSize < 1) lSize = 100;
  50. switch(lTestCase)
  51. {
  52. case 1:
  53. string = "PostMessage/GetMessage (oneway, in-process)";
  54. break;
  55. case 2:
  56. string = "PostMessage/GetMessage (oneway, out-of-process)";
  57. break;
  58. case 3:
  59. string = "PostMessage/MsgWaitForMultipleObjects (oneway, in-process)";
  60. break;
  61. case 4:
  62. string = "PostMessage/MsgWaitForMultipleObjects (oneway, out-of-process)";
  63. break;
  64. case 5:
  65. string = "SendMessage/GetMessage (in-process)";
  66. break;
  67. case 6:
  68. string = "SendMessage/GetMessage (out-of-process)";
  69. break;
  70. case 7:
  71. string = "PostMessage/GetMessage (in-process)";
  72. break;
  73. case 8:
  74. string = "PostMessage/GetMessage (out-of-process)";
  75. break;
  76. case 9:
  77. string = "PostMessage/MsgWaitForMultipleObjects (in-process)";
  78. break;
  79. case 10:
  80. string = "PostMessage/MsgWaitForMultipleObjects (out-of-process)";
  81. break;
  82. case 11:
  83. string = "SetEvent/MsgWaitForMultipleObjects (in-process)";
  84. break;
  85. case 12:
  86. string = "SetEvent/MsgWaitForMultipleObjects (out-of-process)";
  87. break;
  88. case 13:
  89. string = "PostMessage (WM_COPYDATA) WSO reply";
  90. break;
  91. }
  92. hwndServer = FindWindow(CLASS, TITLE);
  93. if (hwndServer == 0)
  94. ApiError("FindWindow", GetLastError());
  95. hReplyEvent = OpenEvent(EVENT_ALL_ACCESS,
  96. FALSE,
  97. REPLY_EVENT);
  98. if (hReplyEvent == 0)
  99. ApiError("OpenEvent", GetLastError());
  100. hRequestEvent = OpenEvent(EVENT_ALL_ACCESS,
  101. FALSE,
  102. REQUEST_EVENT);
  103. if (hRequestEvent == 0)
  104. ApiError("OpenEvent", GetLastError());
  105. switch(lTestCase)
  106. {
  107. case 1:
  108. case 3:
  109. case 5:
  110. case 7:
  111. case 9:
  112. case 11:
  113. {
  114. StartTime();
  115. if ( (PostMessage(hwndServer, MSG_PERF_MESSAGE,
  116. lTestCase, Iterations)) == FALSE)
  117. {
  118. ApiError("PostMessage", GetLastError());
  119. }
  120. // The server process completes the whole test
  121. if (WaitForSingleObject(hReplyEvent, INFINITE) != STATUS_WAIT_0)
  122. {
  123. ApiError("WaitForSingleObject", GetLastError());
  124. }
  125. break;
  126. }
  127. case 2:
  128. case 4:
  129. case 8:
  130. case 10:
  131. {
  132. // Oneway and twoway PostMessages.
  133. StartTime();
  134. for(i = Iterations; i; i--)
  135. {
  136. if ( (PostMessage(hwndServer, MSG_PERF_MESSAGE,
  137. lTestCase, i)) == FALSE)
  138. {
  139. ApiError("PostMessage", GetLastError());
  140. }
  141. if (lTestCase > 4)
  142. {
  143. // Twoway tests wait for reply event
  144. if (WaitForSingleObject(hReplyEvent, INFINITE) !=
  145. STATUS_WAIT_0)
  146. {
  147. ApiError("WaitForSingleObject", GetLastError());
  148. }
  149. }
  150. }
  151. // Wait for all the messages to be processed
  152. if (lTestCase <= 4)
  153. {
  154. if (WaitForSingleObject(hReplyEvent, INFINITE)
  155. != STATUS_WAIT_0)
  156. {
  157. ApiError("WaitForSingleObject", GetLastError());
  158. }
  159. }
  160. break;
  161. }
  162. case 6:
  163. {
  164. // SendMessage()
  165. StartTime();
  166. for(i = Iterations; i; i--)
  167. {
  168. if ( (SendMessage(hwndServer, MSG_PERF_MESSAGE,
  169. lTestCase, i)) != 69)
  170. {
  171. ApiError("SendMessage", GetLastError());
  172. }
  173. }
  174. // No need to wait for all the messages to be processed
  175. break;
  176. }
  177. case 12:
  178. {
  179. // SetEvent/MsgWaitForMultipleObjects
  180. PostMessage(hwndServer, MSG_PERF_MESSAGE, lTestCase, 0);
  181. Sleep(100);
  182. StartTime();
  183. for(i = Iterations; i; i--)
  184. {
  185. SetEvent(hRequestEvent);
  186. WaitForSingleObject(hReplyEvent, INFINITE);
  187. }
  188. break;
  189. }
  190. case 13:
  191. {
  192. // PostMessage (WM_COPYDATA) and SetEvent reply
  193. COPYDATASTRUCT Data;
  194. Data.dwData = 5055;
  195. Data.cbData = lSize;
  196. Data.lpData = malloc(lSize);
  197. ASSERT(0);
  198. // This doesn't build for Win64. I don't think this test
  199. // is relevant, so I'll just comment it out to make it build
  200. /*
  201. StartTime();
  202. for(i = Iterations; i; i--)
  203. {
  204. Status =
  205. SendMessage(hwndServer,
  206. WM_COPYDATA,
  207. hwndServer,
  208. (long)&Data);
  209. if (Status == FALSE)
  210. ASSERT(0);
  211. }
  212. */
  213. }
  214. }
  215. EndTime(string);
  216. if (PostMessage(hwndServer, WM_DESTROY, 0, 0) == FALSE)
  217. ApiError("PostMessage", GetLastError());
  218. return 0;
  219. }