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.

301 lines
8.4 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: testvars.cxx
  4. //
  5. // Synopsis: source code for Interface Marshaling stress test
  6. // variations.
  7. //
  8. // History: 21-Aug-95 Rickhi Created
  9. //
  10. //--------------------------------------------------------------------
  11. #include <smarshal.hxx>
  12. //+-------------------------------------------------------------------
  13. //
  14. // Private Function ProtoTypes:
  15. //
  16. //--------------------------------------------------------------------
  17. BOOL SingleThreadOps(ULONG cThreads, ULONG cReps, DWORD dwFlags);
  18. BOOL ThreadPairOps(ULONG cThreadPairs, ULONG cReps,
  19. DWORD dwServerFlags, DWORD dwClientFlags);
  20. //+-------------------------------------------------------------------
  21. //
  22. // Function: TestVar1
  23. //
  24. // Synopsis: Multiple Operations on the Same Thread.
  25. //
  26. // History: 21-Aug-95 Rickhi Created
  27. //
  28. //--------------------------------------------------------------------
  29. BOOL TestVar1(void)
  30. {
  31. MSGOUT("TestStart: TestLevel1\n");
  32. ULONG cThreads = gicThreads;
  33. ULONG cReps = gicReps;
  34. DWORD dwOps = 0;
  35. BOOL fRes;
  36. // VAR1: test Marshal + ReleaseMarshalData
  37. dwOps = giThreadModel | OPF_MARSHAL | OPF_RELEASEMARSHALDATA;
  38. fRes = SingleThreadOps(cThreads, cReps, dwOps);
  39. CHKTESTRESULT(fRes, "TestVar1");
  40. // VAR2: test Marshal + Unmarshal + Release
  41. dwOps = giThreadModel | OPF_MARSHAL | OPF_UNMARSHAL | OPF_RELEASE;
  42. fRes = SingleThreadOps(cThreads, cReps, dwOps);
  43. CHKTESTRESULT(fRes, "TestVar2");
  44. // VAR3: test Marshal + Disconnect
  45. dwOps = giThreadModel | OPF_MARSHAL | OPF_DISCONNECT;
  46. fRes = SingleThreadOps(cThreads, cReps, dwOps);
  47. CHKTESTRESULT(fRes, "TestVar3");
  48. CHKTESTRESULT(fRes, "TestLevel1");
  49. return fRes;
  50. }
  51. //+-------------------------------------------------------------------
  52. //
  53. // Function: SingleThreadOps
  54. //
  55. // Synopsis: Perform Operations on the Same Thread.
  56. //
  57. // History: 21-Aug-95 Rickhi Created
  58. //
  59. //--------------------------------------------------------------------
  60. BOOL SingleThreadOps(ULONG cThreads, ULONG cReps, DWORD dwFlags)
  61. {
  62. BOOL fRes = TRUE;
  63. MSGOUT("SingleThreadOps Start\n");
  64. // CODEWORK: multiple interfaces
  65. ULONG cIPs = 1;
  66. EXECPARAMS *pEP[20]; // can launch up to 20 threads at once
  67. for (ULONG i=0; i<cThreads; i++)
  68. {
  69. // build an execution parameter block
  70. pEP[i] = CreateExecParam(cIPs);
  71. // fill in the execution parameter block. we dont need events
  72. // to synchronize the repetitions since all operations are done
  73. // on the same thread.
  74. FillExecParam(pEP[i],
  75. dwFlags, // dwFlags (operations to perform)
  76. cReps, // cReps
  77. NULL, // hEventRepStart
  78. NULL, // hEventRepDone
  79. GetEvent(), // hEventThreadStart
  80. GetEvent()); // hEventThreadDone
  81. // fill in the INTERFACEPARAMSs
  82. for (ULONG j=0; j<cIPs; j++)
  83. {
  84. INTERFACEPARAMS *pIP = &(pEP[i]->aIP[j]);
  85. FillInterfaceParam(pIP,
  86. IID_IUnknown, // iid to operate on
  87. GetInterface(), // interface pointer to operate on
  88. GetStream(), // stream to use
  89. NULL, // per interface start event
  90. NULL); // per interface done event
  91. }
  92. }
  93. // Execute all the command blocks simultaneously
  94. fRes = GenericExecute(cThreads, pEP);
  95. GenericCleanup(cThreads, pEP);
  96. CHKTESTRESULT(fRes, "SingleThreadOps");
  97. return fRes;
  98. }
  99. //+-------------------------------------------------------------------
  100. //
  101. // Function: TestVar2
  102. //
  103. // Synopsis: Operations on Thread Pairs (1 server, 1 client)
  104. //
  105. // History: 21-Aug-95 Rickhi Created
  106. //
  107. //--------------------------------------------------------------------
  108. BOOL TestVar2(void)
  109. {
  110. MSGOUT("TestStart: TestLevel2\n");
  111. ULONG cThreads = gicThreads;
  112. ULONG cReps = gicReps;
  113. DWORD dwOps = 0;
  114. BOOL fRes;
  115. // VAR1: test Marshal on Server, Unmarshal + Release on Client.
  116. DWORD dwSrvOps = giThreadModel | OPF_MARSHAL;
  117. DWORD dwCliOps = giThreadModel | OPF_UNMARSHAL | OPF_RELEASE;
  118. fRes = ThreadPairOps(cThreads, cReps, dwSrvOps, dwCliOps);
  119. CHKTESTRESULT(fRes, "TestVar1");
  120. // VAR2: test Marshal on Server, RMD on Client.
  121. #if 0
  122. dwSrvOps = giThreadModel | OPF_MARSHAL;
  123. dwCliOps = giThreadModel | OPF_RELEASEMARSHALDATA;
  124. fRes = ThreadPairOps(cThreads, cReps, dwSrvOps, dwCliOps);
  125. CHKTESTRESULT(fRes, "TestVar1");
  126. #endif
  127. CHKTESTRESULT(fRes, "TestLevel2");
  128. return fRes;
  129. }
  130. //+-------------------------------------------------------------------
  131. //
  132. // Function: ThreadPairOps
  133. //
  134. // Synopsis: Perform Operations on two synchronized threads.
  135. //
  136. // History: 21-Aug-95 Rickhi Created
  137. //
  138. //--------------------------------------------------------------------
  139. BOOL ThreadPairOps(ULONG cThreadPairs, ULONG cReps,
  140. DWORD dwServerFlags, DWORD dwClientFlags)
  141. {
  142. BOOL fRes = TRUE;
  143. MSGOUT("ThreadPairOps Start\n");
  144. // CODEWORK: multiple interfaces
  145. ULONG cIPs = 1;
  146. EXECPARAMS *pEP[20]; // can launch up to 20 threads at once
  147. for (ULONG i=0; i<cThreadPairs * 2; i+=2)
  148. {
  149. // build execution parameter blocks for the server and client threads.
  150. EXECPARAMS *pEPSrv = CreateExecParam(cIPs);
  151. EXECPARAMS *pEPCli = CreateExecParam(cIPs);
  152. pEP[i] = pEPSrv;
  153. pEP[i+1] = pEPCli;
  154. // fill in the server execution parameter block.
  155. FillExecParam(pEPSrv,
  156. dwServerFlags, // dwFlags (operations to perform)
  157. cReps, // cReps
  158. GetEvent(), // hEventRepStart
  159. GetEvent(), // hEventRepDone
  160. GetEvent(), // hEventThreadStart
  161. GetEvent()); // hEventThreadDone
  162. // we need to kick the hEventRepStart in order to get the ball rolling,
  163. // since the server thread will be waiting on it.
  164. SignalEvent(pEPSrv->hEventRepStart);
  165. // client waits for the server to complete his first repetition
  166. // before starting. Server waits for the client to complete his
  167. // first repetition before starting the next iteration.
  168. FillExecParam(pEPCli,
  169. dwClientFlags, // dwFlags (operations to perform)
  170. cReps, // cReps
  171. pEPSrv->hEventRepDone, // hEventRepStart
  172. pEPSrv->hEventRepStart, // hEventRepDone
  173. GetEvent(), // hEventThreadStart
  174. GetEvent()); // hEventThreadDone
  175. // fill in the INTERFACEPARAMSs
  176. // CODEWORK: when multiple interfaces, will need to use events.
  177. for (ULONG j=0; j<cIPs; j++)
  178. {
  179. INTERFACEPARAMS *pIPSrv = &(pEPSrv->aIP[j]);
  180. INTERFACEPARAMS *pIPCli = &(pEPCli->aIP[j]);
  181. FillInterfaceParam(pIPSrv,
  182. IID_IUnknown, // iid to operate on
  183. GetInterface(), // interface pointer to operate on
  184. GetStream(), // stream to use
  185. NULL, // per interface start event
  186. NULL); // per interface done event
  187. // AddRef the stream pointer since both the client and server
  188. // will hold pointers to it.
  189. pIPSrv->pStm->AddRef();
  190. FillInterfaceParam(pIPCli,
  191. IID_IUnknown, // iid to operate on
  192. NULL, // interface pointer to operate on
  193. pIPSrv->pStm, // use same stream as the server
  194. NULL, // per interface start event
  195. NULL); // per interface done event
  196. }
  197. }
  198. // Execute all the command blocks simultaneously
  199. fRes = GenericExecute(cThreadPairs * 2, pEP);
  200. // cleanup all the command blocks. We need to NULL out one copy of
  201. // those events that are shared between two command blocks.
  202. for (i=0; i<cThreadPairs * 2; i+=2)
  203. {
  204. EXECPARAMS *pEPCli = pEP[i+1];
  205. pEPCli->hEventRepStart = NULL;
  206. pEPCli->hEventRepDone = NULL;
  207. for (ULONG j=0; j<cIPs; j++)
  208. {
  209. INTERFACEPARAMS *pIPCli = &(pEPCli->aIP[j]);
  210. pIPCli->hEventStart = NULL;
  211. pIPCli->hEventDone = NULL;
  212. }
  213. }
  214. GenericCleanup(cThreadPairs * 2, pEP);
  215. CHKTESTRESULT(fRes, "ThreadPairOps");
  216. return fRes;
  217. }
  218. //+-------------------------------------------------------------------
  219. //
  220. // Function: TestLevel3
  221. //
  222. // Synopsis: Operations on Thread Pools (1 server, n clients)
  223. //
  224. // History: 21-Aug-95 Rickhi Created
  225. //
  226. //--------------------------------------------------------------------
  227. BOOL TestLevel3(void)
  228. {
  229. BOOL fRes = TRUE;
  230. MSGOUT("TestStart: TestLevel3\n");
  231. // build a command block
  232. // launch a thread to run the command block
  233. CHKTESTRESULT(fRes, "TestLevel3");
  234. return fRes;
  235. }