testSystemInformation.cxx 3.6 KB

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