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.

233 lines
5.4 KiB

  1. Include('types.js');
  2. Include('utils.js');
  3. var g_nThreads = 8;
  4. var g_nLoops = 1000;
  5. var g_fMsg = false;
  6. var g_DepthCounter = 0;
  7. function stress_js::ScriptMain()
  8. {
  9. PrivateData.objUtil.fnStress = stresstest;
  10. PrivateData.fnExecScript = StressRemoteExec;
  11. JSignalThreadSync('StressThreadReady');
  12. JWaitForSync('StressThreadExit', 0);
  13. }
  14. function StressRemoteExec(cmd, params)
  15. {
  16. var vRet = 'ok';
  17. switch (cmd)
  18. {
  19. case "sleep":
  20. LogMsg("SLEEPING");
  21. Sleep(10000);
  22. LogMsg("WAKING");
  23. break;
  24. case "threads":
  25. StressThreads();
  26. break;
  27. case 'ping':
  28. ping(1);
  29. break;
  30. case 'ping2':
  31. ping(2);
  32. break;
  33. case 'exec':
  34. var pid = RunLocalCommand(params,
  35. '',
  36. 'Stress Program',
  37. false,
  38. true,
  39. false);
  40. if (pid == 0)
  41. vRet = GetLastRunLocalError();
  42. else
  43. vRet = pid;
  44. break;
  45. case 'exec_noout':
  46. var pid = RunLocalCommand(params,
  47. '',
  48. 'Stress Program',
  49. false,
  50. false,
  51. false,
  52. false,
  53. false);
  54. if (pid == 0)
  55. vRet = GetLastRunLocalError();
  56. else
  57. vRet = pid;
  58. break;
  59. case 'getoutput':
  60. vRet = GetProcessOutput(params);
  61. break;
  62. case 'send':
  63. var args = params.split(',');
  64. vRet = SendToProcess(args[0], args[1], '');
  65. break;
  66. default:
  67. vRet = 'invalid command: ' + cmd;
  68. }
  69. return vRet;
  70. }
  71. function stress_js::OnProcessEvent(pid, evt, param)
  72. {
  73. NotifyScript('ProcEvent: ', pid+','+evt+','+param);
  74. }
  75. function stress_js::OnEventSourceEvent(RemoteObj, DispID)
  76. {
  77. var RC_COPYSTARTED = 1;
  78. var RC_COPYFILE = 2;
  79. var RC_PROGRESS = 3;
  80. var RC_COPYERROR = 4;
  81. var RC_COPYDONE = 5;
  82. debugger;
  83. if (g_robocopy == RemoteObj)
  84. {
  85. switch(DispID)
  86. {
  87. case RC_COPYSTARTED:
  88. case RC_COPYFILE :
  89. case RC_PROGRESS :
  90. case RC_COPYERROR :
  91. case RC_COPYDONE :
  92. break;
  93. }
  94. }
  95. }
  96. function ping(nMode)
  97. {
  98. var nEvent;
  99. var i, j;
  100. var aStrPing = new Array();
  101. var aStrWait = new Array();
  102. for(j = 0; j < g_nThreads; ++j)
  103. {
  104. ResetSync("pingtestThreadExit,pingtestThreadReady");
  105. aStrPing[j] = "ping" + j;
  106. aStrWait[j] = "wait" + j;
  107. SpawnScript('pingtest.js', aStrPing[j] + "," + aStrWait[j]);
  108. nEvent = JWaitForSync('pingtestThreadReady', 1000);
  109. if (nEvent == 0)
  110. {
  111. LogMsg("timeout on pingtest " + j);
  112. JSignalThreadSync("pingtestThreadExit");
  113. return;
  114. }
  115. }
  116. ResetSync(aStrWait.toString());
  117. for(i = 0; i < g_nLoops; ++i)
  118. {
  119. // if (i % 100 == 0)
  120. LogMsg("Signal #" + (i + 1));
  121. JSignalThreadSync(aStrPing.toString());
  122. if (nMode == 1)
  123. JWaitForMultipleSyncs(aStrWait.toString(), true, 0);
  124. else
  125. {
  126. for(j = 0; j < g_nThreads; ++j)
  127. JWaitForSync(aStrWait[j], 0);
  128. }
  129. ResetSync(aStrWait.toString());
  130. }
  131. JSignalThreadSync("pingtestThreadExit");
  132. }
  133. function StressThreads()
  134. {
  135. var nEvent;
  136. var i, j;
  137. for(j = 0; j < g_nThreads; ++j)
  138. {
  139. ResetSync("threadstestThreadExit,threadstestThreadReady");
  140. SpawnScript('threadstest.js', "stresswait,Thread#" + j);
  141. nEvent = JWaitForSync('threadstestThreadReady', 1000);
  142. if (nEvent == 0)
  143. {
  144. LogMsg("timeout on threadtest " + j);
  145. JSignalThreadSync("threadThreadExit");
  146. return;
  147. }
  148. }
  149. JSignalThreadSync("stresswait");
  150. Sleep(1000);
  151. JSignalThreadSync("threadstestThreadExit");
  152. }
  153. function JSignalThreadSync(strSigs)
  154. {
  155. if (g_fMsg)
  156. LogMsg("SIGNALLING " + strSigs);
  157. SignalThreadSync(strSigs);
  158. }
  159. function JWaitForMultipleSyncs(strSigs, fWaitAll, nTimeOut)
  160. {
  161. if (g_fMsg)
  162. LogMsg("WAITING " + strSigs);
  163. var nEvent = WaitForMultipleSyncs(strSigs, fWaitAll, nTimeOut);
  164. if (g_fMsg)
  165. {
  166. if (nEvent == 0)
  167. LogMsg("TIMEOUT");
  168. else
  169. LogMsg("RECEIVED " + strSigs.split(',')[nEvent - 1]);
  170. }
  171. return nEvent;
  172. }
  173. function JWaitForSync(strSigs, nTimeOut)
  174. {
  175. if (g_fMsg)
  176. return JWaitForMultipleSyncs(strSigs, false, nTimeOut);
  177. return WaitForSync(strSigs, nTimeOut);
  178. }
  179. function stresstest(strID)
  180. {
  181. var i;
  182. var n = ++g_DepthCounter;
  183. var x;
  184. var y;
  185. LogMsg("On entry(" + strID + "), stress test depth is " + g_DepthCounter);
  186. for(i = 0 ; i < 50; ++i)
  187. {
  188. for(x in PublicData)
  189. {
  190. if (!PublicData.__isPublicMember(x))
  191. continue;
  192. y = PublicData[x];
  193. }
  194. }
  195. LogMsg("On exit(" + strID + "), stress test depth is " + g_DepthCounter + " was " + n);
  196. --g_DepthCounter;
  197. }