testSystemInformation.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #include "kwsysPrivate.h"
  4. #include KWSYS_HEADER(SystemInformation.hxx)
  5. // Work-around CMake dependency scanning limitation. This must
  6. // duplicate the above list of headers.
  7. #if 0
  8. #include "SystemInformation.hxx.in"
  9. #endif
  10. #include <iostream>
  11. #if defined(KWSYS_USE_LONG_LONG)
  12. #if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
  13. #define iostreamLongLong(x) (x)
  14. #else
  15. #define iostreamLongLong(x) ((long)x)
  16. #endif
  17. #elif defined(KWSYS_USE___INT64)
  18. #if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
  19. #define iostreamLongLong(x) (x)
  20. #else
  21. #define iostreamLongLong(x) ((long)x)
  22. #endif
  23. #else
  24. #error "No Long Long"
  25. #endif
  26. #define printMethod(info, m) std::cout << #m << ": " << info.m() << "\n"
  27. #define printMethod2(info, m, unit) \
  28. std::cout << #m << ": " << info.m() << " " << unit << "\n"
  29. #define printMethod3(info, m, unit) \
  30. std::cout << #m << ": " << iostreamLongLong(info.m) << " " << unit << "\n"
  31. int testSystemInformation(int, char* [])
  32. {
  33. std::cout << "CTEST_FULL_OUTPUT\n"; // avoid truncation
  34. kwsys::SystemInformation info;
  35. info.RunCPUCheck();
  36. info.RunOSCheck();
  37. info.RunMemoryCheck();
  38. printMethod(info, GetOSName);
  39. printMethod(info, GetOSIsLinux);
  40. printMethod(info, GetOSIsApple);
  41. printMethod(info, GetOSIsWindows);
  42. printMethod(info, GetHostname);
  43. printMethod(info, GetFullyQualifiedDomainName);
  44. printMethod(info, GetOSRelease);
  45. printMethod(info, GetOSVersion);
  46. printMethod(info, GetOSPlatform);
  47. printMethod(info, Is64Bits);
  48. printMethod(info, GetVendorString);
  49. printMethod(info, GetVendorID);
  50. printMethod(info, GetTypeID);
  51. printMethod(info, GetFamilyID);
  52. printMethod(info, GetModelID);
  53. printMethod(info, GetExtendedProcessorName);
  54. printMethod(info, GetSteppingCode);
  55. printMethod(info, GetProcessorSerialNumber);
  56. printMethod2(info, GetProcessorCacheSize, "KB");
  57. printMethod(info, GetLogicalProcessorsPerPhysical);
  58. printMethod2(info, GetProcessorClockFrequency, "MHz");
  59. printMethod(info, GetNumberOfLogicalCPU);
  60. printMethod(info, GetNumberOfPhysicalCPU);
  61. printMethod(info, DoesCPUSupportCPUID);
  62. printMethod(info, GetProcessorAPICID);
  63. printMethod2(info, GetTotalVirtualMemory, "MB");
  64. printMethod2(info, GetAvailableVirtualMemory, "MB");
  65. printMethod2(info, GetTotalPhysicalMemory, "MB");
  66. printMethod2(info, GetAvailablePhysicalMemory, "MB");
  67. printMethod3(info, GetHostMemoryTotal(), "KiB");
  68. printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB");
  69. printMethod3(info, GetProcMemoryAvailable("KWSHL", "KWSPL"), "KiB");
  70. printMethod3(info, GetHostMemoryUsed(), "KiB");
  71. printMethod3(info, GetProcMemoryUsed(), "KiB");
  72. printMethod(info, GetLoadAverage);
  73. for (long int i = 0; i <= 31; i++) {
  74. if (info.DoesCPUSupportFeature(static_cast<long int>(1) << i)) {
  75. std::cout << "CPU feature " << i << "\n";
  76. }
  77. }
  78. /* test stack trace
  79. */
  80. std::cout << "Program Stack:" << std::endl
  81. << kwsys::SystemInformation::GetProgramStack(0, 0) << std::endl
  82. << std::endl;
  83. /* test segv handler
  84. info.SetStackTraceOnError(1);
  85. double *d = (double*)100;
  86. *d=0;
  87. */
  88. /* test abort handler
  89. info.SetStackTraceOnError(1);
  90. abort();
  91. */
  92. return 0;
  93. }