1 /* 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "webrtc/base/gunit.h" 12 #include "webrtc/base/stringutils.h" 13 #include "webrtc/base/systeminfo.h" 14 15 #if defined(CPU_X86) || defined(CPU_ARM) 16 TEST(SystemInfoTest, CpuVendorNonEmpty) { 17 rtc::SystemInfo info; 18 LOG(LS_INFO) << "CpuVendor: " << info.GetCpuVendor(); 19 EXPECT_FALSE(info.GetCpuVendor().empty()); 20 } 21 22 // Tests Vendor identification is Intel or AMD. 23 // See Also http://en.wikipedia.org/wiki/CPUID 24 TEST(SystemInfoTest, CpuVendorIntelAMDARM) { 25 rtc::SystemInfo info; 26 #if defined(CPU_X86) 27 EXPECT_TRUE(rtc::string_match(info.GetCpuVendor().c_str(), 28 "GenuineIntel") || 29 rtc::string_match(info.GetCpuVendor().c_str(), 30 "AuthenticAMD")); 31 #elif defined(CPU_ARM) 32 EXPECT_TRUE(rtc::string_match(info.GetCpuVendor().c_str(), "ARM")); 33 #endif 34 } 35 #endif // defined(CPU_X86) || defined(CPU_ARM) 36 37 // Tests CpuArchitecture matches expectations. 38 TEST(SystemInfoTest, GetCpuArchitecture) { 39 rtc::SystemInfo info; 40 LOG(LS_INFO) << "CpuArchitecture: " << info.GetCpuArchitecture(); 41 rtc::SystemInfo::Architecture architecture = info.GetCpuArchitecture(); 42 #if defined(CPU_X86) || defined(CPU_ARM) 43 if (sizeof(intptr_t) == 8) { 44 EXPECT_EQ(rtc::SystemInfo::SI_ARCH_X64, architecture); 45 } else if (sizeof(intptr_t) == 4) { 46 #if defined(CPU_ARM) 47 EXPECT_EQ(rtc::SystemInfo::SI_ARCH_ARM, architecture); 48 #else 49 EXPECT_EQ(rtc::SystemInfo::SI_ARCH_X86, architecture); 50 #endif 51 } 52 #endif 53 } 54 55 // Tests MachineModel is set. On Mac test machine model is known. 56 TEST(SystemInfoTest, MachineModelKnown) { 57 rtc::SystemInfo info; 58 EXPECT_FALSE(info.GetMachineModel().empty()); 59 const char *machine_model = info.GetMachineModel().c_str(); 60 LOG(LS_INFO) << "MachineModel: " << machine_model; 61 bool known = true; 62 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 63 // Full list as of May 2012. Update when new OSX based models are added. 64 known = rtc::string_match(machine_model, "MacBookPro*") || 65 rtc::string_match(machine_model, "MacBookAir*") || 66 rtc::string_match(machine_model, "MacBook*") || 67 rtc::string_match(machine_model, "MacPro*") || 68 rtc::string_match(machine_model, "Macmini*") || 69 rtc::string_match(machine_model, "iMac*") || 70 rtc::string_match(machine_model, "Xserve*"); 71 #elif !defined(WEBRTC_IOS) 72 // All other machines return Not available. 73 known = rtc::string_match(info.GetMachineModel().c_str(), 74 "Not available"); 75 #endif 76 if (!known) { 77 LOG(LS_WARNING) << "Machine Model Unknown: " << machine_model; 78 } 79 } 80 81 // Tests physical memory size. 82 TEST(SystemInfoTest, MemorySize) { 83 rtc::SystemInfo info; 84 LOG(LS_INFO) << "MemorySize: " << info.GetMemorySize(); 85 EXPECT_GT(info.GetMemorySize(), -1); 86 } 87 88 // Tests number of logical cpus available to the system. 89 TEST(SystemInfoTest, MaxCpus) { 90 rtc::SystemInfo info; 91 LOG(LS_INFO) << "MaxCpus: " << info.GetMaxCpus(); 92 EXPECT_GT(info.GetMaxCpus(), 0); 93 } 94 95 // Tests number of logical cpus available to the process. 96 TEST(SystemInfoTest, CurCpus) { 97 rtc::SystemInfo info; 98 LOG(LS_INFO) << "CurCpus: " << info.GetCurCpus(); 99 EXPECT_GT(info.GetCurCpus(), 0); 100 EXPECT_LE(info.GetCurCpus(), info.GetMaxCpus()); 101 } 102 103 #ifdef CPU_X86 104 // CPU family/model/stepping is only available on X86. The following tests 105 // that they are set when running on x86 CPUs. Valid Family/Model/Stepping 106 // values are non-zero on known CPUs. 107 108 // Tests Intel CPU Family identification. 109 TEST(SystemInfoTest, CpuFamily) { 110 rtc::SystemInfo info; 111 LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); 112 EXPECT_GT(info.GetCpuFamily(), 0); 113 } 114 115 // Tests Intel CPU Model identification. 116 TEST(SystemInfoTest, CpuModel) { 117 rtc::SystemInfo info; 118 LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); 119 EXPECT_GT(info.GetCpuModel(), 0); 120 } 121 122 // Tests Intel CPU Stepping identification. 123 TEST(SystemInfoTest, CpuStepping) { 124 rtc::SystemInfo info; 125 LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); 126 EXPECT_GT(info.GetCpuStepping(), 0); 127 } 128 #else // CPU_X86 129 // If not running on x86 CPU the following tests expect the functions to 130 // return 0. 131 TEST(SystemInfoTest, CpuFamily) { 132 rtc::SystemInfo info; 133 LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); 134 EXPECT_EQ(0, info.GetCpuFamily()); 135 } 136 137 // Tests Intel CPU Model identification. 138 TEST(SystemInfoTest, CpuModel) { 139 rtc::SystemInfo info; 140 LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); 141 EXPECT_EQ(0, info.GetCpuModel()); 142 } 143 144 // Tests Intel CPU Stepping identification. 145 TEST(SystemInfoTest, CpuStepping) { 146 rtc::SystemInfo info; 147 LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); 148 EXPECT_EQ(0, info.GetCpuStepping()); 149 } 150 #endif // CPU_X86 151