Source code of Windows XP (NT5)
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.

274 lines
5.6 KiB

  1. //
  2. //
  3. //***************************************************************************
  4. //
  5. // judyp May 1999
  6. //
  7. //***************************************************************************
  8. #include "stdafx.h"
  9. #pragma warning (disable : 4786)
  10. #pragma warning (disable : 4275)
  11. #include <iostream>
  12. #include <strstream>
  13. #include <fstream>
  14. #include <string>
  15. #include <sstream>
  16. #include <map>
  17. #include <ctime>
  18. #include <list>
  19. using namespace std;
  20. #include <tchar.h>
  21. #include <windows.h>
  22. #ifdef NONNT5
  23. typedef unsigned long ULONG_PTR;
  24. #endif
  25. #include <wmistr.h>
  26. #include <guiddef.h>
  27. #include <initguid.h>
  28. #include <evntrace.h>
  29. #include <WTYPES.H>
  30. #include "t_string.h"
  31. #include "StructureWrappers.h"
  32. #include "StructureWapperHelpers.h"
  33. #include "ConstantMap.h"
  34. #include "TCOData.h"
  35. #include "Persistor.h"
  36. #include "Logger.h"
  37. #include "Validator.h"
  38. #include "Utilities.h"
  39. #include "CollectionControl.h"
  40. int QueryTraceAPI
  41. (
  42. IN LPTSTR lptstrAction, // For logging only.
  43. IN LPCTSTR lpctstrDataFile, // For logging only.
  44. IN LPCTSTR lpctstrTCODetailFile, // If valid we will log to it, can be NULL.
  45. IN bool bLogExpected, // If true we log expected vs actual result.
  46. IN bool bUseTraceHandle, // If true use the handle.
  47. IN OUT TCOData *pstructTCOData, // TCO test data.
  48. OUT int *pAPIReturn // QueryTrace API call return
  49. )
  50. {
  51. // If bUseTracehandle is true we can check for differences in
  52. // props.
  53. *pAPIReturn = -1;
  54. LPTSTR lptstrReturnedError = NULL;
  55. CLogger *pDetailLogger = NULL;
  56. int nResult = 0;
  57. // We only log if the test of "interest" is QueryTrace.
  58. if (pstructTCOData->m_ulAPITest == TCOData::QueryTraceTest)
  59. {
  60. nResult =
  61. OpenLogFiles
  62. (
  63. lpctstrTCODetailFile,
  64. pDetailLogger,
  65. &lptstrReturnedError
  66. );
  67. }
  68. if (FAILED(nResult))
  69. {
  70. delete pDetailLogger;
  71. // Open log files sets error string plpstrReturnedError.
  72. LogSummaryBeforeCall
  73. (
  74. pstructTCOData,
  75. lpctstrDataFile,
  76. lptstrAction,
  77. _T("StartTrace"),
  78. bLogExpected
  79. );
  80. LogSummaryAfterCall
  81. (
  82. pstructTCOData,
  83. lpctstrDataFile,
  84. lptstrAction,
  85. nResult,
  86. lptstrReturnedError,
  87. bLogExpected
  88. );
  89. free (lptstrReturnedError);
  90. lptstrReturnedError = NULL;
  91. return nResult;
  92. }
  93. // This is our log file.
  94. if (pDetailLogger)
  95. {
  96. pDetailLogger->LogTCHAR(_T("\n-------------------------------------------------------\n"));
  97. pDetailLogger->LogTCHAR(_T("QueryTraceAPI TCO test "));
  98. pDetailLogger->Flush();
  99. }
  100. if (pDetailLogger)
  101. {
  102. pDetailLogger->LogTCHAR(pstructTCOData->m_lptstrShortDesc);
  103. int n = pDetailLogger->LogTCHAR(_T(" started at time "));
  104. time_t Time;
  105. time(&Time);
  106. pDetailLogger->LogTime(Time);
  107. pDetailLogger->LogTCHAR(_T(".\n"));
  108. pDetailLogger->Flush();
  109. }
  110. BOOL bAdmin = IsAdmin();
  111. if (pDetailLogger)
  112. {
  113. // Log argument values before calling StopTrace.
  114. LogDetailBeforeCall
  115. (
  116. pDetailLogger,
  117. pstructTCOData,
  118. bAdmin
  119. );
  120. }
  121. CEventTraceProperties CProps (pstructTCOData->m_pProps);
  122. PEVENT_TRACE_PROPERTIES pProps = CProps.GetEventTracePropertiesInstance();
  123. free(pProps->LogFileName);
  124. free(pProps->LoggerName);
  125. pProps->LogFileName = (TCHAR *) malloc (sizeof(TCHAR) * MAX_STR);
  126. pProps->LoggerName = (TCHAR *) malloc (sizeof(TCHAR) * MAX_STR);
  127. LogSummaryBeforeCall
  128. (
  129. pstructTCOData,
  130. lpctstrDataFile,
  131. lptstrAction,
  132. _T("QueryTrace"),
  133. bLogExpected
  134. );
  135. *pAPIReturn =
  136. QueryTrace
  137. (
  138. bUseTraceHandle ? *pstructTCOData->m_pTraceHandle : NULL,
  139. bUseTraceHandle ? NULL : pstructTCOData->m_lptstrInstanceName,
  140. pProps);
  141. ULONG ulResult = pstructTCOData->m_ulExpectedResult == *pAPIReturn ? ERROR_SUCCESS : -1;
  142. if (ulResult != ERROR_SUCCESS && *pAPIReturn == ERROR_SUCCESS)
  143. {
  144. ulResult = *pAPIReturn;
  145. }
  146. else if (*pAPIReturn != ERROR_SUCCESS)
  147. {
  148. lptstrReturnedError = DecodeStatus(*pAPIReturn);
  149. }
  150. else if (pstructTCOData->m_ulAPITest == TCOData::QueryTraceTest &&
  151. pstructTCOData->m_lptstrValidator &&
  152. _tcslen(pstructTCOData->m_lptstrValidator) > 0)
  153. {
  154. CValidator Validator;
  155. bool bValid =
  156. Validator.Validate
  157. (
  158. pstructTCOData->m_pTraceHandle,
  159. pstructTCOData->m_lptstrInstanceName,
  160. pstructTCOData->m_pProps,
  161. pstructTCOData->m_lptstrValidator
  162. );
  163. if (!bValid)
  164. {
  165. ulResult = -1;
  166. lptstrReturnedError = NewTCHAR(_T("Validation routine failed."));
  167. }
  168. }
  169. bool bDiff = FALSE;
  170. if (bUseTraceHandle)
  171. {
  172. bDiff =
  173. LogPropsDiff
  174. (
  175. NULL,
  176. pstructTCOData->m_pProps,
  177. pProps
  178. );
  179. }
  180. // If there were differences and
  181. // *pAPIReturn == ERROR_SUCCESS == pstructTCOData->m_ulExpectedResult
  182. // we need to set return codes to indicate differences. Look in detail
  183. // log for differences.
  184. if (bDiff &&
  185. *pAPIReturn == ERROR_SUCCESS &&
  186. pstructTCOData->m_ulExpectedResult == ERROR_SUCCESS)
  187. {
  188. free (lptstrReturnedError);
  189. lptstrReturnedError = NULL;
  190. *pAPIReturn = -1;
  191. lptstrReturnedError =
  192. NewTCHAR(_T("Different values returned in EVENT_TRACE_PROPERTIES structure."));
  193. }
  194. if (pDetailLogger)
  195. {
  196. LogDetailAfterCall
  197. ( pDetailLogger,
  198. pstructTCOData,
  199. &pProps,
  200. *pAPIReturn,
  201. lptstrReturnedError,
  202. true,
  203. bAdmin,
  204. NULL,
  205. *pAPIReturn == ERROR_SUCCESS // Do not print out Props if not a good return.
  206. );
  207. }
  208. if (bUseTraceHandle)
  209. {
  210. LogPropsDiff
  211. (
  212. pDetailLogger,
  213. pstructTCOData->m_pProps,
  214. pProps
  215. );
  216. }
  217. LogSummaryAfterCall
  218. (
  219. pstructTCOData,
  220. lpctstrDataFile,
  221. lptstrAction,
  222. *pAPIReturn,
  223. lptstrReturnedError,
  224. bLogExpected
  225. );
  226. free (lptstrReturnedError);
  227. lptstrReturnedError = NULL;
  228. delete pDetailLogger;
  229. if (pProps)
  230. {
  231. free(pProps->LoggerName);
  232. free(pProps->LogFileName);
  233. }
  234. free(pProps);
  235. return ulResult;
  236. }