1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: SystemInformation.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 // .NAME Test to print system information useful for remote debugging.
16 // .SECTION Description
17 // Remote dashboard debugging often requires access to the
18 // CMakeCache.txt file. This test will display the file.
19
20 #include "vtkDebugLeaks.h"
21 #include <sys/stat.h>
22 #include <string>
23
vtkSystemInformationPrintFile(const char * name,ostream & os)24 void vtkSystemInformationPrintFile(const char* name, ostream& os)
25 {
26 os << "================================================================\n";
27 struct stat fs;
28 if(stat(name, &fs) != 0)
29 {
30 os << "The file \"" << name << "\" does not exist.\n";
31 return;
32 }
33
34 #ifdef _WIN32
35 ifstream fin(name, ios::in | ios::binary);
36 #else
37 ifstream fin(name, ios::in);
38 #endif
39
40 if(fin)
41 {
42 os << "Contents of \"" << name << "\":\n";
43 os << "----------------------------------------------------------------\n";
44 const int bufferSize = 4096;
45 char buffer[bufferSize];
46 // This copy loop is very sensitive on certain platforms with
47 // slightly broken stream libraries (like HPUX). Normally, it is
48 // incorrect to not check the error condition on the fin.read()
49 // before using the data, but the fin.gcount() will be zero if an
50 // error occurred. Therefore, the loop should be safe everywhere.
51 while(fin)
52 {
53 fin.read(buffer, bufferSize);
54 if(fin.gcount())
55 {
56 os.write(buffer, fin.gcount());
57 }
58 }
59 os.flush();
60 }
61 else
62 {
63 os << "Error opening \"" << name << "\" for reading.\n";
64 }
65 }
66
TestSystemInformation(int argc,char * argv[])67 int TestSystemInformation(int argc, char* argv[])
68 {
69 if(argc != 2)
70 {
71 cerr << "Usage: TestSystemInformation <top-of-build-tree>\n";
72 return 1;
73 }
74 std::string build_dir = argv[1];
75 build_dir += "/";
76
77 const char* files[] =
78 {
79 "CMakeCache.txt",
80 "CMakeFiles/CMakeError.log",
81 "Common/Core/vtkConfigure.h",
82 "Common/Core/vtkToolkits.h",
83 "VTKConfig.cmake",
84 "Testing/Temporary/ConfigSummary.txt",
85 0
86 };
87
88 cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
89
90 for(const char** f = files; *f; ++f)
91 {
92 std::string fname = build_dir + *f;
93 vtkSystemInformationPrintFile(fname.c_str(), cout);
94 }
95
96 #if defined(__sgi) && !defined(__GNUC__) && defined(_COMPILER_VERSION)
97 cout << "SGI compiler version: " << int(_COMPILER_VERSION) << endl;
98 #endif
99
100 return 0;
101 }
102