henrike@webrtc.org | 0e118e7 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
| 28 | #include "talk/base/gunit.h" |
| 29 | #include "talk/base/stringutils.h" |
| 30 | #include "talk/base/systeminfo.h" |
| 31 | |
| 32 | #if defined(CPU_X86) || defined(CPU_ARM) |
| 33 | TEST(SystemInfoTest, CpuVendorNonEmpty) { |
| 34 | talk_base::SystemInfo info; |
| 35 | LOG(LS_INFO) << "CpuVendor: " << info.GetCpuVendor(); |
| 36 | EXPECT_FALSE(info.GetCpuVendor().empty()); |
| 37 | } |
| 38 | |
| 39 | // Tests Vendor identification is Intel or AMD. |
| 40 | // See Also http://en.wikipedia.org/wiki/CPUID |
| 41 | TEST(SystemInfoTest, CpuVendorIntelAMDARM) { |
| 42 | talk_base::SystemInfo info; |
| 43 | #if defined(CPU_X86) |
| 44 | EXPECT_TRUE(talk_base::string_match(info.GetCpuVendor().c_str(), |
| 45 | "GenuineIntel") || |
| 46 | talk_base::string_match(info.GetCpuVendor().c_str(), |
| 47 | "AuthenticAMD")); |
| 48 | #elif defined(CPU_ARM) |
| 49 | EXPECT_TRUE(talk_base::string_match(info.GetCpuVendor().c_str(), "ARM")); |
| 50 | #endif |
| 51 | } |
| 52 | #endif // defined(CPU_X86) || defined(CPU_ARM) |
| 53 | |
| 54 | // Tests CpuArchitecture matches expectations. |
| 55 | TEST(SystemInfoTest, GetCpuArchitecture) { |
| 56 | talk_base::SystemInfo info; |
| 57 | LOG(LS_INFO) << "CpuArchitecture: " << info.GetCpuArchitecture(); |
| 58 | talk_base::SystemInfo::Architecture architecture = info.GetCpuArchitecture(); |
| 59 | #if defined(CPU_X86) || defined(CPU_ARM) |
| 60 | if (sizeof(intptr_t) == 8) { |
| 61 | EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_X64, architecture); |
| 62 | } else if (sizeof(intptr_t) == 4) { |
| 63 | #if defined(CPU_ARM) |
| 64 | EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_ARM, architecture); |
| 65 | #else |
| 66 | EXPECT_EQ(talk_base::SystemInfo::SI_ARCH_X86, architecture); |
| 67 | #endif |
| 68 | } |
| 69 | #endif |
| 70 | } |
| 71 | |
| 72 | // Tests Cpu Cache Size |
| 73 | TEST(SystemInfoTest, CpuCacheSize) { |
| 74 | talk_base::SystemInfo info; |
| 75 | LOG(LS_INFO) << "CpuCacheSize: " << info.GetCpuCacheSize(); |
| 76 | EXPECT_GE(info.GetCpuCacheSize(), 8192); // 8 KB min cache |
| 77 | EXPECT_LE(info.GetCpuCacheSize(), 1024 * 1024 * 1024); // 1 GB max cache |
| 78 | } |
| 79 | |
| 80 | // Tests MachineModel is set. On Mac test machine model is known. |
| 81 | TEST(SystemInfoTest, MachineModelKnown) { |
| 82 | talk_base::SystemInfo info; |
| 83 | EXPECT_FALSE(info.GetMachineModel().empty()); |
| 84 | const char *machine_model = info.GetMachineModel().c_str(); |
| 85 | LOG(LS_INFO) << "MachineModel: " << machine_model; |
| 86 | bool known = true; |
| 87 | #if defined(OSX) |
| 88 | // Full list as of May 2012. Update when new OSX based models are added. |
| 89 | known = talk_base::string_match(machine_model, "MacBookPro*") || |
| 90 | talk_base::string_match(machine_model, "MacBookAir*") || |
| 91 | talk_base::string_match(machine_model, "MacBook*") || |
| 92 | talk_base::string_match(machine_model, "MacPro*") || |
| 93 | talk_base::string_match(machine_model, "Macmini*") || |
| 94 | talk_base::string_match(machine_model, "iMac*") || |
| 95 | talk_base::string_match(machine_model, "Xserve*"); |
| 96 | #elif !defined(IOS) |
| 97 | // All other machines return Not available. |
| 98 | known = talk_base::string_match(info.GetMachineModel().c_str(), |
| 99 | "Not available"); |
| 100 | #endif |
| 101 | if (!known) { |
| 102 | LOG(LS_WARNING) << "Machine Model Unknown: " << machine_model; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Tests maximum cpu clockrate. |
| 107 | TEST(SystemInfoTest, CpuMaxCpuSpeed) { |
| 108 | talk_base::SystemInfo info; |
| 109 | LOG(LS_INFO) << "MaxCpuSpeed: " << info.GetMaxCpuSpeed(); |
| 110 | EXPECT_GT(info.GetMaxCpuSpeed(), 0); |
| 111 | EXPECT_LT(info.GetMaxCpuSpeed(), 100000); // 100 Ghz |
| 112 | } |
| 113 | |
| 114 | // Tests current cpu clockrate. |
| 115 | TEST(SystemInfoTest, CpuCurCpuSpeed) { |
| 116 | talk_base::SystemInfo info; |
| 117 | LOG(LS_INFO) << "MaxCurSpeed: " << info.GetCurCpuSpeed(); |
| 118 | EXPECT_GT(info.GetCurCpuSpeed(), 0); |
| 119 | EXPECT_LT(info.GetMaxCpuSpeed(), 100000); |
| 120 | } |
| 121 | |
| 122 | // Tests physical memory size. |
| 123 | TEST(SystemInfoTest, MemorySize) { |
| 124 | talk_base::SystemInfo info; |
| 125 | LOG(LS_INFO) << "MemorySize: " << info.GetMemorySize(); |
| 126 | EXPECT_GT(info.GetMemorySize(), -1); |
| 127 | } |
| 128 | |
| 129 | // Tests number of logical cpus available to the system. |
| 130 | TEST(SystemInfoTest, MaxCpus) { |
| 131 | talk_base::SystemInfo info; |
| 132 | LOG(LS_INFO) << "MaxCpus: " << info.GetMaxCpus(); |
| 133 | EXPECT_GT(info.GetMaxCpus(), 0); |
| 134 | } |
| 135 | |
| 136 | // Tests number of physical cpus available to the system. |
| 137 | TEST(SystemInfoTest, MaxPhysicalCpus) { |
| 138 | talk_base::SystemInfo info; |
| 139 | LOG(LS_INFO) << "MaxPhysicalCpus: " << info.GetMaxPhysicalCpus(); |
| 140 | EXPECT_GT(info.GetMaxPhysicalCpus(), 0); |
| 141 | EXPECT_LE(info.GetMaxPhysicalCpus(), info.GetMaxCpus()); |
| 142 | } |
| 143 | |
| 144 | // Tests number of logical cpus available to the process. |
| 145 | TEST(SystemInfoTest, CurCpus) { |
| 146 | talk_base::SystemInfo info; |
| 147 | LOG(LS_INFO) << "CurCpus: " << info.GetCurCpus(); |
| 148 | EXPECT_GT(info.GetCurCpus(), 0); |
| 149 | EXPECT_LE(info.GetCurCpus(), info.GetMaxCpus()); |
| 150 | } |
| 151 | |
| 152 | #ifdef CPU_X86 |
| 153 | // CPU family/model/stepping is only available on X86. The following tests |
| 154 | // that they are set when running on x86 CPUs. Valid Family/Model/Stepping |
| 155 | // values are non-zero on known CPUs. |
| 156 | |
| 157 | // Tests Intel CPU Family identification. |
| 158 | TEST(SystemInfoTest, CpuFamily) { |
| 159 | talk_base::SystemInfo info; |
| 160 | LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); |
| 161 | EXPECT_GT(info.GetCpuFamily(), 0); |
| 162 | } |
| 163 | |
| 164 | // Tests Intel CPU Model identification. |
| 165 | TEST(SystemInfoTest, CpuModel) { |
| 166 | talk_base::SystemInfo info; |
| 167 | LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); |
| 168 | EXPECT_GT(info.GetCpuModel(), 0); |
| 169 | } |
| 170 | |
| 171 | // Tests Intel CPU Stepping identification. |
| 172 | TEST(SystemInfoTest, CpuStepping) { |
| 173 | talk_base::SystemInfo info; |
| 174 | LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); |
| 175 | EXPECT_GT(info.GetCpuStepping(), 0); |
| 176 | } |
| 177 | #else // CPU_X86 |
| 178 | // If not running on x86 CPU the following tests expect the functions to |
| 179 | // return 0. |
| 180 | TEST(SystemInfoTest, CpuFamily) { |
| 181 | talk_base::SystemInfo info; |
| 182 | LOG(LS_INFO) << "CpuFamily: " << info.GetCpuFamily(); |
| 183 | EXPECT_EQ(0, info.GetCpuFamily()); |
| 184 | } |
| 185 | |
| 186 | // Tests Intel CPU Model identification. |
| 187 | TEST(SystemInfoTest, CpuModel) { |
| 188 | talk_base::SystemInfo info; |
| 189 | LOG(LS_INFO) << "CpuModel: " << info.GetCpuModel(); |
| 190 | EXPECT_EQ(0, info.GetCpuModel()); |
| 191 | } |
| 192 | |
| 193 | // Tests Intel CPU Stepping identification. |
| 194 | TEST(SystemInfoTest, CpuStepping) { |
| 195 | talk_base::SystemInfo info; |
| 196 | LOG(LS_INFO) << "CpuStepping: " << info.GetCpuStepping(); |
| 197 | EXPECT_EQ(0, info.GetCpuStepping()); |
| 198 | } |
| 199 | #endif // CPU_X86 |
| 200 | |
| 201 | #if WIN32 && !defined(EXCLUDE_D3D9) |
| 202 | TEST(SystemInfoTest, GpuInfo) { |
| 203 | talk_base::SystemInfo info; |
| 204 | talk_base::SystemInfo::GpuInfo gi; |
| 205 | EXPECT_TRUE(info.GetGpuInfo(&gi)); |
| 206 | LOG(LS_INFO) << "GpuDriver: " << gi.driver; |
| 207 | EXPECT_FALSE(gi.driver.empty()); |
| 208 | LOG(LS_INFO) << "GpuDriverVersion: " << gi.driver_version; |
| 209 | EXPECT_FALSE(gi.driver_version.empty()); |
| 210 | } |
| 211 | #endif |