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.

211 lines
3.9 KiB

  1. #include <sacstress.h>
  2. PWSTR
  3. GenerateRandomStringW(
  4. IN ULONG Length
  5. )
  6. /*++
  7. Routine Description:
  8. This routine generates a random alpha string of Length.
  9. Note: caller is responsible for freeing the allocated random string
  10. Arguments:
  11. Length - the length of the new string
  12. Return Value:
  13. The random string
  14. --*/
  15. {
  16. ULONG i;
  17. PWSTR String;
  18. ULONG Size;
  19. //
  20. // Determine the byte count
  21. //
  22. Size = (Length + 1) * sizeof(WCHAR);
  23. //
  24. // allocate and init the random string
  25. //
  26. String = malloc(Size);
  27. if (String == NULL) {
  28. return String;
  29. }
  30. RtlZeroMemory(String, Size);
  31. //
  32. // Generate our random string
  33. //
  34. for (i = 0; i < Length; i++) {
  35. String[i] = (WCHAR)('A' + GET_RANDOM_NUMBER(26));
  36. }
  37. return String;
  38. }
  39. PSTR
  40. GenerateRandomStringA(
  41. IN ULONG Length
  42. )
  43. /*++
  44. Routine Description:
  45. This routine generates a random alpha string of Length.
  46. Note: caller is responsible for freeing the allocated random string
  47. Arguments:
  48. Length - the length of the new string
  49. Return Value:
  50. The random string
  51. --*/
  52. {
  53. ULONG i;
  54. PSTR String;
  55. ULONG Size;
  56. //
  57. // Determine the byte count
  58. //
  59. Size = (Length + 1) * sizeof(UCHAR);
  60. //
  61. // allocate and init the random string
  62. //
  63. String = malloc(Size);
  64. if (String == NULL) {
  65. return String;
  66. }
  67. RtlZeroMemory(String, Size);
  68. //
  69. // Generate our random string
  70. //
  71. for (i = 0; i < Length; i++) {
  72. String[i] = (UCHAR)('A' + GET_RANDOM_NUMBER(26));
  73. }
  74. return String;
  75. }
  76. int
  77. RunStress(
  78. IN CHANNEL_STRESS_THREAD *ChannelTests,
  79. IN ULONG ChannelTestCount
  80. )
  81. /*++
  82. Routine Description:
  83. This routine runs ChannelTestCount threads which apply stress.
  84. Arguments:
  85. ChannelTests - function pointers to the stress threads
  86. ChannelTestCount - # of stress threads
  87. Return Value:
  88. status
  89. --*/
  90. {
  91. HANDLE Channel[THREADCOUNT];
  92. CHANNEL_THREAD_DATA ChannelData[THREADCOUNT];
  93. HANDLE ExitEvent;
  94. ULONG i;
  95. //
  96. // Create the thread exit event
  97. //
  98. ExitEvent = CreateEvent(
  99. NULL, // no security attributes
  100. TRUE, // manual-reset event
  101. FALSE, // initial state is signaled
  102. NULL // object name
  103. );
  104. if (ExitEvent == NULL) {
  105. return 1;
  106. }
  107. //
  108. // Randomize
  109. //
  110. srand( (unsigned)time( NULL ) );
  111. //
  112. // create the worker threads
  113. //
  114. for (i = 0; i < THREADCOUNT; i++) {
  115. //
  116. // populate the thread data structure
  117. //
  118. ChannelData[i].ThreadId = i;
  119. ChannelData[i].ExitEvent = ExitEvent;
  120. //
  121. // create the thread
  122. //
  123. Channel[i] = CreateThread(
  124. NULL,
  125. 0,
  126. ChannelTests[i],
  127. &(ChannelData[i]),
  128. 0,
  129. NULL
  130. );
  131. if (Channel[i] == NULL) {
  132. goto cleanup;
  133. }
  134. }
  135. //
  136. // wait for local user to end the stress
  137. //
  138. getc(stdin);
  139. cleanup:
  140. SetEvent(ExitEvent);
  141. WaitForMultipleObjects(
  142. THREADCOUNT,
  143. Channel,
  144. TRUE,
  145. INFINITE
  146. );
  147. for (i = 0; i < THREADCOUNT; i++) {
  148. CloseHandle(Channel[i]);
  149. }
  150. return 0;
  151. }