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.

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