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.

266 lines
5.2 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 "Persistor.h"
  32. #include "Logger.h"
  33. #include "TCOData.h"
  34. #include "Utilities.h"
  35. #include "StructureWrappers.h"
  36. #include "StructureWapperHelpers.h"
  37. #include "ConstantMap.h"
  38. #include "TCOData.h"
  39. #include "Logger.h"
  40. #include "Validator.h"
  41. #include "CollectionControl.h"
  42. int UpdateTraceAPI
  43. (
  44. IN LPTSTR lptstrAction, // For logging only.
  45. IN LPCTSTR lpctstrDataFile, // For logging only.
  46. IN LPCTSTR lpctstrTCODetailFile, // If valid we will log to it, can be NULL.
  47. IN bool bLogExpected, // If true we log expected vs actual result.
  48. IN bool bUseTraceHandle, // If true use the handle.
  49. IN OUT TCOData *pstructTCOData, // TCO test data.
  50. OUT int *pAPIReturn // UpdateTrace API call return
  51. )
  52. {
  53. LPTSTR lptstrReturnedError = NULL;
  54. *pAPIReturn = -1;
  55. CLogger *pDetailLogger = NULL;
  56. int nResult = 0;
  57. // We only log if the test of "interest" is UpdateTrace.
  58. if (pstructTCOData->m_ulAPITest == TCOData::UpdateTraceTest)
  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 lptstrReturnedError.
  72. LogSummaryBeforeCall
  73. (
  74. pstructTCOData,
  75. lpctstrDataFile,
  76. lptstrAction,
  77. _T("StopTrace"),
  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("UpdateTraceAPI 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. LogSummaryBeforeCall
  124. (
  125. pstructTCOData,
  126. lpctstrDataFile,
  127. lptstrAction,
  128. _T("UpdateTrace"),
  129. bLogExpected
  130. );
  131. *pAPIReturn =
  132. ControlTrace
  133. (
  134. bUseTraceHandle ? *pstructTCOData->m_pTraceHandle : NULL,
  135. bUseTraceHandle ? NULL : pstructTCOData->m_lptstrInstanceName,
  136. pProps,
  137. EVENT_TRACE_CONTROL_UPDATE
  138. );
  139. ULONG ulResult = pstructTCOData->m_ulExpectedResult == *pAPIReturn ? ERROR_SUCCESS : -1;
  140. if (ulResult != ERROR_SUCCESS && *pAPIReturn == ERROR_SUCCESS)
  141. {
  142. ulResult = *pAPIReturn;
  143. }
  144. else if (*pAPIReturn != ERROR_SUCCESS)
  145. {
  146. lptstrReturnedError = DecodeStatus(*pAPIReturn);
  147. }
  148. else if (pstructTCOData->m_ulAPITest == TCOData::UpdateTraceTest &&
  149. pstructTCOData->m_lptstrValidator &&
  150. _tcslen(pstructTCOData->m_lptstrValidator) > 0)
  151. {
  152. CValidator Validator;
  153. bool bValid =
  154. Validator.Validate
  155. (
  156. pstructTCOData->m_pTraceHandle,
  157. pstructTCOData->m_lptstrInstanceName,
  158. pstructTCOData->m_pProps,
  159. pstructTCOData->m_lptstrValidator
  160. );
  161. if (!bValid)
  162. {
  163. ulResult = -1;
  164. lptstrReturnedError = NewTCHAR(_T("Validation routine failed."));
  165. }
  166. }
  167. bool bDiff =
  168. LogPropsDiff
  169. (
  170. NULL,
  171. pstructTCOData->m_pProps,
  172. pProps
  173. );
  174. // If there were differences and
  175. // *pAPIReturn == ERROR_SUCCESS == pstructTCOData->m_ulExpectedResult
  176. // we need to set return codes to indicate differences. Look in detail
  177. // log for differences.
  178. if (bDiff &&
  179. *pAPIReturn == ERROR_SUCCESS &&
  180. pstructTCOData->m_ulExpectedResult == ERROR_SUCCESS)
  181. {
  182. free (lptstrReturnedError);
  183. lptstrReturnedError = NULL;
  184. *pAPIReturn = -1;
  185. lptstrReturnedError =
  186. NewTCHAR(_T("Different values returned in EVENT_TRACE_PROPERTIES structure."));
  187. }
  188. if (pDetailLogger)
  189. {
  190. LogDetailAfterCall
  191. ( pDetailLogger,
  192. pstructTCOData,
  193. &pProps,
  194. *pAPIReturn,
  195. lptstrReturnedError,
  196. true,
  197. bAdmin
  198. );
  199. }
  200. LogPropsDiff
  201. (
  202. pDetailLogger,
  203. pstructTCOData->m_pProps,
  204. pProps
  205. );
  206. LogSummaryAfterCall
  207. (
  208. pstructTCOData,
  209. lpctstrDataFile,
  210. lptstrAction,
  211. *pAPIReturn,
  212. lptstrReturnedError,
  213. bLogExpected
  214. );
  215. delete pDetailLogger;
  216. free(lptstrReturnedError);
  217. lptstrReturnedError = NULL;
  218. if (pProps)
  219. {
  220. free(pProps->LoggerName);
  221. free(pProps->LogFileName);
  222. }
  223. free(pProps);
  224. return ulResult;
  225. }