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.

500 lines
13 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_rrpc.cxx
  7. //
  8. // Contents: Raw Rpc function call tests
  9. //
  10. // Classes: CRawRpc
  11. //
  12. // History: 1-Jul-93 t-martig Created
  13. // 2-Feb-94 rickhi Modified from above for Raw Rpc
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <headers.cxx>
  17. #pragma hdrstop
  18. #include <bm_rrpc.hxx>
  19. HRESULT StartServer(BOOL _fDebug, LPTSTR _pszPath);
  20. extern "C" const GUID IID_IRawRpc;
  21. TCHAR *CRawRpc::Name ()
  22. {
  23. return TEXT("RawRpc");
  24. }
  25. SCODE CRawRpc::Setup (CTestInput *pInput)
  26. {
  27. CTestBase::Setup(pInput);
  28. // get flag indicating whether to keep all values or
  29. // only average values.
  30. TCHAR szAverage[5];
  31. pInput->GetConfigString(Name(), TEXT("Average"), TEXT("Y"),
  32. szAverage, sizeof(szAverage)/sizeof(TCHAR));
  33. if (szAverage[0] == 'n' || szAverage[0] == 'N')
  34. m_fAverage = FALSE;
  35. else
  36. m_fAverage = TRUE;
  37. // get iteration count
  38. if (m_fAverage)
  39. m_ulIterations = pInput->GetRealIterations(Name());
  40. else
  41. m_ulIterations = pInput->GetIterations(Name());
  42. m_pszStringBinding = NULL;
  43. m_hRpc = NULL;
  44. // initialize timing arrays
  45. INIT_RESULTS(m_ulVoidTime);
  46. INIT_RESULTS(m_ulVoidRCTime);
  47. INIT_RESULTS(m_ulDwordInTime);
  48. INIT_RESULTS(m_ulDwordOutTime);
  49. INIT_RESULTS(m_ulDwordInOutTime);
  50. INIT_RESULTS(m_ulStringInTime);
  51. INIT_RESULTS(m_ulStringOutTime);
  52. INIT_RESULTS(m_ulStringInOutTime);
  53. INIT_RESULTS(m_ulGuidInTime);
  54. INIT_RESULTS(m_ulGuidOutTime);
  55. // get the server exe name and debug flag out of the ini file, then
  56. // start the server and wait for it.
  57. TCHAR szServer[15];
  58. pInput->GetConfigString(Name(), TEXT("Server"), TEXT("rawrpc.exe"),
  59. szServer, sizeof(szServer)/sizeof(TCHAR));
  60. // get input
  61. TCHAR szValue[40];
  62. pInput->GetConfigString(Name(), TEXT("Debug"), TEXT("N"),
  63. szValue, sizeof(szValue)/sizeof(TCHAR));
  64. BOOL fDebug = !lstrcmpi(szValue, TEXT("Y"));
  65. DWORD dwTimeout = pInput->GetConfigInt(Name(), TEXT("Timeout"), 60000);
  66. HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE,
  67. TEXT("OleBenchRawRpcServerStarted"));
  68. if (NULL == hEvent)
  69. {
  70. Log (TEXT("Setup - Event Creation failed."), GetLastError());
  71. return E_FAIL;
  72. }
  73. // start the server application and wait for it.
  74. HRESULT sc = StartServer(fDebug, szServer);
  75. if (FAILED(sc))
  76. {
  77. Log (TEXT("Setup - Start Server failed."), sc);
  78. CloseHandle(hEvent);
  79. return sc;
  80. }
  81. if (WAIT_OBJECT_0 != WaitForSingleObject(hEvent, dwTimeout))
  82. {
  83. Log (TEXT("Setup - Server never signaled."), GetLastError());
  84. CloseHandle(hEvent);
  85. return E_FAIL;
  86. }
  87. CloseHandle(hEvent);
  88. // bind to the server application
  89. TCHAR szProtseq[20];
  90. TCHAR szNetworkAddr[20];
  91. pInput->GetConfigString(Name(), TEXT("Protseq"),
  92. #ifdef USE_MSWMSG
  93. TEXT("mswmsg"),
  94. #else
  95. TEXT("ncalrpc"),
  96. #endif
  97. szProtseq, 20);
  98. pInput->GetConfigString(Name(), TEXT("NetworkAddr"), TEXT(""),
  99. szNetworkAddr, 20);
  100. LPTSTR pszEndPoint = TEXT("99999.99999");
  101. RPC_STATUS rc;
  102. #ifdef UNICODE
  103. rc = RpcStringBindingCompose(NULL,
  104. szProtseq,
  105. szNetworkAddr,
  106. pszEndPoint,
  107. NULL,
  108. &m_pszStringBinding);
  109. #else
  110. //
  111. // Can't just use TCHAR here because RpcString*() take unsigned
  112. // chars
  113. //
  114. rc = RpcStringBindingCompose(NULL,
  115. (unsigned char *)szProtseq,
  116. (unsigned char *)szNetworkAddr,
  117. (unsigned char *)pszEndPoint,
  118. NULL,
  119. (unsigned char **)&m_pszStringBinding);
  120. #endif
  121. if (rc != S_OK)
  122. {
  123. Log(TEXT("Setup - RpcStringBindingCompose failed."), rc);
  124. return rc;
  125. }
  126. #ifdef UNICODE
  127. rc = RpcBindingFromStringBinding(m_pszStringBinding, &m_hRpc);
  128. #else
  129. rc = RpcBindingFromStringBinding((unsigned char *)m_pszStringBinding,
  130. &m_hRpc);
  131. #endif
  132. if (rc != S_OK)
  133. {
  134. Log(TEXT("Setup - RpcBindingFromStringBinding failed."), rc);
  135. return rc;
  136. }
  137. // all done.
  138. return S_OK;
  139. }
  140. SCODE CRawRpc::Cleanup ()
  141. {
  142. if (m_hRpc)
  143. {
  144. RpcBindingFree(&m_hRpc);
  145. }
  146. if (m_pszStringBinding)
  147. {
  148. #ifdef UNICODE
  149. RpcStringFree(&m_pszStringBinding);
  150. #else
  151. RpcStringFree((unsigned char **)&m_pszStringBinding);
  152. #endif
  153. }
  154. return S_OK;
  155. }
  156. SCODE CRawRpc::Run ()
  157. {
  158. CStopWatch sw;
  159. SCODE sc;
  160. ULONG iIter;
  161. //
  162. // void passing tests
  163. //
  164. ResetAverage( m_fAverage, sw );
  165. for (iIter=0; iIter<m_ulIterations; iIter++)
  166. {
  167. ResetNotAverage( m_fAverage, sw );
  168. Void(m_hRpc);
  169. ReadNotAverage( m_fAverage, sw, m_ulVoidTime[iIter] );
  170. }
  171. ReadAverage( m_fAverage, sw, m_ulVoidTime[0], m_ulIterations );
  172. ResetAverage( m_fAverage, sw );
  173. for (iIter=0; iIter<m_ulIterations; iIter++)
  174. {
  175. ResetNotAverage( m_fAverage, sw );
  176. sc = VoidRC(m_hRpc);
  177. ReadNotAverage( m_fAverage, sw, m_ulVoidRCTime[iIter] );
  178. }
  179. ReadAverage( m_fAverage, sw, m_ulVoidRCTime[0], m_ulIterations );
  180. //
  181. // dword passing tests
  182. //
  183. DWORD dwTmp = 1;
  184. ResetAverage( m_fAverage, sw );
  185. for (iIter=0; iIter<m_ulIterations; iIter++)
  186. {
  187. ResetNotAverage( m_fAverage, sw );
  188. sc = DwordIn(m_hRpc, dwTmp);
  189. ReadNotAverage( m_fAverage, sw, m_ulDwordInTime[iIter] );
  190. }
  191. ReadAverage( m_fAverage, sw, m_ulDwordInTime[0], m_ulIterations );
  192. ResetAverage( m_fAverage, sw );
  193. for (iIter=0; iIter<m_ulIterations; iIter++)
  194. {
  195. ResetNotAverage( m_fAverage, sw );
  196. sc = DwordOut(m_hRpc, &dwTmp);
  197. ReadNotAverage( m_fAverage, sw, m_ulDwordOutTime[iIter] );
  198. }
  199. ReadAverage( m_fAverage, sw, m_ulDwordOutTime[0], m_ulIterations );
  200. ResetAverage( m_fAverage, sw );
  201. for (iIter=0; iIter<m_ulIterations; iIter++)
  202. {
  203. ResetNotAverage( m_fAverage, sw );
  204. sc = DwordInOut(m_hRpc, &dwTmp);
  205. ReadNotAverage( m_fAverage, sw, m_ulDwordInOutTime[iIter] );
  206. }
  207. ReadAverage( m_fAverage, sw, m_ulDwordInOutTime[0], m_ulIterations );
  208. //
  209. // string passing tests
  210. //
  211. WCHAR szHello[] = L"C:\\FOOFOO\\FOOBAR\\FOOBAK\\FOOBAZ\\FOOTYPICAL\\PATH\\HELLO";
  212. ResetAverage( m_fAverage, sw );
  213. for (iIter=0; iIter<m_ulIterations; iIter++)
  214. {
  215. ResetNotAverage( m_fAverage, sw );
  216. sc = StringIn(m_hRpc, szHello);
  217. ReadNotAverage( m_fAverage, sw, m_ulStringInTime[iIter] );
  218. }
  219. ReadAverage( m_fAverage, sw, m_ulStringInTime[0], m_ulIterations );
  220. LPWSTR pwszOut = NULL;
  221. #ifdef STRINGOUT
  222. ResetAverage( m_fAverage, sw );
  223. for (iIter=0; iIter<m_ulIterations; iIter++)
  224. {
  225. ResetNotAverage( m_fAverage, sw );
  226. pwszOut = NULL;
  227. sc = StringOut(m_hRpc, &pwszOut);
  228. ReadNotAverage( m_fAverage, sw, m_ulStringOutTime[iIter] );
  229. }
  230. ReadAverage( m_fAverage, sw, m_ulStringOutTime[0], m_ulIterations );
  231. #endif
  232. pwszOut = szHello;
  233. ResetAverage( m_fAverage, sw );
  234. for (iIter=0; iIter<m_ulIterations; iIter++)
  235. {
  236. ResetNotAverage( m_fAverage, sw );
  237. sc = StringInOut(m_hRpc, pwszOut);
  238. ReadNotAverage( m_fAverage, sw, m_ulStringInOutTime[iIter] );
  239. }
  240. ReadAverage( m_fAverage, sw, m_ulStringInOutTime[0], m_ulIterations );
  241. //
  242. // guid passing tests
  243. //
  244. ResetAverage( m_fAverage, sw );
  245. for (iIter=0; iIter<m_ulIterations; iIter++)
  246. {
  247. ResetNotAverage( m_fAverage, sw );
  248. sc = GuidIn(m_hRpc, IID_IRawRpc);
  249. ReadNotAverage( m_fAverage, sw, m_ulGuidInTime[iIter] );
  250. }
  251. ReadAverage( m_fAverage, sw, m_ulGuidInTime[0], m_ulIterations );
  252. GUID guid;
  253. ResetAverage( m_fAverage, sw );
  254. for (iIter=0; iIter<m_ulIterations; iIter++)
  255. {
  256. ResetNotAverage( m_fAverage, sw );
  257. sc = GuidOut(m_hRpc, &guid);
  258. ReadNotAverage( m_fAverage, sw, m_ulGuidOutTime[iIter] );
  259. }
  260. ReadAverage( m_fAverage, sw, m_ulGuidOutTime[0], m_ulIterations );
  261. // tell the server to quit.
  262. sc = Quit(m_hRpc);
  263. return S_OK;
  264. }
  265. SCODE CRawRpc::Report (CTestOutput &output)
  266. {
  267. output.WriteSectionHeader (Name(), TEXT("Raw Rpc"), *m_pInput);
  268. if (m_fAverage)
  269. {
  270. output.WriteString (TEXT("\n"));
  271. output.WriteString (TEXT("Average Times\n"));
  272. output.WriteString (TEXT("\n"));
  273. output.WriteResult (TEXT("Void "), m_ulVoidTime[0]);
  274. output.WriteResult (TEXT("VoidRC "), m_ulVoidRCTime[0]);
  275. output.WriteResult (TEXT("DwordIn "), m_ulDwordInTime[0]);
  276. output.WriteResult (TEXT("DwordOut "), m_ulDwordOutTime[0]);
  277. output.WriteResult (TEXT("DwordInOut "), m_ulDwordInOutTime[0]);
  278. output.WriteResult (TEXT("StringIn "), m_ulStringInTime[0]);
  279. #ifdef STRINGOUT
  280. output.WriteResult (TEXT("StringOut "), m_ulStringOutTime[0]);
  281. #endif
  282. output.WriteResult (TEXT("StringInOut "), m_ulStringInOutTime[0]);
  283. output.WriteResult (TEXT("GuidIn "), m_ulGuidInTime[0]);
  284. output.WriteResult (TEXT("GuidOut "), m_ulGuidOutTime[0]);
  285. }
  286. else
  287. {
  288. output.WriteString (TEXT("\n"));
  289. output.WriteResults (TEXT("Void "), m_ulIterations, m_ulVoidTime);
  290. output.WriteResults (TEXT("VoidRC "), m_ulIterations, m_ulVoidRCTime);
  291. output.WriteResults (TEXT("DwordIn "), m_ulIterations, m_ulDwordInTime);
  292. output.WriteResults (TEXT("DwordOut "), m_ulIterations, m_ulDwordOutTime);
  293. output.WriteResults (TEXT("DwordInOut "), m_ulIterations, m_ulDwordInOutTime);
  294. output.WriteResults (TEXT("StringIn "), m_ulIterations, m_ulStringInTime);
  295. #ifdef STRINGOUT
  296. output.WriteResults (TEXT("StringOut "), m_ulIterations, m_ulStringOutTime);
  297. #endif
  298. output.WriteResults (TEXT("StringInOut "), m_ulIterations, m_ulStringInOutTime);
  299. output.WriteResults (TEXT("GuidIn "), m_ulIterations, m_ulGuidInTime);
  300. output.WriteResults (TEXT("GuidOut "), m_ulIterations, m_ulGuidOutTime);
  301. }
  302. return S_OK;
  303. }
  304. //+-------------------------------------------------------------------------
  305. //
  306. // Function: StartServer
  307. //
  308. // Synopsis: Start an Rpc server process
  309. //
  310. // Arguments: [_fDebug] - start in a debugger or not
  311. // [_pwszPath] - name of server process
  312. //
  313. // Returns: S_OK - Server started
  314. // S_FALSE - server is already starting
  315. // CO_E_SERVER_EXEC_FAILURE
  316. //
  317. // Algorithm:
  318. //
  319. // History: 21-Apr-93 Ricksa Created
  320. // 04-Jan-94 Ricksa Modified for class starting sync.
  321. //
  322. //--------------------------------------------------------------------------
  323. HRESULT StartServer(BOOL _fDebug, LPTSTR _pszPath)
  324. {
  325. // Where we put the command line
  326. TCHAR aszTmpCmdLine[MAX_PATH];
  327. TCHAR *pszTmpCmdLine = aszTmpCmdLine;
  328. if (_fDebug)
  329. {
  330. HKEY hKey;
  331. DWORD dwType;
  332. DWORD cbData = sizeof(aszTmpCmdLine)/sizeof(TCHAR);
  333. ULONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  334. TEXT("SOFTWARE\\Microsoft\\scm"),
  335. 0,
  336. KEY_READ,
  337. &hKey);
  338. if (rc == ERROR_SUCCESS)
  339. {
  340. // copy the debugger info into the command line
  341. rc = RegQueryValueEx(hKey, TEXT("Debugger"), 0, &dwType,
  342. (LPBYTE)pszTmpCmdLine, &cbData);
  343. if (rc == ERROR_SUCCESS && dwType == REG_SZ)
  344. {
  345. ULONG ulLen = cbData / sizeof(TCHAR);
  346. pszTmpCmdLine += ulLen;
  347. aszTmpCmdLine[ulLen-1] = TEXT(' '); // whitespace
  348. }
  349. RegCloseKey(hKey);
  350. }
  351. }
  352. #ifdef NOTYET // following code does not compile!
  353. #ifndef CAIROLE_DOWNLEVEL
  354. if (acWinFormat[0] == 0)
  355. {
  356. TCHAR acWinDir[MAX_PATH];
  357. UINT cWinDir = GetSystemDirectory(acWinDir, sizeof(acWinDir)/sizeof(TCHAR));
  358. Win4Assert(cWinDir && "GetWindowsDir failed!");
  359. wsprintf(acWinFormat, TEXT("%s%s"), acWinDir, TEXT("\\%s %s"));
  360. }
  361. // We make all paths relative to the windows directory unless
  362. // the path is absolute.
  363. wsprintf(pszTmpCmdLine,
  364. (_pszPath[1] != TEXT(':')) ? acWinFormat : TEXT("%s %s"),
  365. _pwszPath,
  366. TEXT("-Embedding"));
  367. #else
  368. #endif // CAIROLE_DOWNLEVEL
  369. #endif // NOTYET
  370. // Just use the current path to find the server.
  371. wsprintf(pszTmpCmdLine, TEXT("%s %s"), _pszPath, TEXT("-Embedding"));
  372. // Process info for create process
  373. PROCESS_INFORMATION procinfo;
  374. // build the win32 startup info structure
  375. STARTUPINFO startupinfo;
  376. startupinfo.cb = sizeof(STARTUPINFO);
  377. startupinfo.lpReserved = NULL;
  378. startupinfo.lpDesktop = NULL;
  379. startupinfo.lpTitle = _pszPath;
  380. startupinfo.dwX = 40;
  381. startupinfo.dwY = 40;
  382. startupinfo.dwXSize = 80;
  383. startupinfo.dwYSize = 40;
  384. startupinfo.dwFlags = 0;
  385. startupinfo.wShowWindow = SW_SHOWNORMAL;
  386. startupinfo.cbReserved2 = 0;
  387. startupinfo.lpReserved2 = NULL;
  388. if (!CreateProcess( NULL, // application name
  389. aszTmpCmdLine, // command line
  390. NULL, // process sec attributes
  391. NULL, // thread sec attributes
  392. FALSE, // dont inherit handles
  393. CREATE_NEW_CONSOLE,// creation flags
  394. NULL, // use same enviroment block
  395. NULL, // use same directory
  396. &startupinfo, // no startup info
  397. &procinfo)) // proc info returned
  398. {
  399. return CO_E_SERVER_EXEC_FAILURE;
  400. }
  401. CloseHandle(procinfo.hProcess);
  402. CloseHandle(procinfo.hThread);
  403. return S_OK;
  404. }