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.

470 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vststprocess.h
  5. Abstract:
  6. Declaration of test process classes
  7. Brian Berkowitz [brianb] 05/22/2000
  8. TBD:
  9. Revision History:
  10. Name Date Comments
  11. brianb 05/22/2000 Created
  12. --*/
  13. #ifndef _VSTSTPROCESS_H_
  14. #define _VSTSTPROCESS_H_
  15. // types of process that are understooed
  16. typedef enum VSTST_PROCESS_TYPE
  17. {
  18. VSTST_PT_UNDEFINED = 0,
  19. VSTST_PT_COORDINATOR, // snapshot coordinator (VSSVC)
  20. VSTST_PT_WRITER, // an arbitrary writer
  21. VSTST_PT_TESTWRITER, // the test writer
  22. VSTST_PT_BACKUP, // an arbitrary requestor
  23. VSTST_PT_TESTBACKUP, // the test backup application
  24. VSTST_PT_PROVIDER, // an arbitrary provider
  25. VSTST_PT_TESTPROVIDER, // the test provider application
  26. VSTST_PT_MAXPROCESSTYPE
  27. };
  28. // type of account to be used when running this process
  29. typedef enum VSTST_ACCOUNT_TYPE
  30. {
  31. VSTST_AT_UNDEFINED = 0,
  32. VSTST_AT_GUEST, // use guest account
  33. VSTST_AT_USER, // use an account belonging to the USER group
  34. VSTST_AT_POWERUSER, // use an account belonging to the POWER USER group
  35. VSTST_AT_BACKUPOPERATOR, // use an account belonging to the BACKUP OPERATOR group
  36. VSTST_AT_ADMIN // use an account belonging to the ADMINISTRATOR group
  37. };
  38. // forward declaration
  39. class CVsTstProcessList;
  40. class CVsTstProcess
  41. {
  42. public:
  43. friend class CVsTstProcessList;
  44. // constructor
  45. CVsTstProcess(CVsTstProcessList *pList);
  46. // destructor
  47. ~CVsTstProcess();
  48. // startup a process using a conforming executable
  49. HRESULT InitializeConformingExe
  50. (
  51. ULONGLONG processId, // process id of new process
  52. VSTST_PROCESS_TYPE type, // type of new process
  53. VSTST_ACCOUNT_TYPE account, // account to use to startup new process
  54. LPCWSTR wszExecutableName, // executable name to use
  55. LPCWSTR wszScenarioFile, // scenario file to use
  56. LPCWSTR wszSectionName, // section name within scenario file to use
  57. DWORD seed, // seed for random number generator
  58. UINT lifetime, // lifetime in seconds of application
  59. bool bAbnormalTermination, // is application to be abnormally terminated instead of gracefully terminated
  60. HANDLE hevtTermination // event signalled on process termination
  61. );
  62. // startup a process associated with a non-conforming executable
  63. HRESULT InitializeNonConformingExe
  64. (
  65. ULONGLONG processId, // process id of process
  66. VSTST_PROCESS_TYPE type, // type of the process
  67. VSTST_ACCOUNT_TYPE account, // account to use when starting the process
  68. LPCWSTR wszCommandLine, // command line used to startup the process
  69. UINT lifetime, // lifetime of the process
  70. HANDLE hevtTermination // event signed when the process terminates
  71. );
  72. // set private data for the process
  73. void SetPrivateData(void *pv)
  74. {
  75. m_pvPrivateData = pv;
  76. }
  77. // obtain the private data associated with the process
  78. void *GetPrivateData()
  79. {
  80. return m_pvPrivateData;
  81. }
  82. // determine if the process should be shutdown since its maximum lifetime
  83. // has expired
  84. bool HasProcessExpired();
  85. // terminate process
  86. void DoTerminateProcess(bool bAgressive);
  87. private:
  88. // force termination of the process
  89. void ForceTerminateProcess();
  90. // gracefully terminate the process
  91. void GracefullyTerminateProcess(bool bAgressive);
  92. // cleanup process
  93. void CleanupProcess();
  94. // process id
  95. ULONGLONG m_processId;
  96. // process type
  97. VSTST_PROCESS_TYPE m_type;
  98. // account to use
  99. VSTST_ACCOUNT_TYPE m_account;
  100. // process handle
  101. HANDLE m_hProcess;
  102. // handle to cause normal termination of process
  103. HANDLE m_hevtGracefullyTerminate;
  104. // event to signal on process termination
  105. // not owned by this object
  106. HANDLE m_hevtNotifyProcessTermination;
  107. // time process was started
  108. time_t m_timeProcessStart;
  109. // time process should be terminated
  110. time_t m_timeProcessTerminate;
  111. // time process started termination
  112. time_t m_timeProcessStartTermination;
  113. // time process termination should complete
  114. time_t m_timeProcessTerminationExpiration;
  115. // private data associated with process
  116. void *m_pvPrivateData;
  117. // next process in list
  118. CVsTstProcess *m_next;
  119. // previous process in list
  120. CVsTstProcess *m_prev;
  121. // process list
  122. CVsTstProcessList *m_processList;
  123. // termination event
  124. HANDLE m_hevtTermination;
  125. // is executable conforming
  126. bool m_bConforming;
  127. // has process been gracefully terminated
  128. bool m_bGracefullyTerminated;
  129. // is process linked into process list
  130. bool m_bLinked;
  131. // should process be abnormally terminated
  132. bool m_bAbnormallyTerminate;
  133. };
  134. class CVsTstParams;
  135. // global process list
  136. class CVsTstProcessList
  137. {
  138. public:
  139. friend class CVsTstProcess;
  140. // constructor
  141. CVsTstProcessList();
  142. // destructor
  143. ~CVsTstProcessList();
  144. // startup a process using a conforming executable
  145. HRESULT CreateConformingExe
  146. (
  147. IN VSTST_PROCESS_TYPE type, // type of process
  148. IN VSTST_ACCOUNT_TYPE account, // account to use when starting up the process
  149. IN LPCWSTR wszExecutableName, // excutable name to be used when starting the process
  150. IN LPCWSTR wszScenarioFile, // scenario file to be used by the process
  151. IN LPCWSTR wszSectionName, // section within the scenario file to be used by the process
  152. IN DWORD seed, // random seed to be used by the process
  153. IN UINT lifetime, // lifetime of the process
  154. IN bool bAbnormalTerminate, // should process be abnormally terminated when lifetime is exceeded
  155. IN HANDLE hevtNotify, // event to signal when process is terminated
  156. OUT ULONGLONG &processId // process id created for the process
  157. );
  158. // create a process for a non-conforming executable
  159. HRESULT CreateNonConformingExe
  160. (
  161. IN VSTST_PROCESS_TYPE type, // type of the new process
  162. IN VSTST_ACCOUNT_TYPE account, // account to be used when starting up the new process
  163. IN LPCWSTR wszCommandLine, // command line to be used when starting up the process
  164. IN UINT lifetime, // maximum lifetime in seconds for the process
  165. IN HANDLE hevtNotify, // event to signal when process is terminated
  166. OUT ULONGLONG &processId // process id allocated for the process
  167. );
  168. // initialize the process list and monitor
  169. HRESULT Initialize(UINT maxLifetime, HANDLE hevtTermination);
  170. // get private data associated with a process
  171. void *GetProcessPrivateData(LONGLONG processId);
  172. // set private data associated with a process
  173. void SetProcessPrivateData(LONGLONG processId, void *pv);
  174. // indicate that no more processes will be created
  175. void EndOfProcessCreation();
  176. private:
  177. // monitor function
  178. void MonitorFunc();
  179. // startup function for monitor thrad
  180. static DWORD StartupMonitorThread(void *pv);
  181. // start process termination
  182. void StartTermination();
  183. // link into process list
  184. void LinkIntoProcessList(CVsTstProcess *process);
  185. // remove from process list
  186. void UnlinkFromProcessList(CVsTstProcess *process);
  187. // find a specific process
  188. CVsTstProcess *FindProcess(ULONGLONG processId);
  189. // allocate a process id
  190. ULONGLONG AllocateProcessId();
  191. // lifetime of test
  192. time_t m_timeTerminateTest;
  193. // event to signal when all processes are destroyed
  194. HANDLE m_hevtTermination;
  195. // process id generator
  196. ULONGLONG m_processId;
  197. // process list
  198. CVsTstProcess *m_processList;
  199. // critical section controlling modification of process list
  200. CComCriticalSection m_csProcessList;
  201. // handle for the monitor thread
  202. HANDLE m_hThreadMonitor;
  203. // is critical section intialized
  204. bool m_bcsProcessListInitialized;
  205. // are any more processes being created
  206. bool m_bNoMoreProcessesAreCreated;
  207. // are we shutting down
  208. bool m_bShuttingDown;
  209. };
  210. class CVsTstParams;
  211. class CVsTstINIConfig;
  212. class CVsTstClientMsg;
  213. typedef enum VSTST_SHUTDOWN_REASON
  214. {
  215. VSTST_SR_UNDEFINED = 0,
  216. VSTST_SR_LIFETIME_EXCEEDED,
  217. VSTST_SR_CONTROLLER_SIGNALLED
  218. };
  219. interface IVsTstRunningTest
  220. {
  221. // main invocation point for test
  222. virtual HRESULT RunTest
  223. (
  224. CVsTstINIConfig *pConfig,
  225. CVsTstClientMsg *pMsg,
  226. CVsTstParams *pParams
  227. ) = 0;
  228. // entry point to cause test to shutdown
  229. virtual HRESULT ShutdownTest(VSTST_SHUTDOWN_REASON reason) = 0;
  230. };
  231. typedef enum VSTST_CMDTYPES
  232. {
  233. VSTST_CT_STRING,
  234. VSTST_CT_UINT,
  235. VSTST_CT_HANDLE
  236. };
  237. typedef enum VSTST_CMDPARAMS
  238. {
  239. VSTST_CP_SCENARIOFILE = 1,
  240. VSTST_CP_SECTIONNAME = 2,
  241. VSTST_CP_SEED = 4,
  242. VSTST_CP_LIFETIME = 8,
  243. VSTST_CP_TERMINATIONEVENT = 16,
  244. VSTST_CP_TESTTERMINATIONEVENT = 32,
  245. VSTST_CP_PIDLOW=64,
  246. VSTST_CP_PIDHIGH=128,
  247. VSTST_CP_TESTSERIES=256
  248. };
  249. typedef struct _VSTST_CMDDESC
  250. {
  251. LPCWSTR wszParam;
  252. VSTST_CMDTYPES type;
  253. VSTST_CMDPARAMS param;
  254. } VSTST_CMDDESC;
  255. // test parameters from command line
  256. class CVsTstParams
  257. {
  258. public:
  259. // constructor
  260. CVsTstParams();
  261. // destructor
  262. ~CVsTstParams();
  263. // routine to parse the command line
  264. bool ParseCommandLine(WCHAR **argv, UINT argc);
  265. // obtain file name of scenario file
  266. bool GetScenarioFileName(LPCWSTR *pwszScenarioFile);
  267. // obtain section to use within scenario file
  268. bool GetSectionName(LPCWSTR *pwszSectionName);
  269. // obtain seed to use for random number generator
  270. bool GetRandomSeed(UINT *pSeed);
  271. // obtain lifetime of process in seconds
  272. bool GetLifetime(UINT *pLifetime);
  273. // obtain event signaled to cause process to terminate gracefully
  274. bool GetTerminationEvent(HANDLE *pHandle);
  275. // event used to terminate the process
  276. bool GetTestTerminationEvent(HANDLE *pHandle);
  277. // process id of the process
  278. bool GetProcessId(ULONGLONG *pid);
  279. // get test series
  280. bool GetTestSeries(LPCWSTR *pwszTestSeries);
  281. private:
  282. // parse an integer value
  283. bool ParseUINT(LPCWSTR wsz, UINT *pulVal);
  284. // parse a string value
  285. bool ParseString(LPCWSTR wsz, LPWSTR *pwszVal);
  286. // parse a handle value
  287. bool ParseHandle(LPCWSTR wsz, HANDLE *phVal);
  288. // set seed value
  289. void SetSeed(UINT ulVal);
  290. // set lifetime value
  291. void SetLifetime(UINT ulVal);
  292. // set termination event
  293. void SetTerminationEvent(HANDLE hEvent);
  294. // set scenario file name
  295. void SetScenarioFile(LPWSTR wsz);
  296. // set test series file name
  297. void SetTestSeries(LPWSTR wsz);
  298. // set section name
  299. void SetSectionName(LPWSTR wsz);
  300. // set process id
  301. void SetPidLow(UINT ulVal);
  302. void SetPidHigh(UINT ulVal);
  303. // which parameters were supplied
  304. UINT m_supplied;
  305. // scneario file name
  306. LPWSTR m_wszScenarioFile;
  307. // test series file name
  308. LPWSTR m_wszTestSeries;
  309. // section name within scenario file
  310. LPWSTR m_wszSectionName;
  311. // random seed
  312. UINT m_seed;
  313. // lifetime of process in seconds
  314. UINT m_lifetime;
  315. // process id
  316. UINT m_pidLow;
  317. UINT m_pidHigh;
  318. // event signalled to cause process to terminate
  319. HANDLE m_hTerminationEvent;
  320. // event signalled when the test completes
  321. HANDLE m_hTestTerminationEvent;
  322. };
  323. // helper class to use to run a test within a process
  324. class CVsTstRunner
  325. {
  326. public:
  327. // run a test, i.e., parse command line, launch test thread and
  328. // if requested launch a termination thread
  329. static HRESULT RunVsTest
  330. (
  331. WCHAR **argv,
  332. UINT cArgs,
  333. IVsTstRunningTest *pTest,
  334. bool bCreateTerminationThread
  335. );
  336. private:
  337. // startup termination thread
  338. static DWORD StartupTerminationThread(void *pv);
  339. };
  340. #endif