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.

224 lines
12 KiB

  1. /*---------------------------------------------------------------------------*\
  2. | NTLOG OBJECT
  3. | This module defines the NTLOG object. This header must be include in all
  4. | modules which make NTLOG calls, or utilizes the definitions.
  5. |
  6. |
  7. | Copyright (C) 1990-1994 Microsoft Corp.
  8. |
  9. | created: 01-Oct-90
  10. | history: 01-Oct-90 <chriswil> created.
  11. | 05-Feb-91 <chriswil> added NOPROLOG style.
  12. | 23-Feb-91 <chriswil> expanded log-flags to DWORD.
  13. | 28-May-91 <chriswil> added per-thread variation tracking.
  14. | 19-Mar-92 <chriswil> redefined struct for shared memory.
  15. | 10-Oct-92 <martys> added thread macros
  16. | 05-Oct-93 <chriswil> unicode enabled.
  17. |
  18. \*---------------------------------------------------------------------------*/
  19. // NTLOG STYLES
  20. // The folowing are logging levels in which the Log Object can prejudice
  21. // itself. These are used by the tlLogCreate() in initializing the
  22. // Log Object information. A combination of characteristics is obtained
  23. // by bitwise OR'ing these identifiers together.
  24. //
  25. #define LOG_LEVELS 0x0000FFFFL // These are used to mask out the
  26. #define LOG_STYLES 0xFFFF0000L // styles or levels from log object.
  27. #define TLS_LOGALL 0x0000FFFFL // Log output. Logs all the time.
  28. #define TLS_LOG 0x00000000L // Log output. Logs all the time.
  29. #define TLS_INFO 0x00002000L // Log information.
  30. #define TLS_ABORT 0x00000001L // Log Abort, then kill process.
  31. #define TLS_SEV1 0x00000002L // Log at Severity 1 level
  32. #define TLS_SEV2 0x00000004L // Log at Severity 2 level
  33. #define TLS_SEV3 0x00000008L // Log at Severity 3 level
  34. #define TLS_WARN 0x00000010L // Log at Warn level
  35. #define TLS_PASS 0x00000020L // Log at Pass level
  36. #define TLS_BLOCK 0x00000400L // Block the variation.
  37. #define TLS_BREAK 0x00000800L // Debugger break;
  38. #define TLS_CALLTREE 0x00000040L // Log call-tree (function tracking).
  39. #define TLS_SYSTEM 0x00000080L // Log System debug.
  40. #define TLS_TESTDEBUG 0x00001000L // Debug level.
  41. #define TLS_TEST 0x00000100L // Log Test information (user).
  42. #define TLS_VARIATION 0x00000200L // Log testcase level.
  43. #define TLS_REFRESH 0x00010000L // Create new file || trunc to zero.
  44. #define TLS_SORT 0x00020000L // Sort file output by instance.
  45. #define TLS_DEBUG 0x00040000L // Output to debug (com) monitor).
  46. #define TLS_MONITOR 0x00080000L // Output to 2nd screen.
  47. #define TLS_PROLOG 0x00200000L // Prolog line information.
  48. #define TLS_WINDOW 0x00400000L // Log to windows.
  49. #define TLS_ACCESSON 0x00800000L // Keep log-file open.
  50. // NTLOG tlLogOut() PARAMETERS
  51. // The following defines are used in the tlLogOut() function to output the
  52. // filename and line numbers associated with the caller. This uses the
  53. // preprocessors capabilities for obtaining the file/line.
  54. //
  55. #define TL_LOG TLS_LOG ,(LPTSTR)__FILE__,(int)__LINE__
  56. #define TL_ABORT TLS_ABORT ,(LPTSTR)__FILE__,(int)__LINE__
  57. #define TL_SEV1 TLS_SEV1 ,(LPTSTR)__FILE__,(int)__LINE__
  58. #define TL_SEV2 TLS_SEV2 ,(LPTSTR)__FILE__,(int)__LINE__
  59. #define TL_SEV3 TLS_SEV3 ,(LPTSTR)__FILE__,(int)__LINE__
  60. #define TL_WARN TLS_WARN ,(LPTSTR)__FILE__,(int)__LINE__
  61. #define TL_PASS TLS_PASS ,(LPTSTR)__FILE__,(int)__LINE__
  62. #define TL_BLOCK TLS_BLOCK ,(LPTSTR)__FILE__,(int)__LINE__
  63. #define TL_INFO TLS_INFO ,(LPTSTR)__FILE__,(int)__LINE__
  64. #define TL_BREAK TLS_BREAK ,(LPTSTR)__FILE__,(int)__LINE__
  65. #define TL_CALLTREE TLS_CALLTREE ,(LPTSTR)__FILE__,(int)__LINE__
  66. #define TL_SYSTEM TLS_SYSTEM ,(LPTSTR)__FILE__,(int)__LINE__
  67. #define TL_TESTDEBUG TLS_TESTDEBUG,(LPTSTR)__FILE__,(int)__LINE__
  68. #define TL_TEST TLS_TEST ,(LPTSTR)__FILE__,(int)__LINE__
  69. #define TL_VARIATION TLS_VARIATION,(LPTSTR)__FILE__,(int)__LINE__
  70. // NTLOG API (EXPORT METHODS)
  71. // These routines are exported from the library. These should be the only
  72. // interface with the NTLOG object.
  73. //
  74. HANDLE APIENTRY tlCreateLog_W(LPWSTR,DWORD);
  75. HANDLE APIENTRY tlCreateLog_A(LPSTR,DWORD);
  76. BOOL APIENTRY tlDestroyLog(HANDLE);
  77. BOOL APIENTRY tlAddParticipant(HANDLE,DWORD,int);
  78. BOOL APIENTRY tlRemoveParticipant(HANDLE);
  79. DWORD APIENTRY tlParseCmdLine_W(LPWSTR);
  80. DWORD APIENTRY tlParseCmdLine_A(LPSTR);
  81. int APIENTRY tlGetLogFileName_W(HANDLE,LPWSTR);
  82. int APIENTRY tlGetLogFileName_A(HANDLE,LPSTR);
  83. BOOL APIENTRY tlSetLogFileName_W(HANDLE,LPWSTR);
  84. BOOL APIENTRY tlSetLogFileName_A(HANDLE,LPSTR);
  85. DWORD APIENTRY tlGetLogInfo(HANDLE);
  86. DWORD APIENTRY tlSetLogInfo(HANDLE,DWORD);
  87. HANDLE APIENTRY tlPromptLog(HWND,HANDLE);
  88. int APIENTRY tlGetTestStat(HANDLE,DWORD);
  89. int APIENTRY tlGetVariationStat(HANDLE,DWORD);
  90. VOID APIENTRY tlClearTestStats(HANDLE);
  91. VOID APIENTRY tlClearVariationStats(HANDLE);
  92. BOOL APIENTRY tlStartVariation(HANDLE);
  93. DWORD APIENTRY tlEndVariation(HANDLE);
  94. VOID APIENTRY tlReportStats(HANDLE);
  95. BOOL APIENTRY tlLogX_W(HANDLE,DWORD,LPWSTR,int,LPWSTR);
  96. BOOL APIENTRY tlLogX_A(HANDLE,DWORD,LPSTR,int,LPSTR);
  97. BOOL FAR cdecl tlLog_W(HANDLE,DWORD,LPWSTR,int,LPWSTR,...);
  98. BOOL FAR cdecl tlLog_A(HANDLE,DWORD,LPSTR,int,LPSTR,...);
  99. #ifdef UNICODE
  100. #define tlCreateLog tlCreateLog_W
  101. #define tlParseCmdLine tlParseCmdLine_W
  102. #define tlGetLogFileName tlGetLogFileName_W
  103. #define tlSetLogFileName tlSetLogFileName_W
  104. #define tlLogX tlLogX_W
  105. #define tlLog tlLog_W
  106. #else
  107. #define tlCreateLog tlCreateLog_A
  108. #define tlParseCmdLine tlParseCmdLine_A
  109. #define tlGetLogFileName tlGetLogFileName_A
  110. #define tlSetLogFileName tlSetLogFileName_A
  111. #define tlLogX tlLogX_A
  112. #define tlLog tlLog_A
  113. #endif
  114. // RATS MACROS
  115. // These macros are provided as a common logging interface which is
  116. // compatible with the RATS logging-macros.
  117. //
  118. #define L_PASS hLog,TL_PASS
  119. #define L_WARN hLog,TL_WARN
  120. #define L_DEBUG hLog,TL_TESTDEBUG
  121. #define L_TRACE hLog,TL_SYSTEM
  122. #define L_FAIL hLog,TL_SEV1
  123. #define L_FAIL2 hLog,TL_SEV2
  124. #define L_FAIL3 hLog,TL_SEV3
  125. #define L_BLOCK hLog,TL_BLOCK
  126. #define TESTDATA HANDLE hLog;
  127. #define TESTOTHERDATA extern HANDLE hLog;
  128. #define TESTBEGIN(cmd) TCHAR log[100]; \
  129. DWORD tlFlags; \
  130. tlFlags = tlParseCmdLine(cmd,log); \
  131. hLog = tlCreateLog(log,tlFlags); \
  132. tlAddParticipant(hLog,0,0);
  133. #define TESTEND tlRemoveParticipant(hLog); \
  134. tlDestroyLog(hLog);
  135. #define VARIATION(name,flags) if(tlStartVariation(hLog)) \
  136. { \
  137. DWORD dwResult; \
  138. tlLog(hLog,TL_VARIATION,TEXT("%s"),(LPTSTR)name);
  139. #define ENDVARIATION dwResult = tlEndVariation(hLog); \
  140. tlLog(hLog,dwResult | TL_VARIATION,TEXT("End Variation reported")); \
  141. }
  142. #define ENTERTHREAD(_hLG,_szNM) { \
  143. LPTSTR _lpFN = _szNM; \
  144. tlAddParticipant(_hLG,0,0); \
  145. tlLog(_hLG,TL_CALLTREE,TEXT("Entering %s()"),(LPTSTR)_lpFN);
  146. #define LEAVETHREAD(_hLG,_ret) \
  147. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  148. tlRemoveParticipant(_hLG); \
  149. return(_ret); \
  150. }
  151. #define LEAVETHREADVOID(_hLG) \
  152. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  153. tlRemoveParticipant(_hLG); \
  154. return; \
  155. }
  156. // Macro to report variation PASS/FAIL statistic (based on an expression)
  157. //
  158. #define THPRINTF tlLog
  159. #define TESTRESULT(expr,msg) tlLog((expr ? L_PASS : L_FAIL),TEXT("%s"),(LPTSTR)msg);
  160. #define TESTFAIL(msg) TESTSEV2(msg)
  161. #define TESTSEV1(msg) tlLog(L_FAIL ,TEXT("%s"),(LPTSTR)msg);
  162. #define TESTSEV2(msg) tlLog(L_FAIL2,TEXT("%s"),(LPTSTR)msg);
  163. #define TESTSEV3(msg) tlLog(L_FAIL3,TEXT("%s"),(LPTSTR)msg);
  164. #define TESTPASS(msg) tlLog(L_PASS ,TEXT("%s"),(LPTSTR)msg);
  165. #define TESTWARN(expr,msg) if(expr) tlLog(L_WARN,TEXT("%s"),(LPTSTR)msg);
  166. #define TESTBLOCK(expr,msg) if(expr) tlLog(L_BLOCK,TEXT("%s"),(LPTSTR)msg);
  167. #define VAR_SI 0x01 // Ship Issue
  168. #define VAR_NSI 0x02 // Non-ship Issue
  169. #define VAR_LI 0x03 // Less Important
  170. #define VAR_ISSUE_MASK 0x03 // To get ship-issue bits only
  171. #define VAR_TIMEABLE 0x04 // Var. used in timing suites
  172. #define CORE_API 0x08 // API is in most used list
  173. #define CORE_SI (CORE_API | VAR_TIMEABLE | VAR_SI ) //
  174. #define CORE_NSI (CORE_API | VAR_TIMEABLE | VAR_NSI) //
  175. #define NONCORE_SI (VAR_TIMEABLE | VAR_SI ) //
  176. #define NONCORE_NSI (VAR_TIMEABLE | VAR_NSI) //
  177. // CALLTREE Macros
  178. // These macros are useful for bracketing function-calls.
  179. //
  180. #define ENTER(_hLG,_szNM) { \
  181. LPTSTR _lpFN = _szNM; \
  182. tlLog(_hLG,TL_CALLTREE,TEXT("Entering %s()"),(LPTSTR)_lpFN);
  183. #define LEAVE(_hLG,_ret) \
  184. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  185. return(_ret); \
  186. }
  187. #define LEAVEVOID(_hLG) \
  188. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  189. return; \
  190. }