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.

218 lines
5.8 KiB

  1. #include <sacstress.h>
  2. DWORD
  3. ChannelThreadVTUTF8Write(
  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. PWCHAR 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 = ChannelTypeVTUTF8;
  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 = GenerateRandomStringW(k);
  79. do {
  80. //
  81. // Write the entire string first so a test app can compare the following output
  82. //
  83. bSuccess = SacChannelVTUTF8Write(
  84. SacChannelHandle,
  85. Buffer,
  86. k * sizeof(WCHAR)
  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 = SacChannelVTUTF8Write(
  112. SacChannelHandle,
  113. Buffer,
  114. i * sizeof(WCHAR)
  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 = SacChannelVTUTF8WriteString(
  125. SacChannelHandle,
  126. L"\r\n"
  127. );
  128. if (!bSuccess) {
  129. printf("%d: Failed to print string to channel\n", ChannelThreadData->ThreadId);
  130. bContinue = FALSE;
  131. break;
  132. }
  133. }
  134. } while ( FALSE );
  135. //
  136. // Release the random string
  137. //
  138. free(Buffer);
  139. //
  140. // Close the channel
  141. //
  142. if (SacChannelClose(&SacChannelHandle)) {
  143. printf("%d: Successfully closed channel\n", ChannelThreadData->ThreadId);
  144. } else {
  145. bContinue = FALSE;
  146. printf("%d: Failed to close channel\n", ChannelThreadData->ThreadId);
  147. }
  148. }
  149. return 0;
  150. }
  151. //
  152. // Define our tests
  153. //
  154. DWORD (*ChannelTests[THREADCOUNT])(PVOID) = {
  155. ChannelThreadVTUTF8Write,
  156. ChannelThreadVTUTF8Write,
  157. ChannelThreadVTUTF8Write,
  158. ChannelThreadVTUTF8Write,
  159. ChannelThreadVTUTF8Write,
  160. ChannelThreadVTUTF8Write,
  161. ChannelThreadVTUTF8Write,
  162. ChannelThreadVTUTF8Write,
  163. ChannelThreadVTUTF8Write,
  164. ChannelThreadVTUTF8Write,
  165. ChannelThreadVTUTF8Write,
  166. ChannelThreadVTUTF8Write,
  167. ChannelThreadVTUTF8Write,
  168. ChannelThreadVTUTF8Write,
  169. ChannelThreadVTUTF8Write,
  170. ChannelThreadVTUTF8Write,
  171. };
  172. int _cdecl
  173. wmain(
  174. int argc,
  175. WCHAR **argv
  176. )
  177. {
  178. return RunStress(
  179. ChannelTests,
  180. THREADCOUNT
  181. );
  182. }