Leaked source code of windows server 2003
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.

216 lines
5.7 KiB

  1. #include <sacstress.h>
  2. DWORD
  3. ChannelThreadRawWrite(
  4. PVOID Data
  5. )
  6. {
  7. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  8. SAC_CHANNEL_HANDLE SacChannelHandle;
  9. PCHANNEL_THREAD_DATA ChannelThreadData;
  10. DWORD Status;
  11. ULONG i;
  12. PUCHAR Buffer;
  13. BOOL bContinue;
  14. ULONG k;
  15. PWSTR Name;
  16. PWSTR Description;
  17. BOOL bSuccess;
  18. ChannelThreadData = (PCHANNEL_THREAD_DATA)Data;
  19. //
  20. // Perform thread work
  21. //
  22. bContinue = TRUE;
  23. while (bContinue) {
  24. //
  25. // See if we need to exit the thread
  26. //
  27. Status = WaitForSingleObject(
  28. ChannelThreadData->ExitEvent,
  29. THREAD_WAIT_TIMEOUT
  30. );
  31. if (Status != WAIT_TIMEOUT) {
  32. bContinue = FALSE;
  33. continue;
  34. }
  35. //
  36. // Configure the new channel
  37. //
  38. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  39. //
  40. // generate a random name and description
  41. //
  42. // Note: we make the maxlength > than the allowed to test the driver, etc.
  43. //
  44. Name = GenerateRandomStringW(GET_RANDOM_NUMBER(SAC_MAX_CHANNEL_NAME_LENGTH*2));
  45. Description = GenerateRandomStringW(GET_RANDOM_NUMBER(SAC_MAX_CHANNEL_DESCRIPTION_LENGTH*2));
  46. Attributes.Type = ChannelTypeRaw;
  47. Attributes.Name = Name;
  48. Attributes.Description = Description;
  49. Attributes.Flags = 0;
  50. Attributes.CloseEvent = NULL;
  51. Attributes.HasNewDataEvent = NULL;
  52. Attributes.ApplicationType = NULL;
  53. //
  54. // Open the channel
  55. //
  56. bSuccess = SacChannelOpen(
  57. &SacChannelHandle,
  58. &Attributes
  59. );
  60. //
  61. // We are done with the random strings
  62. //
  63. free(Name);
  64. free(Description);
  65. if (bSuccess) {
  66. printf("%d: Successfully opened new channel\n", ChannelThreadData->ThreadId);
  67. } else {
  68. printf("%d: Failed to open new channel\n", ChannelThreadData->ThreadId);
  69. continue;
  70. }
  71. //
  72. // randomly determine how long we'll loop
  73. //
  74. k = GET_RANDOM_NUMBER(MAX_ITER_COUNT);
  75. //
  76. // Generate a random string of random length to send
  77. //
  78. Buffer = GenerateRandomStringA(k);
  79. do {
  80. //
  81. // Write the entire string first so a test app can compare the following output
  82. //
  83. bSuccess = SacChannelRawWrite(
  84. SacChannelHandle,
  85. Buffer,
  86. k * sizeof(UCHAR)
  87. );
  88. if (!bSuccess) {
  89. printf("%d: Failed to print string to channel\n", ChannelThreadData->ThreadId);
  90. bContinue = FALSE;
  91. break;
  92. }
  93. //
  94. // Loop and write
  95. //
  96. for (i = 0; i < k; i++) {
  97. //
  98. // See if we need to exit the thread
  99. //
  100. Status = WaitForSingleObject(
  101. ChannelThreadData->ExitEvent,
  102. THREAD_WAIT_TIMEOUT
  103. );
  104. if (Status != WAIT_TIMEOUT) {
  105. bContinue = FALSE;
  106. break;
  107. }
  108. //
  109. // Write to the channel
  110. //
  111. bSuccess = SacChannelRawWrite(
  112. SacChannelHandle,
  113. Buffer,
  114. i * sizeof(UCHAR)
  115. );
  116. if (!bSuccess) {
  117. printf("%d: Failed to print string to channel\n", ChannelThreadData->ThreadId);
  118. bContinue = FALSE;
  119. break;
  120. }
  121. //
  122. // Write to the channel
  123. //
  124. bSuccess = SacChannelRawWrite(
  125. SacChannelHandle,
  126. "\r\n",
  127. strlen("\r\n") * sizeof(UCHAR)
  128. );
  129. if (!bSuccess) {
  130. printf("%d: Failed to print string to channel\n", ChannelThreadData->ThreadId);
  131. bContinue = FALSE;
  132. break;
  133. }
  134. }
  135. } while ( FALSE );
  136. //
  137. // Release the random string
  138. //
  139. free(Buffer);
  140. //
  141. // Close the channel
  142. //
  143. if (SacChannelClose(&SacChannelHandle)) {
  144. printf("%d: Successfully closed channel\n", ChannelThreadData->ThreadId);
  145. } else {
  146. bContinue = FALSE;
  147. printf("%d: Failed to close channel\n", ChannelThreadData->ThreadId);
  148. }
  149. }
  150. return 0;
  151. }
  152. DWORD (*ChannelTests[THREADCOUNT])(PVOID) = {
  153. ChannelThreadRawWrite,
  154. ChannelThreadRawWrite,
  155. ChannelThreadRawWrite,
  156. ChannelThreadRawWrite,
  157. ChannelThreadRawWrite,
  158. ChannelThreadRawWrite,
  159. ChannelThreadRawWrite,
  160. ChannelThreadRawWrite,
  161. ChannelThreadRawWrite,
  162. ChannelThreadRawWrite,
  163. ChannelThreadRawWrite,
  164. ChannelThreadRawWrite,
  165. ChannelThreadRawWrite,
  166. ChannelThreadRawWrite,
  167. ChannelThreadRawWrite,
  168. ChannelThreadRawWrite,
  169. };
  170. int _cdecl
  171. wmain(
  172. int argc,
  173. WCHAR **argv
  174. )
  175. {
  176. return RunStress(
  177. ChannelTests,
  178. THREADCOUNT
  179. );
  180. }