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.

226 lines
4.3 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 StopTraceAPI
  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 // StopTrace API call return
  49. )
  50. {
  51. LPTSTR lpstrReturnedError = NULL;
  52. *pAPIReturn = -1;
  53. CLogger *pDetailLogger = NULL;
  54. int nResult = 0;
  55. // We only log if the test of "interest" is StopTrace.
  56. if (pstructTCOData->m_ulAPITest == TCOData::StopTraceTest)
  57. {
  58. nResult =
  59. OpenLogFiles
  60. (
  61. lpctstrTCODetailFile,
  62. pDetailLogger,
  63. &lpstrReturnedError
  64. );
  65. }
  66. if (FAILED(nResult))
  67. {
  68. delete pDetailLogger;
  69. // Open log files sets error string plpstrReturnedError.
  70. LogSummaryBeforeCall
  71. (
  72. pstructTCOData,
  73. lpctstrDataFile,
  74. lptstrAction,
  75. _T("StopTrace"),
  76. bLogExpected
  77. );
  78. LogSummaryAfterCall
  79. (
  80. pstructTCOData,
  81. lpctstrDataFile,
  82. lptstrAction,
  83. nResult,
  84. lpstrReturnedError,
  85. bLogExpected
  86. );
  87. free(lpstrReturnedError);
  88. lpstrReturnedError = NULL;
  89. return nResult;
  90. }
  91. // This is our log file.
  92. if (pDetailLogger)
  93. {
  94. pDetailLogger->LogTCHAR(_T("\n-------------------------------------------------------\n"));
  95. pDetailLogger->LogTCHAR(_T("StopTraceAPI TCO test "));
  96. pDetailLogger->Flush();
  97. }
  98. if (pDetailLogger)
  99. {
  100. pDetailLogger->LogTCHAR(pstructTCOData->m_lptstrShortDesc);
  101. int n = pDetailLogger->LogTCHAR(_T(" started at time "));
  102. time_t Time;
  103. time(&Time);
  104. pDetailLogger->LogTime(Time);
  105. pDetailLogger->LogTCHAR(_T(".\n"));
  106. pDetailLogger->Flush();
  107. }
  108. BOOL bAdmin = IsAdmin();
  109. if (pDetailLogger)
  110. {
  111. // Log argument values before calling StopTrace.
  112. LogDetailBeforeCall
  113. (
  114. pDetailLogger,
  115. pstructTCOData,
  116. bAdmin
  117. );
  118. }
  119. LogSummaryBeforeCall
  120. (
  121. pstructTCOData,
  122. lpctstrDataFile,
  123. lptstrAction,
  124. _T("StopTrace"),
  125. bLogExpected
  126. );
  127. *pAPIReturn =
  128. StopTrace
  129. (
  130. bUseTraceHandle ? *pstructTCOData->m_pTraceHandle : NULL,
  131. bUseTraceHandle ? NULL : pstructTCOData->m_lptstrInstanceName,
  132. pstructTCOData->m_pProps
  133. );
  134. ULONG ulResult = pstructTCOData->m_ulExpectedResult == *pAPIReturn ? ERROR_SUCCESS : -1;
  135. bool bValid = true;
  136. if (ulResult != ERROR_SUCCESS && *pAPIReturn == ERROR_SUCCESS )
  137. {
  138. ulResult = *pAPIReturn;
  139. }
  140. else if (*pAPIReturn != ERROR_SUCCESS)
  141. {
  142. lpstrReturnedError = DecodeStatus(*pAPIReturn);
  143. }
  144. else if (pstructTCOData->m_ulAPITest == TCOData::StopTraceTest &&
  145. pstructTCOData->m_lptstrValidator &&
  146. _tcslen(pstructTCOData->m_lptstrValidator) > 0)
  147. {
  148. CValidator Validator;
  149. bool bValid =
  150. Validator.Validate
  151. (
  152. pstructTCOData->m_pTraceHandle,
  153. pstructTCOData->m_lptstrInstanceName,
  154. pstructTCOData->m_pProps,
  155. pstructTCOData->m_lptstrValidator
  156. );
  157. if (!bValid)
  158. {
  159. ulResult = -1;
  160. lpstrReturnedError = NewTCHAR(_T("Validation routine failed."));
  161. }
  162. }
  163. if (pDetailLogger)
  164. {
  165. LogDetailAfterCall
  166. ( pDetailLogger,
  167. pstructTCOData,
  168. &pstructTCOData->m_pProps,
  169. *pAPIReturn,
  170. lpstrReturnedError,
  171. bValid,
  172. bAdmin
  173. );
  174. }
  175. LogSummaryAfterCall
  176. (
  177. pstructTCOData,
  178. lpctstrDataFile,
  179. lptstrAction,
  180. *pAPIReturn,
  181. lpstrReturnedError,
  182. bLogExpected
  183. );
  184. free(lpstrReturnedError);
  185. lpstrReturnedError = NULL;
  186. delete pDetailLogger;
  187. return ulResult;
  188. }