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.

270 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. vststntlog.cxx
  5. Abstract:
  6. Wrapper class for the test team's ntlog suite of APIs and VolSnap test harness.
  7. Author:
  8. Stefan R. Steiner [ssteiner] 06-05-2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "ntlog.h"
  13. #include "vststntlog.hxx"
  14. #define VS_TST_NT_LOG_INFO_LEVELS_AND_STYLES \
  15. TLS_INFO | TLS_WARN | TLS_SEV2 | TLS_PASS | TLS_VARIATION | TLS_REFRESH | TLS_TEST
  16. /*++
  17. Routine Description:
  18. Constructor for the CVsTstNtLog class
  19. Arguments:
  20. None
  21. --*/
  22. CVsTstNtLog::CVsTstNtLog(
  23. IN LPCWSTR pwszLogFileName
  24. ) : m_cwsNtLogFileName( pwszLogFileName ),
  25. m_hNtLog( NULL ),
  26. m_bInVariation( FALSE ),
  27. m_dwHighestLogLev( TLS_PASS )
  28. {
  29. //
  30. // Create the NtLog log file
  31. //
  32. m_hNtLog = ::tlCreateLog( m_cwsNtLogFileName.c_str(),
  33. VS_TST_NT_LOG_INFO_LEVELS_AND_STYLES );
  34. if ( m_hNtLog == NULL )
  35. VSTST_THROW( HRESULT_FROM_WIN32( ::GetLastError() ) ) ;
  36. //
  37. // Add this thread as a participant
  38. //
  39. AddParticipant();
  40. }
  41. /*++
  42. Routine Description:
  43. Destructor for the CVsTstNtLog class
  44. Arguments:
  45. None
  46. --*/
  47. CVsTstNtLog::~CVsTstNtLog()
  48. {
  49. if ( m_hNtLog != NULL )
  50. {
  51. //
  52. // If we are still in a variation, end it
  53. //
  54. if ( m_bInVariation )
  55. EndVariation();
  56. //
  57. // Specify that the test is finished
  58. //
  59. ::tlLog_W( m_hNtLog, m_dwHighestLogLev | TL_TEST,
  60. L"Test finished, highest test log-lev: %d",
  61. m_dwHighestLogLev );
  62. //
  63. // Report test stats
  64. //
  65. ::tlReportStats( m_hNtLog );
  66. //
  67. // Remove main thread as a participant
  68. //
  69. ::tlRemoveParticipant( m_hNtLog );
  70. //
  71. // Destroy the log object
  72. //
  73. ::tlDestroyLog( m_hNtLog );
  74. m_hNtLog = INVALID_HANDLE_VALUE;
  75. }
  76. }
  77. /*++
  78. Routine Description:
  79. When a new thread needs access to this logging object, this function
  80. needs to be called.
  81. Arguments:
  82. None
  83. Return Value:
  84. <Enter return values here>
  85. --*/
  86. VOID
  87. CVsTstNtLog::AddParticipant()
  88. {
  89. if ( !::tlAddParticipant( m_hNtLog, 0, 0 ) )
  90. VSTST_THROW( E_UNEXPECTED );
  91. //
  92. // This next part is kind of a hack to make sure the new participant has
  93. // a variation started. This code needs to be changed when the coordinator
  94. // is able to get it's message thread to start a variation.
  95. //
  96. if ( !m_cwsVariationName.IsEmpty() )
  97. if ( !::tlStartVariation( m_hNtLog ) )
  98. VSTST_THROW( E_UNEXPECTED );
  99. Log( eSevLev_Info, L"Participant added, thread id: 0x%04x", ::GetCurrentThreadId() );
  100. }
  101. /*++
  102. Routine Description:
  103. When a thread is finished accessing this logging object, this function may
  104. be called. The thread which created the object doesn't need to call this
  105. function since it is done in the destructor.
  106. Arguments:
  107. None
  108. Return Value:
  109. <Enter return values here>
  110. --*/
  111. VOID
  112. CVsTstNtLog::RemoveParticipant()
  113. {
  114. ::tlRemoveParticipant( m_hNtLog );
  115. Log( eSevLev_Info, L"Participant removed, thread id: 0x%04x", ::GetCurrentThreadId() );
  116. }
  117. /*++
  118. Routine Description:
  119. Call this function when a thread wants to start a new variation.
  120. Arguments:
  121. None
  122. Return Value:
  123. <Enter return values here>
  124. --*/
  125. VOID
  126. CVsTstNtLog::StartVariation(
  127. IN LPCWSTR pwszVariationName
  128. )
  129. {
  130. if ( m_bInVariation )
  131. EndVariation();
  132. m_cwsVariationName = pwszVariationName;
  133. if ( !::tlStartVariation( m_hNtLog ) )
  134. VSTST_THROW( E_UNEXPECTED );
  135. m_bInVariation = TRUE;
  136. Log( eSevLev_Info, L"Variation '%s' started", m_cwsVariationName.c_str() );
  137. }
  138. /*++
  139. Routine Description:
  140. Call this when a thread is finished with a variation.
  141. Arguments:
  142. None
  143. Return Value:
  144. Returns the most severe log-level encountered during the variation.
  145. --*/
  146. DWORD
  147. CVsTstNtLog::EndVariation()
  148. {
  149. DWORD dwMostSevereLev;
  150. dwMostSevereLev = ::tlEndVariation( m_hNtLog );
  151. ::tlLog_W( m_hNtLog, dwMostSevereLev | TL_VARIATION,
  152. L"Variation '%s' ended, highest log-lev: %d",
  153. m_cwsVariationName.c_str(), dwMostSevereLev );
  154. m_bInVariation = FALSE;
  155. m_cwsVariationName.Empty();
  156. return dwMostSevereLev;
  157. }
  158. VOID
  159. CVsTstNtLog::Log(
  160. IN EVsTstNtLogSeverityLevel eSevLev,
  161. IN LPCWSTR pwszFormat,
  162. IN ...
  163. )
  164. {
  165. va_list marker;
  166. va_start( marker, pwszFormat );
  167. CBsString cwsFormatted;
  168. cwsFormatted.FormatV( pwszFormat, marker );
  169. va_end( marker );
  170. DWORD dwStyle;
  171. switch( eSevLev )
  172. {
  173. case eSevLev_Info: dwStyle = TLS_INFO; break;
  174. case eSevLev_Pass: dwStyle = TLS_PASS; break;
  175. case eSevLev_Warning: dwStyle = TLS_WARN; break;
  176. case eSevLev_Severe: dwStyle = TLS_SEV2; break;
  177. default:
  178. VSTST_THROW( E_FAIL );
  179. }
  180. if ( m_dwHighestLogLev > dwStyle )
  181. m_dwHighestLogLev = dwStyle;
  182. if ( m_bInVariation )
  183. dwStyle |= TLS_VARIATION;
  184. else
  185. dwStyle |= TLS_TEST;
  186. ::tlLog_W( m_hNtLog, dwStyle, TEXT( __FILE__ ), (int)__LINE__, L"%s", cwsFormatted.c_str() );
  187. }