You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
7.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2009 Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "talk/base/gunit.h"
  28. #include "talk/base/stringutils.h"
  29. #include "talk/base/systeminfo.h"
  30. #if defined(CPU_X86) || defined(CPU_ARM)
  31. TEST(SystemInfoTest, CpuVendorNonEmpty) {
  32. talk_base::SystemInfo info;
  33. LOG(LS_INFO) << "CpuVendor: " << info.GetCpuVendor();
  34. EXPECT_FALSE(info.GetCpuVendor().empty());
  35. }
  36. // Tests Vendor identification is Intel or AMD.
  37. // See Also http://en.wikipedia.org/wiki/CPUID
  38. TEST(SystemInfoTest, CpuVendorIntelAMDARM) {
  39. talk_base::SystemInfo info;
  40. #if defined(CPU_X86)
  41. EXPECT_TRUE(talk_base::string_match(info.GetCpuVendor().c_str(),
  42. "GenuineIntel") ||
  43. talk_base::string_match(info.GetCpuVendor().c_str(),
  44. "AuthenticAMD"));
  45. #elif defined(CPU_ARM)
  46. EXPECT_TRUE(talk_base::string_match(info.GetCpuVendor().c_str(), "ARM"));
  47. #endif
  48. }
  49. #endif // defined(CPU_X86) || defined(CPU_ARM)
  50. // Tests CpuArchitecture matches expectations.
  51. TEST(SystemInfoTest, GetCpuArchitecture) {
  52. talk_base::SystemInfo info;
  53. LOG(LS_INFO) << "CpuArchitecture: " << info.GetCpuArchitecture();
  54. talk_base::SystemInfo::Architecture architecture = info.GetCpuArchitecture();
  55. #if defined(CPU_X86) || defined(CPU_ARM)
  56. if (sizeof(intptr_t) == 8) {
  57. EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_X64, architecture);
  58. } else if (sizeof(intptr_t) == 4) {
  59. #if defined(CPU_ARM)
  60. EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_ARM, architecture);
  61. #else
  62. EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_X86, architecture);
  63. #endif
  64. }
  65. #endif
  66. }
  67. // Tests Cpu Cache Size
  68. TEST(SystemInfoTest, CpuCacheSize) {
  69. talk_base::SystemInfo info;
  70. LOG(LS_INFO) << "CpuCacheSize: " << info.GetCpuCacheSize();
  71. EXPECT_GE(info.GetCpuCacheSize(), 8192); // 8 KB min cache
  72. EXPECT_LE(info.GetCpuCacheSize(), 1024 * 1024 * 1024); // 1 GB max cache
  73. }
  74. // Tests MachineModel is set. On Mac test machine model is known.
  75. TEST(SystemInfoTest, MachineModelKnown) {
  76. talk_base::SystemInfo info;
  77. EXPECT_FALSE(info.GetMachineModel().empty());
  78. const char *machine_model = info.GetMachineModel().c_str();
  79. LOG(LS_INFO) << "MachineModel: " << machine_model;
  80. bool known = true;
  81. #if defined(OSX)
  82. // Full list as of May 2012. Update when new OSX based models are added.
  83. known = talk_base::string_match(machine_model, "MacBookPro*") ||
  84. talk_base::string_match(machine_model, "MacBookAir*") ||
  85. talk_base::string_match(machine_model, "MacBook*") ||
  86. talk_base::string_match(machine_model, "MacPro*") ||
  87. talk_base::string_match(machine_model, "Macmini*") ||
  88. talk_base::string_match(machine_model, "iMac*") ||
  89. talk_base::string_match(machine_model, "Xserve*");
  90. #elif !defined(IOS)
  91. // All other machines return Not available.
  92. known = talk_base::string_match(info.GetMachineModel().c_str(),
  93. "Not available");
  94. #endif
  95. if (!known) {
  96. LOG(LS_WARNING) << "Machine Model Unknown: " << machine_model;
  97. }
  98. }
  99. // Tests maximum cpu clockrate.
  100. TEST(SystemInfoTest, CpuMaxCpuSpeed) {
  101. talk_base::SystemInfo info;
  102. LOG(LS_INFO) << "MaxCpuSpeed: " << info.GetMaxCpuSpeed();
  103. EXPECT_GT(info.GetMaxCpuSpeed(), 0);
  104. EXPECT_LT(info.GetMaxCpuSpeed(), 100000); // 100 Ghz
  105. }
  106. // Tests current cpu clockrate.
  107. TEST(SystemInfoTest, CpuCurCpuSpeed) {
  108. talk_base::SystemInfo info;
  109. LOG(LS_INFO) << "MaxCurSpeed: " << info.GetCurCpuSpeed();
  110. EXPECT_GT(info.GetCurCpuSpeed(), 0);
  111. EXPECT_LT(info.GetMaxCpuSpeed(), 100000);
  112. }
  113. // Tests physical memory size.
  114. TEST(SystemInfoTest, MemorySize) {
  115. talk_base::SystemInfo info;
  116. LOG(LS_INFO) << "MemorySize: " << info.GetMemorySize();
  117. EXPECT_GT(info.GetMemorySize(), -1);
  118. }
  119. // Tests number of logical cpus available to the system.
  120. TEST(SystemInfoTest, MaxCpus) {
  121. talk_base::SystemInfo info;
  122. LOG(LS_INFO) << "MaxCpus: " << info.GetMaxCpus();
  123. EXPECT_GT(info.GetMaxCpus(), 0);
  124. }
  125. // Tests number of physical cpus available to the system.
  126. TEST(SystemInfoTest, MaxPhysicalCpus) {
  127. talk_base::SystemInfo info;
  128. LOG(LS_INFO) << "MaxPhysicalCpus: " << info.GetMaxPhysicalCpus();
  129. EXPECT_GT(info.GetMaxPhysicalCpus(), 0);
  130. EXPECT_LE(info.GetMaxPhysicalCpus(), info.GetMaxCpus());
  131. }
  132. // Tests number of logical cpus available to the process.
  133. TEST(SystemInfoTest, CurCpus) {
  134. talk_base::SystemInfo info;
  135. LOG(LS_INFO) << "CurCpus: " << info.GetCurCpus();
  136. EXPECT_GT(info.GetCurCpus(), 0);
  137. EXPECT_LE(info.GetCurCpus(), info.GetMaxCpus());
  138. }
  139. #ifdef CPU_X86
  140. // CPU family/model/stepping is only available on X86. The following tests
  141. // that they are set when running on x86 CPUs. Valid Family/Model/Stepping
  142. // values are non-zero on known CPUs.
  143. // Tests Intel CPU Family identification.
  144. TEST(SystemInfoTest, CpuFamily) {
  145. talk_base::SystemInfo info;
  146. LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily();
  147. EXPECT_GT(info.GetCpuFamily(), 0);
  148. }
  149. // Tests Intel CPU Model identification.
  150. TEST(SystemInfoTest, CpuModel) {
  151. talk_base::SystemInfo info;
  152. LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel();
  153. EXPECT_GT(info.GetCpuModel(), 0);
  154. }
  155. // Tests Intel CPU Stepping identification.
  156. TEST(SystemInfoTest, CpuStepping) {
  157. talk_base::SystemInfo info;
  158. LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping();
  159. EXPECT_GT(info.GetCpuStepping(), 0);
  160. }
  161. #else // CPU_X86
  162. // If not running on x86 CPU the following tests expect the functions to
  163. // return 0.
  164. TEST(SystemInfoTest, CpuFamily) {
  165. talk_base::SystemInfo info;
  166. LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily();
  167. EXPECT_EQ(0, info.GetCpuFamily());
  168. }
  169. // Tests Intel CPU Model identification.
  170. TEST(SystemInfoTest, CpuModel) {
  171. talk_base::SystemInfo info;
  172. LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel();
  173. EXPECT_EQ(0, info.GetCpuModel());
  174. }
  175. // Tests Intel CPU Stepping identification.
  176. TEST(SystemInfoTest, CpuStepping) {
  177. talk_base::SystemInfo info;
  178. LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping();
  179. EXPECT_EQ(0, info.GetCpuStepping());
  180. }
  181. #endif // CPU_X86
  182. #if WIN32 && !defined(EXCLUDE_D3D9)
  183. TEST(SystemInfoTest, GpuInfo) {
  184. talk_base::SystemInfo info;
  185. talk_base::SystemInfo::GpuInfo gi;
  186. EXPECT_TRUE(info.GetGpuInfo(&gi));
  187. LOG(LS_INFO) << "GpuDriver: " << gi.driver;
  188. EXPECT_FALSE(gi.driver.empty());
  189. LOG(LS_INFO) << "GpuDriverVersion: " << gi.driver_version;
  190. EXPECT_FALSE(gi.driver_version.empty());
  191. }
  192. #endif