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.

427 lines
13 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_rpc.cxx
  7. //
  8. // Contents: Rpc Method Invocation tests
  9. //
  10. // Classes: CRpcTest
  11. //
  12. // History: 1-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_rpc.hxx>
  18. #include <oletest.hxx>
  19. #include <tracelog.hxx>
  20. TCHAR *CRpcTest::Name ()
  21. {
  22. return TEXT("RpcTest");
  23. }
  24. SCODE CRpcTest::Setup (CTestInput *pInput)
  25. {
  26. CTestBase::Setup(pInput);
  27. SCODE sc = pInput->GetGUID(&m_ClsID, Name(), TEXT("Clsid_Local"));
  28. if (FAILED(sc))
  29. {
  30. Log (TEXT("Setup - GetClassID failed."), sc);
  31. return sc;
  32. }
  33. // get flag indicating whether to keep all values or
  34. // only average values.
  35. TCHAR szAverage[5];
  36. pInput->GetConfigString(Name(), TEXT("Average"), TEXT("Y"),
  37. szAverage, sizeof(szAverage)/sizeof(TCHAR));
  38. if (szAverage[0] == 'n' || szAverage[0] == 'N')
  39. m_fAverage = FALSE;
  40. else
  41. m_fAverage = TRUE;
  42. // get iteration count
  43. if (m_fAverage)
  44. m_ulIterations = pInput->GetRealIterations(Name());
  45. else
  46. m_ulIterations = pInput->GetIterations(Name());
  47. // initialize timing arrays
  48. INIT_RESULTS(m_ulVoidTime);
  49. INIT_RESULTS(m_ulVoidRCTime);
  50. INIT_RESULTS(m_ulDwordInTime);
  51. INIT_RESULTS(m_ulDwordOutTime);
  52. INIT_RESULTS(m_ulDwordInOutTime);
  53. INIT_RESULTS(m_ulStringInTime);
  54. INIT_RESULTS(m_ulStringOutTime);
  55. INIT_RESULTS(m_ulStringInOutTime);
  56. INIT_RESULTS(m_ulGuidInTime);
  57. INIT_RESULTS(m_ulGuidOutTime);
  58. INIT_RESULTS(m_ulIUnknownInprocInTime);
  59. INIT_RESULTS(m_ulIUnknownInprocOutTime);
  60. INIT_RESULTS(m_ulIUnknownLocalInTime);
  61. INIT_RESULTS(m_ulIUnknownLocalOutTime);
  62. INIT_RESULTS(m_ulIUnknownKeepInTime);
  63. INIT_RESULTS(m_ulIUnknownKeepOutTime);
  64. INIT_RESULTS(m_ulInterfaceInprocInTime);
  65. INIT_RESULTS(m_ulInterfaceLocalInTime);
  66. sc = InitCOM();
  67. if (FAILED(sc))
  68. {
  69. Log (TEXT("Setup - CoInitialize failed."), sc);
  70. return sc;
  71. }
  72. m_pRPC=NULL;
  73. sc = CoCreateInstance(m_ClsID, NULL, CLSCTX_LOCAL_SERVER,
  74. IID_IRpcTest, (void **)&m_pRPC);
  75. if (FAILED(sc))
  76. {
  77. Log (TEXT("Setup - CoCreateInstance IRpcTest failed."), sc);
  78. return sc;
  79. }
  80. // get the inprocess object for the IUnknown marshalling test
  81. sc = pInput->GetGUID(&m_ClsID, Name(), TEXT("Clsid_Inproc"));
  82. if (FAILED(sc))
  83. {
  84. Log (TEXT("Setup - GetClassID Inproc failed."), sc);
  85. return sc;
  86. }
  87. m_punkInproc = NULL;
  88. sc = CoCreateInstance(m_ClsID, NULL, CLSCTX_INPROC_SERVER,
  89. IID_IUnknown, (void **)&m_punkInproc);
  90. if (FAILED(sc))
  91. {
  92. Log (TEXT("Setup - CoCreateInstance IUnknown Inproc failed."), sc);
  93. return sc;
  94. }
  95. // get the out of process object for the IUnknown marshalling test
  96. m_punkLocal = NULL;
  97. sc = CoCreateInstance(m_ClsID, NULL, CLSCTX_LOCAL_SERVER,
  98. IID_IUnknown, (void **)&m_punkLocal);
  99. if (FAILED(sc))
  100. {
  101. Log (TEXT("Setup - CoCreateInstance IUnknown LocalSrv failed."), sc);
  102. return sc;
  103. }
  104. return S_OK;
  105. }
  106. SCODE CRpcTest::Cleanup ()
  107. {
  108. if (m_pRPC)
  109. m_pRPC->Release();
  110. if (m_punkInproc)
  111. m_punkInproc->Release();
  112. if (m_punkLocal)
  113. m_punkLocal->Release();
  114. UninitCOM();
  115. return S_OK;
  116. }
  117. SCODE CRpcTest::Run ()
  118. {
  119. CStopWatch sw;
  120. SCODE sc;
  121. ULONG iIter;
  122. //
  123. // void passing tests
  124. //
  125. // STARTTRACE("CRpcTest");
  126. ResetAverage( m_fAverage, sw );
  127. for (iIter=0; iIter<m_ulIterations; iIter++)
  128. {
  129. // TRACECALL(TRACE_APP, "m_pRPC->Void()");
  130. ResetNotAverage( m_fAverage, sw );
  131. m_pRPC->Void();
  132. ReadNotAverage( m_fAverage, sw, m_ulVoidTime[iIter] );
  133. }
  134. ReadAverage( m_fAverage, sw, m_ulVoidTime[0], m_ulIterations );
  135. // STOPTRACE("CRpcTest");
  136. ResetAverage( m_fAverage, sw );
  137. for (iIter=0; iIter<m_ulIterations; iIter++)
  138. {
  139. // TRACECALL(TRACE_APP, "m_pRPC->VoidRC()");
  140. ResetNotAverage( m_fAverage, sw );
  141. sc = m_pRPC->VoidRC();
  142. ReadNotAverage( m_fAverage, sw, m_ulVoidRCTime[iIter] );
  143. }
  144. ReadAverage( m_fAverage, sw, m_ulVoidRCTime[0], m_ulIterations );
  145. //
  146. // dword passing tests
  147. //
  148. DWORD dwTmp = 1;
  149. ResetAverage( m_fAverage, sw );
  150. for (iIter=0; iIter<m_ulIterations; iIter++)
  151. {
  152. ResetNotAverage( m_fAverage, sw );
  153. sc = m_pRPC->DwordIn(dwTmp);
  154. ReadNotAverage( m_fAverage, sw, m_ulDwordInTime[iIter] );
  155. }
  156. ReadAverage( m_fAverage, sw, m_ulDwordInTime[0], m_ulIterations );
  157. ResetAverage( m_fAverage, sw );
  158. for (iIter=0; iIter<m_ulIterations; iIter++)
  159. {
  160. ResetNotAverage( m_fAverage, sw );
  161. sc = m_pRPC->DwordOut(&dwTmp);
  162. ReadNotAverage( m_fAverage, sw, m_ulDwordOutTime[iIter] );
  163. }
  164. ReadAverage( m_fAverage, sw, m_ulDwordOutTime[0], m_ulIterations );
  165. ResetAverage( m_fAverage, sw );
  166. for (iIter=0; iIter<m_ulIterations; iIter++)
  167. {
  168. ResetNotAverage( m_fAverage, sw );
  169. sc = m_pRPC->DwordInOut(&dwTmp);
  170. ReadNotAverage( m_fAverage, sw, m_ulDwordInOutTime[iIter] );
  171. }
  172. ReadAverage( m_fAverage, sw, m_ulDwordInOutTime[0], m_ulIterations );
  173. //
  174. // string passing tests
  175. //
  176. OLECHAR wszHello[] = L"C:\\FOOFOO\\FOOBAR\\FOOBAK\\FOOBAZ\\FOOTYPICAL\\PATH\\HELLO";
  177. ResetAverage( m_fAverage, sw );
  178. for (iIter=0; iIter<m_ulIterations; iIter++)
  179. {
  180. ResetNotAverage( m_fAverage, sw );
  181. sc = m_pRPC->StringIn(wszHello);
  182. ReadNotAverage( m_fAverage, sw, m_ulStringInTime[iIter] );
  183. }
  184. ReadAverage( m_fAverage, sw, m_ulStringInTime[0], m_ulIterations );
  185. LPOLESTR pwszOut = NULL;
  186. #ifdef STRINGOUT
  187. ResetAverage( m_fAverage, sw );
  188. for (iIter=0; iIter<m_ulIterations; iIter++)
  189. {
  190. pwszOut = NULL;
  191. ResetNotAverage( m_fAverage, sw );
  192. sc = m_pRPC->StringOut(&pwszOut);
  193. ReadNotAverage( m_fAverage, sw, m_ulStringOutTime[iIter] );
  194. }
  195. ReadAverage( m_fAverage, sw, m_ulStringOutTime[0], m_ulIterations );
  196. #endif
  197. pwszOut = wszHello;
  198. ResetAverage( m_fAverage, sw );
  199. for (iIter=0; iIter<m_ulIterations; iIter++)
  200. {
  201. ResetNotAverage( m_fAverage, sw );
  202. sc = m_pRPC->StringInOut(pwszOut);
  203. ReadNotAverage( m_fAverage, sw, m_ulStringInOutTime[iIter] );
  204. }
  205. ReadAverage( m_fAverage, sw, m_ulStringInOutTime[0], m_ulIterations );
  206. //
  207. // guid passing tests
  208. //
  209. ResetAverage( m_fAverage, sw );
  210. for (iIter=0; iIter<m_ulIterations; iIter++)
  211. {
  212. ResetNotAverage( m_fAverage, sw );
  213. sc = m_pRPC->GuidIn(IID_IRpcTest);
  214. ReadNotAverage( m_fAverage, sw, m_ulGuidInTime[iIter] );
  215. }
  216. ReadAverage( m_fAverage, sw, m_ulGuidInTime[0], m_ulIterations );
  217. GUID guid;
  218. ResetAverage( m_fAverage, sw );
  219. for (iIter=0; iIter<m_ulIterations; iIter++)
  220. {
  221. ResetNotAverage( m_fAverage, sw );
  222. sc = m_pRPC->GuidOut(&guid);
  223. ReadNotAverage( m_fAverage, sw, m_ulGuidOutTime[iIter] );
  224. }
  225. ReadAverage( m_fAverage, sw, m_ulGuidOutTime[0], m_ulIterations );
  226. //
  227. // IUnknown passing tests
  228. //
  229. ResetAverage( m_fAverage, sw );
  230. for (iIter=0; iIter<m_ulIterations; iIter++)
  231. {
  232. ResetNotAverage( m_fAverage, sw );
  233. sc = m_pRPC->IUnknownIn(m_punkInproc);
  234. ReadNotAverage( m_fAverage, sw, m_ulIUnknownInprocInTime[iIter] );
  235. }
  236. ReadAverage( m_fAverage, sw, m_ulIUnknownInprocInTime[0], m_ulIterations );
  237. ResetAverage( m_fAverage, sw );
  238. for (iIter=0; iIter<m_ulIterations; iIter++)
  239. {
  240. ResetNotAverage( m_fAverage, sw );
  241. sc = m_pRPC->IUnknownIn(m_punkLocal);
  242. ReadNotAverage( m_fAverage, sw, m_ulIUnknownLocalInTime[iIter] );
  243. }
  244. ReadAverage( m_fAverage, sw, m_ulIUnknownLocalInTime[0], m_ulIterations );
  245. IUnknown *punk = NULL;
  246. ResetAverage( m_fAverage, sw );
  247. for (iIter=0; iIter<m_ulIterations; iIter++)
  248. {
  249. ResetNotAverage( m_fAverage, sw );
  250. sc = m_pRPC->IUnknownOut(&punk);
  251. punk->Release();
  252. punk = NULL;
  253. ReadNotAverage( m_fAverage, sw, m_ulIUnknownInprocOutTime[iIter] );
  254. }
  255. ReadAverage( m_fAverage, sw, m_ulIUnknownInprocOutTime[0], m_ulIterations );
  256. //
  257. // interface passing tests
  258. //
  259. #ifdef NOTYET
  260. IStream *pIStm = NULL;
  261. sc = m_punkInproc->QueryInterface(IID_IStream, (void **)&pIStm);
  262. if (SUCCEEDED(sc) && pIStm)
  263. {
  264. ResetAverage( m_fAverage, sw );
  265. for (iIter=0; iIter<m_ulIterations; iIter++)
  266. {
  267. ResetNotAverage( m_fAverage, sw );
  268. sc = m_pRPC->InterfaceIn(IID_IStream, pIStm);
  269. ReadNotAverage( m_fAverage, sw, m_ulInterfaceInprocInTime[iIter] );
  270. }
  271. ReadAverage( m_fAverage, sw, m_ulInterfaceInprocInTime[0], m_ulIterations );
  272. pIStm->Release();
  273. }
  274. pIStm = NULL;
  275. sc = m_punkLocal->QueryInterface(IID_IStream, (void **)&pIStm);
  276. if (SUCCEEDED(sc) && pIStm)
  277. {
  278. ResetAverage( m_fAverage, sw );
  279. for (iIter=0; iIter<m_ulIterations; iIter++)
  280. {
  281. ResetNotAverage( m_fAverage, sw );
  282. sc = m_pRPC->InterfaceIn(IID_IStream, pIStm);
  283. ReadNotAverage( m_fAverage, sw, m_ulInterfaceLocalInTime[iIter] );
  284. }
  285. ReadAverage( m_fAverage, sw, m_ulInterfaceLocalInTime[0], m_ulIterations );
  286. pIStm->Release();
  287. }
  288. #endif
  289. return S_OK;
  290. }
  291. SCODE CRpcTest::Report (CTestOutput &output)
  292. {
  293. if (m_fAverage)
  294. {
  295. output.WriteSectionHeader (Name(), TEXT("Object Rpc"), *m_pInput);
  296. output.WriteString (TEXT("\n"));
  297. output.WriteString (TEXT("Average times\n"));
  298. output.WriteString (TEXT("\n"));
  299. output.WriteResult (TEXT("Void "), m_ulVoidTime[0]);
  300. output.WriteResult (TEXT("VoidRC "), m_ulVoidRCTime[0]);
  301. output.WriteResult (TEXT("DwordIn "), m_ulDwordInTime[0]);
  302. output.WriteResult (TEXT("DwordOut "), m_ulDwordOutTime[0]);
  303. output.WriteResult (TEXT("DwordInOut "), m_ulDwordInOutTime[0]);
  304. output.WriteResult (TEXT("StringIn "), m_ulStringInTime[0]);
  305. #ifdef STRINGOUT
  306. output.WriteResult (TEXT("StringOut "), m_ulStringOutTime[0]);
  307. #endif
  308. output.WriteResult (TEXT("StringInOut "), m_ulStringInOutTime[0]);
  309. output.WriteResult (TEXT("GuidIn "), m_ulGuidInTime[0]);
  310. output.WriteResult (TEXT("GuidOut "), m_ulGuidOutTime[0]);
  311. output.WriteResult (TEXT("IUnknownIp "), m_ulIUnknownInprocInTime[0]);
  312. output.WriteResult (TEXT("IUnknownLcl "), m_ulIUnknownLocalInTime[0]);
  313. output.WriteResult (TEXT("IUnknownOut "), m_ulIUnknownInprocOutTime[0]);
  314. // output.WriteResult (TEXT("IUnknownKpIn "), m_ulIUnknownKeepInTime[0]);
  315. // output.WriteResult (TEXT("IUnknownKpOut"), m_ulIUnknownKeepOutTime[0]);
  316. #ifdef NOTYET
  317. output.WriteResult (TEXT("InterfaceIn "), m_ulInterfaceInprocInTime[0]);
  318. output.WriteResult (TEXT("InterfaceLcl"), m_ulInterfaceLocalInTime[0]);
  319. #endif
  320. }
  321. else
  322. {
  323. output.WriteSectionHeader (Name(), TEXT("Object Rpc"), *m_pInput);
  324. output.WriteString (TEXT("\n"));
  325. output.WriteResults (TEXT("Void "), m_ulIterations, m_ulVoidTime);
  326. output.WriteResults (TEXT("VoidRC "), m_ulIterations, m_ulVoidRCTime);
  327. output.WriteResults (TEXT("DwordIn "), m_ulIterations, m_ulDwordInTime);
  328. output.WriteResults (TEXT("DwordOut "), m_ulIterations, m_ulDwordOutTime);
  329. output.WriteResults (TEXT("DwordInOut "), m_ulIterations, m_ulDwordInOutTime);
  330. output.WriteResults (TEXT("StringIn "), m_ulIterations, m_ulStringInTime);
  331. #ifdef STRINGOUT
  332. output.WriteResults (TEXT("StringOut "), m_ulIterations, m_ulStringOutTime);
  333. #endif
  334. output.WriteResults (TEXT("StringInOut "), m_ulIterations, m_ulStringInOutTime);
  335. output.WriteResults (TEXT("GuidIn "), m_ulIterations, m_ulGuidInTime);
  336. output.WriteResults (TEXT("GuidOut "), m_ulIterations, m_ulGuidOutTime);
  337. output.WriteResults (TEXT("IUnknownIp "), m_ulIterations, m_ulIUnknownInprocInTime);
  338. output.WriteResults (TEXT("IUnknownLcl "), m_ulIterations, m_ulIUnknownLocalInTime);
  339. output.WriteResults (TEXT("IUnknownOut "), m_ulIterations, m_ulIUnknownInprocOutTime);
  340. // output.WriteResults (TEXT("IUnknownKpIn "), m_ulIterations, m_ulIUnknownKeepInTime);
  341. // output.WriteResults (TEXT("IUnknownKpOut"), m_ulIterations, m_ulIUnknownKeepOutTime);
  342. #ifdef NOTYET
  343. output.WriteResults (TEXT("InterfaceIn "), m_ulIterations, m_ulInterfaceInprocInTime);
  344. output.WriteResults (TEXT("InterfaceLcl"), m_ulIterations, m_ulInterfaceLocalInTime);
  345. #endif
  346. }
  347. return S_OK;
  348. }