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.

175 lines
4.1 KiB

  1. /*--
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. STWLog.w (generates stwlog.h)
  5. Abstract:
  6. Setup Test Wrapper logging function for use by testing running as part of IDWLog process
  7. Author:
  8. Mark Freeman (mfree)
  9. Revision History:
  10. Created on 15-Jan-2002
  11. Contains these functions:
  12. VOID STWLog ( TCHAR * lpTestName, TCHAR * lpTestOwner, DWORD dwLevel, TCHAR * lpTestOutput )
  13. --*/
  14. #define LOG_INFO 0
  15. #define LOG_TEST_PASS 1
  16. #define LOG_TEST_FAILURE 2
  17. #define LOG_FATAL_ERROR 3
  18. #define LOG_NEW 9
  19. TCHAR szLogDirectory[MAX_PATH];
  20. /*
  21. Logging function to be used by tests under the control of STWrap
  22. Required Parameters:( TCHAR * lpTestName, TCHAR * lpTestOwner, DWORD dwLevel, TCHAR * lpTestOutput )
  23. Return Value: NONE
  24. Created: 15-Nov-2001 Mark Freeman (mfree)
  25. */
  26. VOID STWLog ( TCHAR * lpTestName, TCHAR * lpTestOwner, DWORD dwLevel, TCHAR * lpTestOutput ) {
  27. FILE* fpTestLogFile;
  28. TCHAR szTestLogFileAndPath[MAX_PATH];
  29. TCHAR szLogLevel[16];
  30. TCHAR szTestOutput[MAX_PATH];
  31. TCHAR szIdwlogFile[30];
  32. TCHAR szIdwlogFileAndPath[MAX_PATH];
  33. TCHAR szSystemDrive[4];
  34. BOOL bUseSysDrive;
  35. HANDLE hTestExistence;
  36. WIN32_FIND_DATA ffd;
  37. UINT i;
  38. time_t t;
  39. TCHAR szTimeBuffer[30];
  40. //figure out where idwlog is and use that folder for logs
  41. bUseSysDrive = TRUE;
  42. for (i= TEXT('c'); i <= TEXT('z'); i++){
  43. //search the drives
  44. _stprintf ( szIdwlogFileAndPath,
  45. TEXT("%c:\\idwlog\\*.log"), i);
  46. hTestExistence = FindFirstFile(szIdwlogFileAndPath, &ffd);
  47. if (INVALID_HANDLE_VALUE != hTestExistence){
  48. // We found a log file in this case here.
  49. bUseSysDrive = FALSE;
  50. FindClose(hTestExistence);
  51. _stprintf ( szLogDirectory, TEXT("%c:\\idwlog"), i);
  52. break;
  53. }
  54. }
  55. if (TRUE == bUseSysDrive){
  56. // We couldn't find it - Get the system Drive and use that
  57. if ( 0 == GetEnvironmentVariable(TEXT("SystemDrive"),szSystemDrive, 4)) {
  58. // Default to C: (we're probably running on Win9x where there is
  59. // no SystemDrive envinronment variable)
  60. //
  61. _tcscpy(szSystemDrive, TEXT("C:"));
  62. }
  63. _stprintf(szLogDirectory,TEXT("%s\\idwlog"), szSystemDrive);
  64. }
  65. _tcscpy(szTestLogFileAndPath,szLogDirectory);
  66. _tcscat(szTestLogFileAndPath,"\\");
  67. _tcscat(szTestLogFileAndPath,lpTestName);
  68. _tcscat(szTestLogFileAndPath,".LOG");
  69. fpTestLogFile = _tfopen(szTestLogFileAndPath,TEXT("a+"));
  70. if(fpTestLogFile == NULL) {
  71. // nothing we can do if the logfile is not opened
  72. // what about STWRAP.LOG ? log that failure somewhere?
  73. //_tprintf ( TEXT("ERROR - Could not open log file: %s\n"), szTestLogFileAndPath );
  74. ExitProcess(GetLastError());
  75. }
  76. szTestOutput[0]='\0';
  77. switch (dwLevel)
  78. {
  79. case LOG_NEW:
  80. //new - delete file
  81. fclose(fpTestLogFile);
  82. fpTestLogFile = _tfopen(szTestLogFileAndPath,TEXT("w"));
  83. _stprintf(szLogLevel, "~NEW~");
  84. /*
  85. // Write the time to the log.
  86. time(&t);
  87. _stprintf ( szTimeBuffer, TEXT("%s"), ctime(&t) );
  88. // ctime addes a new line to the buffer. Erase it here.
  89. szTimeBuffer[_tcslen(szTimeBuffer) - 1] = TEXT('\0');
  90. _tcscpy(szTestOutput, szTimeBuffer);
  91. _tcscat(szTestOutput, " - ");
  92. */
  93. break;
  94. case LOG_INFO:
  95. _stprintf(szLogLevel, "INFO ");
  96. break;
  97. case LOG_TEST_PASS:
  98. _stprintf(szLogLevel, "PASS ");
  99. break;
  100. case LOG_TEST_FAILURE:
  101. _stprintf(szLogLevel, "FAIL ");
  102. break;
  103. case LOG_FATAL_ERROR:
  104. _stprintf(szLogLevel, "FATAL");
  105. break;
  106. default :
  107. _stprintf(szLogLevel, "INVALID CODE");
  108. break;
  109. }
  110. // Write the time to the log.
  111. time(&t);
  112. _stprintf ( szTimeBuffer, TEXT("%s"), ctime(&t) );
  113. // ctime addes a new line to the buffer. Erase it here.
  114. szTimeBuffer[_tcslen(szTimeBuffer) - 1] = TEXT('\0');
  115. //_tcscpy(szTestOutput, szTimeBuffer);
  116. _tcscat(szTestOutput, lpTestOutput);
  117. _ftprintf (fpTestLogFile, TEXT("%s %s %s [%s] %s\n"), szLogLevel, lpTestName, lpTestOwner, szTimeBuffer, szTestOutput);
  118. fclose(fpTestLogFile);
  119. }