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.

305 lines
15 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: ntlog.h
  8. //
  9. //--------------------------------------------------------------------------
  10. /*---------------------------------------------------------------------------*\
  11. | NTLOG OBJECT
  12. | This module defines the NTLOG object. This header must be include in all
  13. | modules which make NTLOG calls, or utilizes the definitions.
  14. |
  15. |
  16. | Copyright (C) 1990-1994 Microsoft Corp.
  17. |
  18. | created: 01-Oct-90
  19. | history: 01-Oct-90 <chriswil> created.
  20. | 05-Feb-91 <chriswil> added NOPROLOG style.
  21. | 23-Feb-91 <chriswil> expanded log-flags to DWORD.
  22. | 28-May-91 <chriswil> added per-thread variation tracking.
  23. | 19-Mar-92 <chriswil> redefined struct for shared memory.
  24. | 10-Oct-92 <martys> added thread macros
  25. | 05-Oct-93 <chriswil> unicode enabled.
  26. | 10-Oct-96 (darrenf) fixed _FILE_ for unicode, added _NTLOG_LOGPATH handling
  27. |
  28. \*---------------------------------------------------------------------------*/
  29. // If doing C++ stuff, this needs to be here to
  30. // prevent decorating of symbols.
  31. //
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. // **NEW** 10/26/96 Log path environment variable **NEW**
  36. // if the environment variable _NTLOG_LOGPATH is set to a non-empty string
  37. // the value of this variable will be prepended to the log name
  38. // The path should NOT include a trailing backslash.
  39. // No validation is performed on the path, however, if the value is invalid,
  40. // the call to tlCreateLog will fail because CreateFile will fail.
  41. // Basically should be used to force logfiles to a location other than the current directory
  42. // without changing the source file.
  43. // **NEW** 1/20/97 environment variable to force diffable files **NEW**
  44. // if the environment variable _NTLOG_DIFFABLE is set, then log files
  45. // will not contain process and thread specific data, and time and date data.
  46. //
  47. // NTLOG STYLES
  48. // The folowing are logging levels in which the Log Object can prejudice
  49. // itself. These are used by the tlLogCreate() in initializing the
  50. // Log Object information. A combination of characteristics is obtained
  51. // by bitwise OR'ing these identifiers together.
  52. //
  53. #define LOG_LEVELS 0x0000FFFFL // These are used to mask out the
  54. #define LOG_STYLES 0xFFFF0000L // styles or levels from log object.
  55. #define TLS_LOGALL 0x0000FFFFL // Log output. Logs all the time.
  56. #define TLS_LOG 0x00000000L // Log output. Logs all the time.
  57. #define TLS_INFO 0x00002000L // Log information.
  58. #define TLS_ABORT 0x00000001L // Log Abort, then kill process.
  59. #define TLS_SEV1 0x00000002L // Log at Severity 1 level
  60. #define TLS_SEV2 0x00000004L // Log at Severity 2 level
  61. #define TLS_SEV3 0x00000008L // Log at Severity 3 level
  62. #define TLS_WARN 0x00000010L // Log at Warn level
  63. #define TLS_PASS 0x00000020L // Log at Pass level
  64. #define TLS_BLOCK 0x00000400L // Block the variation.
  65. #define TLS_BREAK 0x00000800L // Debugger break;
  66. #define TLS_CALLTREE 0x00000040L // Log call-tree (function tracking).
  67. #define TLS_SYSTEM 0x00000080L // Log System debug.
  68. #define TLS_TESTDEBUG 0x00001000L // Debug level.
  69. #define TLS_TEST 0x00000100L // Log Test information (user).
  70. #define TLS_VARIATION 0x00000200L // Log testcase level.
  71. #define TLS_REFRESH 0x00010000L // Create new file || trunc to zero.
  72. #define TLS_SORT 0x00020000L // Sort file output by instance.
  73. #define TLS_DEBUG 0x00040000L // Output to debug (com) monitor).
  74. #define TLS_MONITOR 0x00080000L // Output to 2nd screen.
  75. #define TLS_PROLOG 0x00200000L // Prolog line information.
  76. #define TLS_WINDOW 0x00400000L // Log to windows.
  77. #define TLS_ACCESSON 0x00800000L // Keep log-file open.
  78. #define TLS_DIFFABLE 0x01000000L // make log file windiff'able (no dates..)
  79. #define TLS_NOHEADER 0x02000000L // suppress headers so it is more diffable
  80. // NTLOG tlLogOut() PARAMETERS
  81. // The following defines are used in the tlLogOut() function to output the
  82. // filename and line numbers associated with the caller. This uses the
  83. // preprocessors capabilities for obtaining the file/line.
  84. //
  85. #define TL_LOG TLS_LOG ,TEXT(__FILE__),(int)__LINE__
  86. #define TL_ABORT TLS_ABORT ,TEXT(__FILE__),(int)__LINE__
  87. #define TL_SEV1 TLS_SEV1 ,TEXT(__FILE__),(int)__LINE__
  88. #define TL_SEV2 TLS_SEV2 ,TEXT(__FILE__),(int)__LINE__
  89. #define TL_SEV3 TLS_SEV3 ,TEXT(__FILE__),(int)__LINE__
  90. #define TL_WARN TLS_WARN ,TEXT(__FILE__),(int)__LINE__
  91. #define TL_PASS TLS_PASS ,TEXT(__FILE__),(int)__LINE__
  92. #define TL_BLOCK TLS_BLOCK ,TEXT(__FILE__),(int)__LINE__
  93. #define TL_INFO TLS_INFO ,TEXT(__FILE__),(int)__LINE__
  94. #define TL_BREAK TLS_BREAK ,TEXT(__FILE__),(int)__LINE__
  95. #define TL_CALLTREE TLS_CALLTREE ,TEXT(__FILE__),(int)__LINE__
  96. #define TL_SYSTEM TLS_SYSTEM ,TEXT(__FILE__),(int)__LINE__
  97. #define TL_TESTDEBUG TLS_TESTDEBUG,TEXT(__FILE__),(int)__LINE__
  98. #define TL_TEST TLS_TEST ,TEXT(__FILE__),(int)__LINE__
  99. #define TL_VARIATION TLS_VARIATION,TEXT(__FILE__),(int)__LINE__
  100. // NTLOG API (EXPORT METHODS)
  101. // These routines are exported from the library. These should be the only
  102. // interface with the NTLOG object.
  103. //
  104. HANDLE APIENTRY tlCreateLog_W(LPCWSTR,DWORD);
  105. HANDLE APIENTRY tlCreateLog_A(LPCSTR,DWORD);
  106. BOOL APIENTRY tlDestroyLog(HANDLE);
  107. BOOL APIENTRY tlAddParticipant(HANDLE,DWORD,int);
  108. BOOL APIENTRY tlRemoveParticipant(HANDLE);
  109. DWORD APIENTRY tlParseCmdLine_W(LPCWSTR);
  110. DWORD APIENTRY tlParseCmdLine_A(LPCSTR);
  111. int APIENTRY tlGetLogFileName_W(HANDLE,LPWSTR);
  112. int APIENTRY tlGetLogFileName_A(HANDLE,LPSTR);
  113. BOOL APIENTRY tlSetLogFileName_W(HANDLE,LPCWSTR);
  114. BOOL APIENTRY tlSetLogFileName_A(HANDLE,LPCSTR);
  115. DWORD APIENTRY tlGetLogInfo(HANDLE);
  116. DWORD APIENTRY tlSetLogInfo(HANDLE,DWORD);
  117. HANDLE APIENTRY tlPromptLog(HWND,HANDLE);
  118. int APIENTRY tlGetTestStat(HANDLE,DWORD);
  119. int APIENTRY tlGetVariationStat(HANDLE,DWORD);
  120. VOID APIENTRY tlClearTestStats(HANDLE);
  121. VOID APIENTRY tlClearVariationStats(HANDLE);
  122. BOOL APIENTRY tlStartVariation(HANDLE);
  123. DWORD APIENTRY tlEndVariation(HANDLE);
  124. VOID APIENTRY tlReportStats(HANDLE);
  125. BOOL APIENTRY tlLogX_W(HANDLE,DWORD,LPCWSTR,int,LPCWSTR);
  126. BOOL APIENTRY tlLogX_A(HANDLE,DWORD,LPCSTR,int,LPCSTR);
  127. BOOL FAR cdecl tlLog_W(HANDLE,DWORD,LPCWSTR,int,LPCWSTR,...);
  128. BOOL FAR cdecl tlLog_A(HANDLE,DWORD,LPCSTR,int,LPCSTR,...);
  129. #ifdef UNICODE
  130. #define tlCreateLog tlCreateLog_W
  131. #define tlParseCmdLine tlParseCmdLine_W
  132. #define tlGetLogFileName tlGetLogFileName_W
  133. #define tlSetLogFileName tlSetLogFileName_W
  134. #define tlLogX tlLogX_W
  135. #define tlLog tlLog_W
  136. #else
  137. #define tlCreateLog tlCreateLog_A
  138. #define tlParseCmdLine tlParseCmdLine_A
  139. #define tlGetLogFileName tlGetLogFileName_A
  140. #define tlSetLogFileName tlSetLogFileName_A
  141. #define tlLogX tlLogX_A
  142. #define tlLog tlLog_A
  143. #endif
  144. // RATS MACROS
  145. // These macros are provided as a common logging interface which is
  146. // compatible with the RATS logging-macros.
  147. //
  148. #define TESTDATA HANDLE hLog;
  149. #define TESTOTHERDATA extern HANDLE hLog;
  150. // These must be useless. TL_* macros do not include TLS_TEST or
  151. // TLS_VARIATION, so they DO NOT count in the stats. Leaving them around
  152. // for 'backwards compatibility, if anyone was actually using them...
  153. //
  154. #define L_PASS hLog,TL_PASS
  155. #define L_WARN hLog,TL_WARN
  156. #define L_DEBUG hLog,TL_TESTDEBUG
  157. #define L_TRACE hLog,TL_SYSTEM
  158. #define L_FAIL hLog,TL_SEV1
  159. #define L_FAIL2 hLog,TL_SEV2
  160. #define L_FAIL3 hLog,TL_SEV3
  161. #define L_BLOCK hLog,TL_BLOCK
  162. // macros for incrementing test/variation counts for various log levels
  163. //
  164. #define L_TESTPASS hLog,TLS_TEST | TL_PASS
  165. #define L_TESTWARN hLog,TLS_TEST | TL_WARN
  166. #define L_TESTDEBUG hLog,TLS_TEST | TL_TESTDEBUG
  167. #define L_TESTTRACE hLog,TLS_TEST | TL_SYSTEM
  168. #define L_TESTFAIL hLog,TLS_TEST | TL_SEV1
  169. #define L_TESTFAIL2 hLog,TLS_TEST | TL_SEV2
  170. #define L_TESTFAIL3 hLog,TLS_TEST | TL_SEV3
  171. #define L_TESTBLOCK hLog,TLS_TEST | TL_BLOCK
  172. #define L_TESTABORT hLog,TLS_TEST | TL_ABORT
  173. #define L_VARPASS hLog,TLS_VARIATION | TL_PASS
  174. #define L_VARWARN hLog,TLS_VARIATION | TL_WARN
  175. #define L_VARDEBUG hLog,TLS_VARIATION | TL_TESTDEBUG
  176. #define L_VARTRACE hLog,TLS_VARIATION | TL_SYSTEM
  177. #define L_VARFAIL hLog,TLS_VARIATION | TL_SEV1
  178. #define L_VARFAIL2 hLog,TLS_VARIATION | TL_SEV2
  179. #define L_VARFAIL3 hLog,TLS_VARIATION | TL_SEV3
  180. #define L_VARBLOCK hLog,TLS_VARIATION | TL_BLOCK
  181. #define L_VARABORT hLog,TLS_VARIATION | TL_ABORT
  182. #define TESTBEGIN(cmd,logfilename){ \
  183. DWORD __tlFlags; \
  184. __tlFlags = tlParseCmdLine(cmd); \
  185. hLog = tlCreateLog(logfilename,__tlFlags); \
  186. tlAddParticipant(hLog,0l,0);
  187. #define TESTEND tlRemoveParticipant(hLog); \
  188. tlDestroyLog(hLog); \
  189. }
  190. #define VARIATION(name,flags) if(tlStartVariation(hLog)) \
  191. { \
  192. DWORD __dwResult; \
  193. tlLog(hLog,TL_VARIATION,TEXT("%s"),(LPTSTR)name);
  194. #define ENDVARIATION __dwResult = tlEndVariation(hLog); \
  195. tlLog(hLog,__dwResult | TL_VARIATION,TEXT("End Variation reported")); \
  196. }
  197. #define ENTERTHREAD(_hLG,_szNM) { \
  198. LPTSTR _lpFN = _szNM; \
  199. tlAddParticipant(_hLG,0,0); \
  200. tlLog(_hLG,TL_CALLTREE,TEXT("Entering %s()"),(LPTSTR)_lpFN);
  201. #define LEAVETHREAD(_hLG,_ret) \
  202. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  203. tlRemoveParticipant(_hLG); \
  204. return(_ret); \
  205. }
  206. #define LEAVETHREADVOID(_hLG) \
  207. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  208. tlRemoveParticipant(_hLG); \
  209. return; \
  210. }
  211. // Macro to report variation PASS/FAIL statistic (based on an expression)
  212. //
  213. #define THPRINTF tlLog
  214. #define TESTRESULT(expr,msg) (expr) ? tlLog(L_TESTPASS,TEXT("%s"),(LPTSTR)msg) : tlLog(L_TESTFAIL2,TEXT("%s"),(LPTSTR)msg)
  215. #define TESTFAIL(msg) TESTSEV2(msg)
  216. #define TESTSEV1(msg) tlLog(L_TESTFAIL ,TEXT("%s"),(LPTSTR)msg);
  217. #define TESTSEV2(msg) tlLog(L_TESTFAIL2,TEXT("%s"),(LPTSTR)msg);
  218. #define TESTSEV3(msg) tlLog(L_TESTFAIL3,TEXT("%s"),(LPTSTR)msg);
  219. #define TESTPASS(msg) tlLog(L_TESTPASS ,TEXT("%s"),(LPTSTR)msg);
  220. #define TESTABORT(msg) tlLog(L_TESTABORT,TEXT("%s"),(LPTSTR)msg);
  221. #define TESTWARN(expr,msg) if(expr) tlLog(L_TESTWARN,TEXT("%s"),(LPTSTR)msg);
  222. #define TESTBLOCK(expr,msg) if(expr) tlLog(L_TESTBLOCK,TEXT("%s"),(LPTSTR)msg);
  223. #define VARRESULT(expr,msg) (expr) ? tlLog(L_VARPASS,TEXT("%s"),(LPTSTR)msg) : tlLog(L_VARFAIL2,TEXT("%s"),(LPTSTR)msg)
  224. #define VARFAIL(msg) VARSEV2(msg)
  225. #define VARSEV1(msg) tlLog(L_VARFAIL ,TEXT("%s"),(LPTSTR)msg);
  226. #define VARSEV2(msg) tlLog(L_VARFAIL2,TEXT("%s"),(LPTSTR)msg);
  227. #define VARSEV3(msg) tlLog(L_VARFAIL3,TEXT("%s"),(LPTSTR)msg);
  228. #define VARPASS(msg) tlLog(L_VARPASS ,TEXT("%s"),(LPTSTR)msg);
  229. #define VARABORT(msg) tlLog(L_VARABORT,TEXT("%s"),(LPTSTR)msg);
  230. #define VARWARN(expr,msg) if(expr) tlLog(L_VARWARN,TEXT("%s"),(LPTSTR)msg);
  231. #define VARBLOCK(expr,msg) if(expr) tlLog(L_VARBLOCK,TEXT("%s"),(LPTSTR)msg);
  232. #define VAR_SI 0x01 // Ship Issue
  233. #define VAR_NSI 0x02 // Non-ship Issue
  234. #define VAR_LI 0x03 // Less Important
  235. #define VAR_ISSUE_MASK 0x03 // To get ship-issue bits only
  236. #define VAR_TIMEABLE 0x04 // Var. used in timing suites
  237. #define CORE_API 0x08 // API is in most used list
  238. #define CORE_SI (CORE_API | VAR_TIMEABLE | VAR_SI ) //
  239. #define CORE_NSI (CORE_API | VAR_TIMEABLE | VAR_NSI) //
  240. #define NONCORE_SI (VAR_TIMEABLE | VAR_SI ) //
  241. #define NONCORE_NSI (VAR_TIMEABLE | VAR_NSI) //
  242. // CALLTREE Macros
  243. // These macros are useful for bracketing function-calls.
  244. //
  245. #define ENTER(_hLG,_szNM) { \
  246. LPTSTR _lpFN = _szNM; \
  247. tlLog(_hLG,TL_CALLTREE,TEXT("Entering %s()"),(LPTSTR)_lpFN);
  248. #define LEAVE(_hLG,_ret) \
  249. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  250. return(_ret); \
  251. }
  252. #define LEAVEVOID(_hLG) \
  253. tlLog(_hLG,TL_CALLTREE,TEXT("Exiting %s()"),(LPTSTR)_lpFN); \
  254. return; \
  255. }
  256. #ifdef __cplusplus
  257. }
  258. #endif