cmake/Source/kwsys/testSystemInformation.cxx

91 lines
3.0 KiB
C++
Raw Normal View History

2017-04-14 19:02:05 +02:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#include "kwsysPrivate.h"
#include KWSYS_HEADER(SystemInformation.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
2018-08-09 18:06:22 +02:00
# include "SystemInformation.hxx.in"
#endif
2015-11-17 17:22:37 +01:00
#include <iostream>
2017-04-14 19:02:05 +02:00
#define printMethod(info, m) std::cout << #m << ": " << info.m() << "\n"
2009-10-04 10:30:41 +03:00
2017-04-14 19:02:05 +02:00
#define printMethod2(info, m, unit) \
std::cout << #m << ": " << info.m() << " " << unit << "\n"
2009-10-04 10:30:41 +03:00
2017-04-14 19:02:05 +02:00
#define printMethod3(info, m, unit) \
2020-08-30 11:54:41 +02:00
std::cout << #m << ": " << info.m << " " << unit << "\n"
2013-03-16 19:13:01 +02:00
2023-05-23 16:38:00 +02:00
int testSystemInformation(int, char*[])
{
2015-11-17 17:22:37 +01:00
std::cout << "CTEST_FULL_OUTPUT\n"; // avoid truncation
2013-03-16 19:13:01 +02:00
kwsys::SystemInformation info;
info.RunCPUCheck();
info.RunOSCheck();
info.RunMemoryCheck();
2009-10-04 10:30:41 +03:00
printMethod(info, GetOSName);
2013-03-16 19:13:01 +02:00
printMethod(info, GetOSIsLinux);
printMethod(info, GetOSIsApple);
printMethod(info, GetOSIsWindows);
2009-10-04 10:30:41 +03:00
printMethod(info, GetHostname);
2013-03-16 19:13:01 +02:00
printMethod(info, GetFullyQualifiedDomainName);
2009-10-04 10:30:41 +03:00
printMethod(info, GetOSRelease);
printMethod(info, GetOSVersion);
printMethod(info, GetOSPlatform);
2017-07-20 19:35:53 +02:00
printMethod(info, Is64Bits);
printMethod(info, GetVendorString);
printMethod(info, GetVendorID);
printMethod(info, GetTypeID);
printMethod(info, GetFamilyID);
printMethod(info, GetModelID);
printMethod(info, GetExtendedProcessorName);
2013-03-16 19:13:01 +02:00
printMethod(info, GetSteppingCode);
printMethod(info, GetProcessorSerialNumber);
2009-10-04 10:30:41 +03:00
printMethod2(info, GetProcessorCacheSize, "KB");
printMethod(info, GetLogicalProcessorsPerPhysical);
2009-10-04 10:30:41 +03:00
printMethod2(info, GetProcessorClockFrequency, "MHz");
printMethod(info, GetNumberOfLogicalCPU);
printMethod(info, GetNumberOfPhysicalCPU);
printMethod(info, DoesCPUSupportCPUID);
2009-10-04 10:30:41 +03:00
printMethod(info, GetProcessorAPICID);
printMethod2(info, GetTotalVirtualMemory, "MB");
printMethod2(info, GetAvailableVirtualMemory, "MB");
printMethod2(info, GetTotalPhysicalMemory, "MB");
printMethod2(info, GetAvailablePhysicalMemory, "MB");
2013-03-16 19:13:01 +02:00
printMethod3(info, GetHostMemoryTotal(), "KiB");
printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB");
2017-04-14 19:02:05 +02:00
printMethod3(info, GetProcMemoryAvailable("KWSHL", "KWSPL"), "KiB");
2013-03-16 19:13:01 +02:00
printMethod3(info, GetHostMemoryUsed(), "KiB");
printMethod3(info, GetProcMemoryUsed(), "KiB");
2015-11-17 17:22:37 +01:00
printMethod(info, GetLoadAverage);
2009-10-04 10:30:41 +03:00
2017-04-14 19:02:05 +02:00
for (long int i = 0; i <= 31; i++) {
if (info.DoesCPUSupportFeature(static_cast<long int>(1) << i)) {
2015-11-17 17:22:37 +01:00
std::cout << "CPU feature " << i << "\n";
2013-03-16 19:13:01 +02:00
}
2017-04-14 19:02:05 +02:00
}
2013-11-03 12:27:13 +02:00
/* test stack trace
2018-08-09 18:06:22 +02:00
*/
2017-04-14 19:02:05 +02:00
std::cout << "Program Stack:" << std::endl
<< kwsys::SystemInformation::GetProgramStack(0, 0) << std::endl
<< std::endl;
2013-11-03 12:27:13 +02:00
/* test segv handler
info.SetStackTraceOnError(1);
double *d = (double*)100;
*d=0;
*/
/* test abort handler
info.SetStackTraceOnError(1);
abort();
*/
return 0;
}