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) 16TEST(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 24TEST(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. 38TEST(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 Cpu Cache Size 56TEST(SystemInfoTest, CpuCacheSize) { 57 rtc::SystemInfo info; 58 LOG(LS_INFO) << "CpuCacheSize: " << info.GetCpuCacheSize(); 59 EXPECT_GE(info.GetCpuCacheSize(), 8192); // 8 KB min cache 60 EXPECT_LE(info.GetCpuCacheSize(), 1024 * 1024 * 1024); // 1 GB max cache 61} 62 63// Tests MachineModel is set. On Mac test machine model is known. 64TEST(SystemInfoTest, MachineModelKnown) { 65 rtc::SystemInfo info; 66 EXPECT_FALSE(info.GetMachineModel().empty()); 67 const char *machine_model = info.GetMachineModel().c_str(); 68 LOG(LS_INFO) << "MachineModel: " << machine_model; 69 bool known = true; 70#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 71 // Full list as of May 2012. Update when new OSX based models are added. 72 known = rtc::string_match(machine_model, "MacBookPro*") || 73 rtc::string_match(machine_model, "MacBookAir*") || 74 rtc::string_match(machine_model, "MacBook*") || 75 rtc::string_match(machine_model, "MacPro*") || 76 rtc::string_match(machine_model, "Macmini*") || 77 rtc::string_match(machine_model, "iMac*") || 78 rtc::string_match(machine_model, "Xserve*"); 79#elif !defined(WEBRTC_IOS) 80 // All other machines return Not available. 81 known = rtc::string_match(info.GetMachineModel().c_str(), 82 "Not available"); 83#endif 84 if (!known) { 85 LOG(LS_WARNING) << "Machine Model Unknown: " << machine_model; 86 } 87} 88 89// Tests maximum cpu clockrate. 90TEST(SystemInfoTest, CpuMaxCpuSpeed) { 91 rtc::SystemInfo info; 92 LOG(LS_INFO) << "MaxCpuSpeed: " << info.GetMaxCpuSpeed(); 93 EXPECT_GT(info.GetMaxCpuSpeed(), 0); 94 EXPECT_LT(info.GetMaxCpuSpeed(), 100000); // 100 Ghz 95} 96 97// Tests current cpu clockrate. 98TEST(SystemInfoTest, CpuCurCpuSpeed) { 99 rtc::SystemInfo info; 100 LOG(LS_INFO) << "MaxCurSpeed: " << info.GetCurCpuSpeed(); 101 EXPECT_GT(info.GetCurCpuSpeed(), 0); 102 EXPECT_LT(info.GetMaxCpuSpeed(), 100000); 103} 104 105// Tests physical memory size. 106TEST(SystemInfoTest, MemorySize) { 107 rtc::SystemInfo info; 108 LOG(LS_INFO) << "MemorySize: " << info.GetMemorySize(); 109 EXPECT_GT(info.GetMemorySize(), -1); 110} 111 112// Tests number of logical cpus available to the system. 113TEST(SystemInfoTest, MaxCpus) { 114 rtc::SystemInfo info; 115 LOG(LS_INFO) << "MaxCpus: " << info.GetMaxCpus(); 116 EXPECT_GT(info.GetMaxCpus(), 0); 117} 118 119// Tests number of physical cpus available to the system. 120TEST(SystemInfoTest, MaxPhysicalCpus) { 121 rtc::SystemInfo info; 122 LOG(LS_INFO) << "MaxPhysicalCpus: " << info.GetMaxPhysicalCpus(); 123 EXPECT_GT(info.GetMaxPhysicalCpus(), 0); 124 EXPECT_LE(info.GetMaxPhysicalCpus(), info.GetMaxCpus()); 125} 126 127// Tests number of logical cpus available to the process. 128TEST(SystemInfoTest, CurCpus) { 129 rtc::SystemInfo info; 130 LOG(LS_INFO) << "CurCpus: " << info.GetCurCpus(); 131 EXPECT_GT(info.GetCurCpus(), 0); 132 EXPECT_LE(info.GetCurCpus(), info.GetMaxCpus()); 133} 134 135#ifdef CPU_X86 136// CPU family/model/stepping is only available on X86. The following tests 137// that they are set when running on x86 CPUs. Valid Family/Model/Stepping 138// values are non-zero on known CPUs. 139 140// Tests Intel CPU Family identification. 141TEST(SystemInfoTest, CpuFamily) { 142 rtc::SystemInfo info; 143 LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); 144 EXPECT_GT(info.GetCpuFamily(), 0); 145} 146 147// Tests Intel CPU Model identification. 148TEST(SystemInfoTest, CpuModel) { 149 rtc::SystemInfo info; 150 LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); 151 EXPECT_GT(info.GetCpuModel(), 0); 152} 153 154// Tests Intel CPU Stepping identification. 155TEST(SystemInfoTest, CpuStepping) { 156 rtc::SystemInfo info; 157 LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); 158 EXPECT_GT(info.GetCpuStepping(), 0); 159} 160#else // CPU_X86 161// If not running on x86 CPU the following tests expect the functions to 162// return 0. 163TEST(SystemInfoTest, CpuFamily) { 164 rtc::SystemInfo info; 165 LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); 166 EXPECT_EQ(0, info.GetCpuFamily()); 167} 168 169// Tests Intel CPU Model identification. 170TEST(SystemInfoTest, CpuModel) { 171 rtc::SystemInfo info; 172 LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); 173 EXPECT_EQ(0, info.GetCpuModel()); 174} 175 176// Tests Intel CPU Stepping identification. 177TEST(SystemInfoTest, CpuStepping) { 178 rtc::SystemInfo info; 179 LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); 180 EXPECT_EQ(0, info.GetCpuStepping()); 181} 182#endif // CPU_X86 183 184#if WEBRTC_WIN && !defined(EXCLUDE_D3D9) 185TEST(SystemInfoTest, GpuInfo) { 186 rtc::SystemInfo info; 187 rtc::SystemInfo::GpuInfo gi; 188 EXPECT_TRUE(info.GetGpuInfo(&gi)); 189 LOG(LS_INFO) << "GpuDriver: " << gi.driver; 190 EXPECT_FALSE(gi.driver.empty()); 191 LOG(LS_INFO) << "GpuDriverVersion: " << gi.driver_version; 192 EXPECT_FALSE(gi.driver_version.empty()); 193} 194#endif 195