1 /*============================================================================
2   KWSys - Kitware System Library
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4 
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7 
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "kwsysPrivate.h"
13 #include KWSYS_HEADER(SystemInformation.hxx)
14 #include KWSYS_HEADER(ios/iostream)
15 
16 // Work-around CMake dependency scanning limitation.  This must
17 // duplicate the above list of headers.
18 #if 0
19 # include "SystemInformation.hxx.in"
20 # include "kwsys_ios_iostream.h.in"
21 #endif
22 
23 #if defined(KWSYS_USE_LONG_LONG)
24 # if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
25 #  define iostreamLongLong(x) (x)
26 # else
27 #  define iostreamLongLong(x) ((long)x)
28 # endif
29 #elif defined(KWSYS_USE___INT64)
30 # if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
31 #  define iostreamLongLong(x) (x)
32 # else
33 #  define iostreamLongLong(x) ((long)x)
34 # endif
35 #else
36 # error "No Long Long"
37 #endif
38 
39 #define printMethod(info, m) kwsys_ios::cout << #m << ": " \
40 << info.m() << "\n"
41 
42 #define printMethod2(info, m, unit) kwsys_ios::cout << #m << ": " \
43 << info.m() << " " << unit << "\n"
44 
45 #define printMethod3(info, m, unit) kwsys_ios::cout << #m << ": " \
46 << iostreamLongLong(info.m) << " " << unit << "\n"
47 
testSystemInformation(int,char * [])48 int testSystemInformation(int, char*[])
49 {
50   kwsys_ios::cout << "CTEST_FULL_OUTPUT\n"; // avoid truncation
51 
52   kwsys::SystemInformation info;
53   info.RunCPUCheck();
54   info.RunOSCheck();
55   info.RunMemoryCheck();
56   printMethod(info, GetOSName);
57   printMethod(info, GetOSIsLinux);
58   printMethod(info, GetOSIsApple);
59   printMethod(info, GetOSIsWindows);
60   printMethod(info, GetHostname);
61   printMethod(info, GetFullyQualifiedDomainName);
62   printMethod(info, GetOSRelease);
63   printMethod(info, GetOSVersion);
64   printMethod(info, GetOSPlatform);
65   printMethod(info, GetVendorString);
66   printMethod(info, GetVendorID);
67   printMethod(info, GetTypeID);
68   printMethod(info, GetFamilyID);
69   printMethod(info, GetModelID);
70   printMethod(info, GetExtendedProcessorName);
71   printMethod(info, GetSteppingCode);
72   printMethod(info, GetProcessorSerialNumber);
73   printMethod2(info, GetProcessorCacheSize, "KB");
74   printMethod(info, GetLogicalProcessorsPerPhysical);
75   printMethod2(info, GetProcessorClockFrequency, "MHz");
76   printMethod(info, Is64Bits);
77   printMethod(info, GetNumberOfLogicalCPU);
78   printMethod(info, GetNumberOfPhysicalCPU);
79   printMethod(info, DoesCPUSupportCPUID);
80   printMethod(info, GetProcessorAPICID);
81   printMethod2(info, GetTotalVirtualMemory, "MB");
82   printMethod2(info, GetAvailableVirtualMemory, "MB");
83   printMethod2(info, GetTotalPhysicalMemory, "MB");
84   printMethod2(info, GetAvailablePhysicalMemory, "MB");
85   printMethod3(info, GetHostMemoryTotal(), "KiB");
86   printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB");
87   printMethod3(info, GetProcMemoryAvailable("KWSHL","KWSPL"), "KiB");
88   printMethod3(info, GetHostMemoryUsed(), "KiB");
89   printMethod3(info, GetProcMemoryUsed(), "KiB");
90 
91   for (long int i = 0; i <= 31; i++)
92     {
93     if (info.DoesCPUSupportFeature(static_cast<long int>(1) << i))
94       {
95       kwsys_ios::cout << "CPU feature " << i << "\n";
96       }
97     }
98 
99   /* test stack trace
100   */
101   kwsys_ios::cout
102     << "Program Stack:" << kwsys_ios::endl
103     << kwsys::SystemInformation::GetProgramStack(0,0) << kwsys_ios::endl
104     << kwsys_ios::endl;
105 
106   /* test segv handler
107   info.SetStackTraceOnError(1);
108   double *d = (double*)100;
109   *d=0;
110   */
111 
112   /* test abort handler
113   info.SetStackTraceOnError(1);
114   abort();
115   */
116 
117   return 0;
118 }
119