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.

204 lines
5.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1994 - 1999
  3. Module Name:
  4. client.c
  5. Abstract:
  6. NT LPC performance test used to compare with RLRPC performance.
  7. Currently limited to message I/O only, it won't do large I/O.
  8. Author:
  9. Mario Goertzel (mariogo) 29-Mar-1994
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <rpcperf.h>
  17. #include <lpctest.h>
  18. const char *USAGE = "-n test_case -n in_size -n out_size\n"
  19. " Cases:\n"
  20. " 1: data as part of message, max ~240 byte sizes\n"
  21. " 2: read/write data from client address space, sizes unlimited\n";
  22. #define MAX(a,b) ((a)>(b))?(a):(b)
  23. int __cdecl
  24. main(int argc, char **argv)
  25. {
  26. ULONG i;
  27. HANDLE portServer;
  28. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  29. ANSI_STRING ansiPortName;
  30. UNICODE_STRING unicodePortName;
  31. char pszPortName[100];
  32. NTSTATUS status;
  33. LPC_PERF_MESSAGE *pMessage, *pReplyMessage;
  34. char *BigBuffer;
  35. unsigned long ConnectInfoSize = sizeof(LPC_PERF_BIND)-sizeof(PORT_MESSAGE);
  36. ULONG RequestSize, ReplySize;
  37. ParseArgv(argc, argv);
  38. RequestSize = Options[1];
  39. ReplySize = Options[2];
  40. if ( (Options[0] < 0)
  41. || (Options[0] > 2)
  42. || (RequestSize < 0)
  43. || (ReplySize < 0) )
  44. {
  45. printf("%s: Usage:\n",
  46. USAGE,
  47. argv[0]
  48. );
  49. return 1;
  50. }
  51. /* Create Port */
  52. strcpy(pszPortName, DEFAULT_PORT_DIR);
  53. strcat(pszPortName, DEFAULT_PORT_NAME);
  54. RtlInitAnsiString(&ansiPortName, pszPortName);
  55. RtlAnsiStringToUnicodeString(&unicodePortName,
  56. &ansiPortName,
  57. TRUE);
  58. BigBuffer = malloc(MAX(RequestSize,ReplySize));
  59. pMessage = malloc(sizeof(LPC_PERF_MESSAGE));
  60. pReplyMessage = malloc(sizeof(LPC_PERF_MESSAGE));
  61. if (pMessage == 0
  62. || pReplyMessage == 0
  63. || BigBuffer == 0)
  64. {
  65. printf("Error: Malloc failed\n");
  66. return 1;
  67. }
  68. SecurityQos.EffectiveOnly = TRUE;
  69. SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  70. SecurityQos.ImpersonationLevel = SecurityImpersonation;
  71. SecurityQos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  72. pMessage->Bind.MsgType = PERF_BIND;
  73. pMessage->Bind.BufferLengthIn = RequestSize;
  74. pMessage->Bind.BufferLengthOut = ReplySize;
  75. status =
  76. NtConnectPort(&portServer,
  77. &unicodePortName,
  78. &SecurityQos,
  79. 0, // No attributes
  80. 0,
  81. 0,
  82. ((char *)pMessage + sizeof(PORT_MESSAGE)),
  83. &ConnectInfoSize);
  84. CHECK_STATUS(status, "NtConnectPort");
  85. printf("Connected to server\n");
  86. switch(Options[0])
  87. {
  88. case 1:
  89. pMessage->Lpc.u1.s1.TotalLength = (USHORT)RequestSize + sizeof(LPC_PERF_COMMON);
  90. pMessage->Lpc.u1.s1.DataLength = (USHORT)RequestSize;
  91. pMessage->Lpc.u2.ZeroInit = 0;
  92. pMessage->Packet.MsgType = PERF_REQUEST;
  93. pMessage->Packet.Buffer[0] = 'G';
  94. break;
  95. case 2:
  96. pMessage->Lpc.u1.s1.TotalLength = sizeof(LPC_PERF_BUFFER);
  97. pMessage->Lpc.u1.s1.DataLength = sizeof(LPC_PERF_BUFFER) -
  98. sizeof(PORT_MESSAGE);
  99. pMessage->Lpc.u2.ZeroInit = 0;
  100. pMessage->Lpc.u2.s2.DataInfoOffset = sizeof(LPC_PERF_COMMON);
  101. pMessage->Buffer.MsgType = PERF_READ_CLIENT_BUFFER;
  102. pMessage->Buffer.CountDataEntries = 1;
  103. pMessage->Buffer.DataEntries[0].Base = (void *)BigBuffer;
  104. pMessage->Buffer.DataEntries[0].Size = MAX(RequestSize,ReplySize);
  105. break;
  106. default:
  107. printf("Invalid Test Type: %ld\n", Options[0]);
  108. return 1;
  109. }
  110. StartTime();
  111. for(i = 0 ; i < Iterations ; i++)
  112. {
  113. status =
  114. NtRequestWaitReplyPort(portServer,
  115. (PPORT_MESSAGE)pMessage,
  116. (PPORT_MESSAGE)pReplyMessage
  117. );
  118. if (!NT_SUCCESS(status))
  119. {
  120. printf("NtRequestWaitReplyPort failed - %8lX\n",
  121. status);
  122. return status;
  123. }
  124. switch(pReplyMessage->Common.MsgType)
  125. {
  126. case PERF_REPLY:
  127. break;
  128. case PERF_SHARED_REPLY:
  129. break;
  130. case PERF_READ_SERVER_BUFFER:
  131. //
  132. // The server has already done everything!
  133. //
  134. break;
  135. default:
  136. {
  137. printf("Invalid reply message type: %ld\n",
  138. pReplyMessage->Common.MsgType);
  139. i = Iterations;
  140. }
  141. }
  142. }
  143. EndTime("for LPC calls");
  144. pMessage->Common.MsgType = PERF_REQUEST;
  145. pMessage->Packet.Buffer[0] = 'X';
  146. pMessage->Lpc.u1.s1.TotalLength = 1 + sizeof(LPC_PERF_COMMON);
  147. pMessage->Lpc.u1.s1.DataLength = 1 + sizeof(LPC_PERF_COMMON) - sizeof(PORT_MESSAGE);
  148. pMessage->Lpc.u2.ZeroInit = 0;
  149. printf("Sending shutdown\n");
  150. status =
  151. NtRequestWaitReplyPort(portServer,
  152. (PPORT_MESSAGE)pMessage,
  153. (PPORT_MESSAGE)pReplyMessage
  154. );
  155. CHECK_STATUS(status, "NtRequestWaitRequestPort");
  156. if (pReplyMessage->Packet.Buffer[0] != 'Z')
  157. {
  158. printf("Server failed to shutdown normally\n");
  159. }
  160. return 0;
  161. }