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.

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