Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/json/json_reader.h" | |
| 10 #include "gpu/config/gpu_control_list.h" | 7 #include "gpu/config/gpu_control_list.h" |
| 8 #include "gpu/config/gpu_control_list_testing_data.h" | |
| 11 #include "gpu/config/gpu_info.h" | 9 #include "gpu/config/gpu_info.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 11 |
| 14 #define LONG_STRING_CONST(...) #__VA_ARGS__ | |
| 15 | |
| 16 namespace gpu { | 12 namespace gpu { |
| 17 | 13 |
| 18 enum TestFeatureType { | 14 namespace { |
| 19 TEST_FEATURE_0 = 0, | 15 |
| 20 TEST_FEATURE_1, | 16 constexpr auto kOsLinux = GpuControlList::kOsLinux; |
| 21 TEST_FEATURE_2 | 17 constexpr auto kOsMacosx = GpuControlList::kOsMacosx; |
| 22 }; | 18 constexpr auto kOsWin = GpuControlList::kOsWin; |
| 19 constexpr auto kOsChromeOS = GpuControlList::kOsChromeOS; | |
| 20 constexpr auto kOsAndroid = GpuControlList::kOsAndroid; | |
| 21 constexpr auto kOsAny = GpuControlList::kOsAny; | |
|
Ken Russell (switch to Gerrit)
2017/03/31 02:37:06
I thought there was another way of doing this like
Zhenyao Mo
2017/03/31 19:14:13
No that doesn't compile. using constexpr auto is
| |
| 22 | |
| 23 } // namespace anonymous | |
| 23 | 24 |
| 24 class GpuControlListEntryTest : public testing::Test { | 25 class GpuControlListEntryTest : public testing::Test { |
| 25 public: | 26 public: |
| 26 GpuControlListEntryTest() { } | 27 GpuControlListEntryTest() {} |
| 27 ~GpuControlListEntryTest() override {} | 28 ~GpuControlListEntryTest() override {} |
| 28 | 29 |
| 29 const GPUInfo& gpu_info() const { | 30 const GPUInfo& gpu_info() const { |
| 30 return gpu_info_; | 31 return gpu_info_; |
| 31 } | 32 } |
| 32 | 33 |
| 33 typedef GpuControlList::ScopedGpuControlListEntry ScopedEntry; | 34 typedef GpuControlList::Entry Entry; |
| 34 | 35 |
| 35 static ScopedEntry GetEntryFromString( | 36 const Entry& GetEntry(size_t index) { |
| 36 const std::string& json, bool supports_feature_type_all) { | 37 EXPECT_LT(index, kGpuControlListTestingEntryCount); |
| 37 std::unique_ptr<base::Value> root = base::JSONReader::Read(json); | 38 EXPECT_EQ(index + 1, kGpuControlListTestingEntries[index].id); |
| 38 base::DictionaryValue* value = NULL; | 39 return kGpuControlListTestingEntries[index]; |
| 39 if (!root || !root->GetAsDictionary(&value)) | |
| 40 return NULL; | |
| 41 | |
| 42 GpuControlList::FeatureMap feature_map; | |
| 43 feature_map["test_feature_0"] = TEST_FEATURE_0; | |
| 44 feature_map["test_feature_1"] = TEST_FEATURE_1; | |
| 45 feature_map["test_feature_2"] = TEST_FEATURE_2; | |
| 46 | |
| 47 return GpuControlList::GpuControlListEntry::GetEntryFromValue( | |
| 48 value, true, feature_map, supports_feature_type_all); | |
| 49 } | 40 } |
| 50 | 41 |
| 51 static ScopedEntry GetEntryFromString(const std::string& json) { | 42 size_t CountFeature(const Entry& entry, int feature) { |
| 52 return GetEntryFromString(json, false); | 43 size_t count = 0; |
| 44 for (size_t ii = 0; ii < entry.feature_size; ++ii) { | |
| 45 if (entry.features[ii] == feature) { | |
| 46 ++count; | |
| 47 } | |
| 48 } | |
| 49 return count; | |
| 53 } | 50 } |
| 54 | 51 |
| 55 void SetUp() override { | 52 void SetUp() override { |
| 56 gpu_info_.gpu.vendor_id = 0x10de; | 53 gpu_info_.gpu.vendor_id = 0x10de; |
| 57 gpu_info_.gpu.device_id = 0x0640; | 54 gpu_info_.gpu.device_id = 0x0640; |
| 58 gpu_info_.gpu.active = true; | 55 gpu_info_.gpu.active = true; |
| 59 gpu_info_.driver_vendor = "NVIDIA"; | 56 gpu_info_.driver_vendor = "NVIDIA"; |
| 60 gpu_info_.driver_version = "1.6.18"; | 57 gpu_info_.driver_version = "1.6.18"; |
| 61 gpu_info_.driver_date = "7-14-2009"; | 58 gpu_info_.driver_date = "7-14-2009"; |
| 62 gpu_info_.gl_version = "2.1 NVIDIA-8.24.11 310.90.9b01"; | 59 gpu_info_.gl_version = "2.1 NVIDIA-8.24.11 310.90.9b01"; |
| 63 gpu_info_.gl_vendor = "NVIDIA Corporation"; | 60 gpu_info_.gl_vendor = "NVIDIA Corporation"; |
| 64 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | 61 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 65 } | 62 } |
| 66 | 63 |
| 67 protected: | 64 protected: |
| 68 GPUInfo gpu_info_; | 65 GPUInfo gpu_info_; |
| 69 }; | 66 }; |
| 70 | 67 |
| 71 TEST_F(GpuControlListEntryTest, DetailedEntry) { | 68 TEST_F(GpuControlListEntryTest, DetailedEntry) { |
| 72 const std::string json = LONG_STRING_CONST( | 69 const Entry& entry = GetEntry(kGpuControlListEntryTest_DetailedEntry); |
| 73 { | 70 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 74 "id": 5, | 71 EXPECT_STREQ("GpuControlListEntryTest.DetailedEntry", entry.description); |
| 75 "description": "test entry", | 72 EXPECT_EQ(2u, entry.cr_bug_size); |
| 76 "cr_bugs": [1024, 678], | 73 EXPECT_EQ(1024u, entry.cr_bugs[0]); |
| 77 "webkit_bugs": [1950], | 74 EXPECT_EQ(678u, entry.cr_bugs[1]); |
| 78 "os": { | 75 EXPECT_EQ(1u, entry.feature_size); |
| 79 "type": "macosx", | 76 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_0)); |
| 80 "version": { | 77 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info(), true)); |
| 81 "op": "=", | 78 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6.4", gpu_info())); |
| 82 "value": "10.6.4" | 79 EXPECT_EQ(2u, entry.disabled_extension_size); |
| 83 } | 80 EXPECT_STREQ("test_extension1", entry.disabled_extensions[0]); |
| 84 }, | 81 EXPECT_STREQ("test_extension2", entry.disabled_extensions[1]); |
| 85 "vendor_id": "0x10de", | |
| 86 "device_id": ["0x0640"], | |
| 87 "driver_version": { | |
| 88 "op": "=", | |
| 89 "value": "1.6.18" | |
| 90 }, | |
| 91 "features": [ | |
| 92 "test_feature_0" | |
| 93 ], | |
| 94 "disabled_extensions": [ | |
| 95 "test_extension1", | |
| 96 "test_extension2" | |
| 97 ] | |
| 98 } | |
| 99 ); | |
| 100 | |
| 101 ScopedEntry entry(GetEntryFromString(json)); | |
| 102 EXPECT_TRUE(entry.get() != NULL); | |
| 103 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
| 104 EXPECT_FALSE(entry->disabled()); | |
| 105 EXPECT_EQ(5u, entry->id()); | |
| 106 EXPECT_STREQ("test entry", entry->description().c_str()); | |
| 107 EXPECT_EQ(2u, entry->cr_bugs().size()); | |
| 108 EXPECT_EQ(1024, entry->cr_bugs()[0]); | |
| 109 EXPECT_EQ(678, entry->cr_bugs()[1]); | |
| 110 EXPECT_EQ(1u, entry->webkit_bugs().size()); | |
| 111 EXPECT_EQ(1950, entry->webkit_bugs()[0]); | |
| 112 EXPECT_EQ(1u, entry->features().size()); | |
| 113 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0)); | |
| 114 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info(), true)); | |
| 115 EXPECT_TRUE(entry->Contains( | |
| 116 GpuControlList::kOsMacosx, "10.6.4", gpu_info())); | |
| 117 EXPECT_STREQ("test_extension1", entry->disabled_extensions()[0].c_str()); | |
| 118 EXPECT_STREQ("test_extension2", entry->disabled_extensions()[1].c_str()); | |
| 119 } | 82 } |
| 120 | 83 |
| 121 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) { | 84 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) { |
| 122 const std::string json = LONG_STRING_CONST( | 85 const Entry& entry = GetEntry(kGpuControlListEntryTest_VendorOnAllOsEntry); |
| 123 { | 86 EXPECT_EQ(kOsAny, entry.conditions.os_type); |
| 124 "id": 1, | 87 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsLinux, |
| 125 "vendor_id": "0x10de", | 88 kOsChromeOS, kOsAndroid}; |
| 126 "features": [ | 89 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 127 "test_feature_0" | 90 EXPECT_TRUE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 128 ] | |
| 129 } | |
| 130 ); | |
| 131 ScopedEntry entry(GetEntryFromString(json)); | |
| 132 EXPECT_TRUE(entry.get() != NULL); | |
| 133 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | |
| 134 | |
| 135 const GpuControlList::OsType os_type[] = { | |
| 136 GpuControlList::kOsMacosx, | |
| 137 GpuControlList::kOsWin, | |
| 138 GpuControlList::kOsLinux, | |
| 139 GpuControlList::kOsChromeOS, | |
| 140 GpuControlList::kOsAndroid | |
| 141 }; | |
| 142 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 143 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 144 } | 91 } |
| 145 | 92 |
| 146 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) { | 93 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) { |
| 147 const std::string json = LONG_STRING_CONST( | 94 const Entry& entry = GetEntry(kGpuControlListEntryTest_VendorOnLinuxEntry); |
| 148 { | 95 EXPECT_EQ(kOsLinux, entry.conditions.os_type); |
| 149 "id": 1, | 96 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsChromeOS, |
| 150 "os": { | 97 kOsAndroid}; |
| 151 "type": "linux" | 98 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 152 }, | 99 EXPECT_FALSE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 153 "vendor_id": "0x10de", | 100 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info())); |
| 154 "features": [ | |
| 155 "test_feature_0" | |
| 156 ] | |
| 157 } | |
| 158 ); | |
| 159 ScopedEntry entry(GetEntryFromString(json)); | |
| 160 EXPECT_TRUE(entry.get() != NULL); | |
| 161 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
| 162 | |
| 163 const GpuControlList::OsType os_type[] = { | |
| 164 GpuControlList::kOsMacosx, | |
| 165 GpuControlList::kOsWin, | |
| 166 GpuControlList::kOsChromeOS, | |
| 167 GpuControlList::kOsAndroid | |
| 168 }; | |
| 169 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 170 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 171 EXPECT_TRUE(entry->Contains( | |
| 172 GpuControlList::kOsLinux, "10.6", gpu_info())); | |
| 173 } | 101 } |
| 174 | 102 |
| 175 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) { | 103 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) { |
| 176 const std::string json = LONG_STRING_CONST( | 104 const Entry& entry = |
| 177 { | 105 GetEntry(kGpuControlListEntryTest_AllExceptNVidiaOnLinuxEntry); |
| 178 "id": 1, | 106 EXPECT_EQ(kOsLinux, entry.conditions.os_type); |
| 179 "os": { | 107 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsLinux, |
| 180 "type": "linux" | 108 kOsChromeOS, kOsAndroid}; |
| 181 }, | 109 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 182 "exceptions": [ | 110 EXPECT_FALSE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 183 { | |
| 184 "vendor_id": "0x10de" | |
| 185 } | |
| 186 ], | |
| 187 "features": [ | |
| 188 "test_feature_0" | |
| 189 ] | |
| 190 } | |
| 191 ); | |
| 192 ScopedEntry entry(GetEntryFromString(json)); | |
| 193 EXPECT_TRUE(entry.get() != NULL); | |
| 194 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
| 195 | |
| 196 const GpuControlList::OsType os_type[] = { | |
| 197 GpuControlList::kOsMacosx, | |
| 198 GpuControlList::kOsWin, | |
| 199 GpuControlList::kOsLinux, | |
| 200 GpuControlList::kOsChromeOS, | |
| 201 GpuControlList::kOsAndroid | |
| 202 }; | |
| 203 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 204 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 205 } | 111 } |
| 206 | 112 |
| 207 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) { | 113 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) { |
| 208 const std::string json = LONG_STRING_CONST( | 114 const Entry& entry = |
| 209 { | 115 GetEntry(kGpuControlListEntryTest_AllExceptIntelOnLinuxEntry); |
| 210 "id": 1, | 116 EXPECT_EQ(kOsLinux, entry.conditions.os_type); |
| 211 "os": { | 117 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsChromeOS, |
| 212 "type": "linux" | 118 kOsAndroid}; |
| 213 }, | 119 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 214 "exceptions": [ | 120 EXPECT_FALSE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 215 { | 121 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info())); |
| 216 "vendor_id": "0x8086" | |
| 217 } | |
| 218 ], | |
| 219 "features": [ | |
| 220 "test_feature_0" | |
| 221 ] | |
| 222 } | |
| 223 ); | |
| 224 ScopedEntry entry(GetEntryFromString(json)); | |
| 225 EXPECT_TRUE(entry.get() != NULL); | |
| 226 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
| 227 | |
| 228 const GpuControlList::OsType os_type[] = { | |
| 229 GpuControlList::kOsMacosx, | |
| 230 GpuControlList::kOsWin, | |
| 231 GpuControlList::kOsChromeOS, | |
| 232 GpuControlList::kOsAndroid | |
| 233 }; | |
| 234 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 235 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 236 EXPECT_TRUE(entry->Contains( | |
| 237 GpuControlList::kOsLinux, "10.6", gpu_info())); | |
| 238 } | 122 } |
| 239 | 123 |
| 240 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) { | 124 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) { |
| 241 const std::string json = LONG_STRING_CONST( | 125 const Entry& entry = GetEntry(kGpuControlListEntryTest_DateOnWindowsEntry); |
| 242 { | 126 EXPECT_EQ(kOsWin, entry.conditions.os_type); |
| 243 "id": 1, | |
| 244 "os": { | |
| 245 "type": "win" | |
| 246 }, | |
| 247 "driver_date": { | |
| 248 "op": "<", | |
| 249 "value": "2010.5.8" | |
| 250 }, | |
| 251 "features": [ | |
| 252 "test_feature_0" | |
| 253 ] | |
| 254 } | |
| 255 ); | |
| 256 ScopedEntry entry(GetEntryFromString(json)); | |
| 257 EXPECT_TRUE(entry.get() != NULL); | |
| 258 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType()); | |
| 259 | |
| 260 GPUInfo gpu_info; | 127 GPUInfo gpu_info; |
| 261 gpu_info.driver_date = "4-12-2010"; | 128 gpu_info.driver_date = "4-12-2010"; |
| 262 EXPECT_TRUE(entry->Contains( | 129 EXPECT_TRUE(entry.Contains(kOsWin, "10.6", gpu_info)); |
| 263 GpuControlList::kOsWin, "10.6", gpu_info)); | |
| 264 gpu_info.driver_date = "5-8-2010"; | 130 gpu_info.driver_date = "5-8-2010"; |
| 265 EXPECT_FALSE(entry->Contains( | 131 EXPECT_FALSE(entry.Contains(kOsWin, "10.6", gpu_info)); |
| 266 GpuControlList::kOsWin, "10.6", gpu_info)); | |
| 267 gpu_info.driver_date = "5-9-2010"; | 132 gpu_info.driver_date = "5-9-2010"; |
| 268 EXPECT_FALSE(entry->Contains( | 133 EXPECT_FALSE(entry.Contains(kOsWin, "10.6", gpu_info)); |
| 269 GpuControlList::kOsWin, "10.6", gpu_info)); | |
| 270 } | 134 } |
| 271 | 135 |
| 272 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) { | 136 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) { |
| 273 const std::string json = LONG_STRING_CONST( | 137 const Entry& entry = GetEntry(kGpuControlListEntryTest_MultipleDevicesEntry); |
| 274 { | 138 EXPECT_EQ(kOsAny, entry.conditions.os_type); |
| 275 "id": 1, | 139 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsLinux, |
| 276 "vendor_id": "0x10de", | 140 kOsChromeOS, kOsAndroid}; |
| 277 "device_id": ["0x1023", "0x0640"], | 141 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 278 "features": [ | 142 EXPECT_TRUE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 279 "test_feature_0" | |
| 280 ] | |
| 281 } | |
| 282 ); | |
| 283 ScopedEntry entry(GetEntryFromString(json)); | |
| 284 EXPECT_TRUE(entry.get() != NULL); | |
| 285 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | |
| 286 | |
| 287 const GpuControlList::OsType os_type[] = { | |
| 288 GpuControlList::kOsMacosx, | |
| 289 GpuControlList::kOsWin, | |
| 290 GpuControlList::kOsLinux, | |
| 291 GpuControlList::kOsChromeOS, | |
| 292 GpuControlList::kOsAndroid | |
| 293 }; | |
| 294 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 295 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 296 } | 143 } |
| 297 | 144 |
| 298 TEST_F(GpuControlListEntryTest, ChromeOSEntry) { | 145 TEST_F(GpuControlListEntryTest, ChromeOSEntry) { |
| 299 const std::string json = LONG_STRING_CONST( | 146 const Entry& entry = GetEntry(kGpuControlListEntryTest_ChromeOSEntry); |
| 300 { | 147 EXPECT_EQ(kOsChromeOS, entry.conditions.os_type); |
| 301 "id": 1, | 148 const GpuControlList::OsType os_type[] = {kOsMacosx, kOsWin, kOsLinux, |
| 302 "os": { | 149 kOsAndroid}; |
| 303 "type": "chromeos" | 150 for (size_t i = 0; i < arraysize(os_type); ++i) |
| 304 }, | 151 EXPECT_FALSE(entry.Contains(os_type[i], "10.6", gpu_info())); |
| 305 "features": [ | 152 EXPECT_TRUE(entry.Contains(kOsChromeOS, "10.6", gpu_info())); |
| 306 "test_feature_0" | |
| 307 ] | |
| 308 } | |
| 309 ); | |
| 310 ScopedEntry entry(GetEntryFromString(json)); | |
| 311 EXPECT_TRUE(entry.get() != NULL); | |
| 312 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType()); | |
| 313 | |
| 314 const GpuControlList::OsType os_type[] = { | |
| 315 GpuControlList::kOsMacosx, | |
| 316 GpuControlList::kOsWin, | |
| 317 GpuControlList::kOsLinux, | |
| 318 GpuControlList::kOsAndroid | |
| 319 }; | |
| 320 for (size_t i = 0; i < arraysize(os_type); ++i) | |
| 321 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
| 322 EXPECT_TRUE(entry->Contains( | |
| 323 GpuControlList::kOsChromeOS, "10.6", gpu_info())); | |
| 324 } | |
| 325 | |
| 326 TEST_F(GpuControlListEntryTest, MalformedVendor) { | |
| 327 const std::string json = LONG_STRING_CONST( | |
| 328 { | |
| 329 "id": 1, | |
| 330 "vendor_id": "[0x10de]", | |
| 331 "features": [ | |
| 332 "test_feature_0" | |
| 333 ] | |
| 334 } | |
| 335 ); | |
| 336 ScopedEntry entry(GetEntryFromString(json)); | |
| 337 EXPECT_TRUE(entry.get() == NULL); | |
| 338 } | |
| 339 | |
| 340 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) { | |
| 341 const std::string json = LONG_STRING_CONST( | |
| 342 { | |
| 343 "id": 1, | |
| 344 "unknown_field": 0, | |
| 345 "features": [ | |
| 346 "test_feature_0" | |
| 347 ] | |
| 348 } | |
| 349 ); | |
| 350 ScopedEntry entry(GetEntryFromString(json)); | |
| 351 EXPECT_TRUE(entry.get() == NULL); | |
| 352 } | |
| 353 | |
| 354 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) { | |
| 355 const std::string json = LONG_STRING_CONST( | |
| 356 { | |
| 357 "id": 2, | |
| 358 "exceptions": [ | |
| 359 { | |
| 360 "unknown_field": 0 | |
| 361 } | |
| 362 ], | |
| 363 "features": [ | |
| 364 "test_feature_0" | |
| 365 ] | |
| 366 } | |
| 367 ); | |
| 368 ScopedEntry entry(GetEntryFromString(json)); | |
| 369 EXPECT_TRUE(entry.get() == NULL); | |
| 370 } | |
| 371 | |
| 372 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) { | |
| 373 const std::string json = LONG_STRING_CONST( | |
| 374 { | |
| 375 "id": 1, | |
| 376 "features": [ | |
| 377 "some_unknown_feature", | |
| 378 "test_feature_0" | |
| 379 ] | |
| 380 } | |
| 381 ); | |
| 382 ScopedEntry entry(GetEntryFromString(json)); | |
| 383 EXPECT_TRUE(entry.get() == NULL); | |
| 384 } | 153 } |
| 385 | 154 |
| 386 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) { | 155 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) { |
| 387 const std::string json = LONG_STRING_CONST( | 156 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlVersionGLESEntry); |
| 388 { | |
| 389 "id": 1, | |
| 390 "gl_type": "gles", | |
| 391 "gl_version": { | |
| 392 "op": "=", | |
| 393 "value": "3.0" | |
| 394 }, | |
| 395 "features": [ | |
| 396 "test_feature_0" | |
| 397 ] | |
| 398 } | |
| 399 ); | |
| 400 ScopedEntry entry(GetEntryFromString(json)); | |
| 401 EXPECT_TRUE(entry.get() != NULL); | |
| 402 | |
| 403 GPUInfo gpu_info; | 157 GPUInfo gpu_info; |
| 404 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; | 158 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; |
| 405 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info)); | 159 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.4.2", gpu_info)); |
| 406 | |
| 407 gpu_info.gl_version = "OpenGL ES 3.0V@66.0 AU@ (CL@)"; | 160 gpu_info.gl_version = "OpenGL ES 3.0V@66.0 AU@ (CL@)"; |
| 408 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info)); | 161 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.4.2", gpu_info)); |
| 409 | |
| 410 gpu_info.gl_version = "OpenGL ES 3.1 V@66.0 AU@ (CL@)"; | 162 gpu_info.gl_version = "OpenGL ES 3.1 V@66.0 AU@ (CL@)"; |
| 411 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info)); | 163 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.4.2", gpu_info)); |
| 412 | |
| 413 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; | 164 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; |
| 414 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 165 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 415 | |
| 416 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; | 166 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; |
| 417 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info)); | 167 EXPECT_FALSE(entry.Contains(kOsWin, "6.1", gpu_info)); |
| 418 } | 168 } |
| 419 | 169 |
| 420 TEST_F(GpuControlListEntryTest, GlVersionANGLEEntry) { | 170 TEST_F(GpuControlListEntryTest, GlVersionANGLEEntry) { |
| 421 const std::string json = LONG_STRING_CONST( | 171 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlVersionANGLEEntry); |
| 422 { | |
| 423 "id": 1, | |
| 424 "gl_type": "angle", | |
| 425 "gl_version": { | |
| 426 "op": ">", | |
| 427 "value": "2.0" | |
| 428 }, | |
| 429 "features": [ | |
| 430 "test_feature_0" | |
| 431 ] | |
| 432 } | |
| 433 ); | |
| 434 ScopedEntry entry(GetEntryFromString(json)); | |
| 435 EXPECT_TRUE(entry.get() != NULL); | |
| 436 | |
| 437 GPUInfo gpu_info; | 172 GPUInfo gpu_info; |
| 438 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; | 173 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; |
| 439 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info)); | 174 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.4.2", gpu_info)); |
| 440 | |
| 441 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; | 175 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; |
| 442 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 176 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 443 | |
| 444 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; | 177 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; |
| 445 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info)); | 178 EXPECT_TRUE(entry.Contains(kOsWin, "6.1", gpu_info)); |
| 446 | |
| 447 gpu_info.gl_version = "OpenGL ES 2.0 (ANGLE 1.2.0.2450)"; | 179 gpu_info.gl_version = "OpenGL ES 2.0 (ANGLE 1.2.0.2450)"; |
| 448 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info)); | 180 EXPECT_FALSE(entry.Contains(kOsWin, "6.1", gpu_info)); |
| 449 } | 181 } |
| 450 | 182 |
| 451 TEST_F(GpuControlListEntryTest, GlVersionGLEntry) { | 183 TEST_F(GpuControlListEntryTest, GlVersionGLEntry) { |
| 452 const std::string json = LONG_STRING_CONST( | 184 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlVersionGLEntry); |
| 453 { | |
| 454 "id": 1, | |
| 455 "gl_type": "gl", | |
| 456 "gl_version": { | |
| 457 "op": "<", | |
| 458 "value": "4.0" | |
| 459 }, | |
| 460 "features": [ | |
| 461 "test_feature_0" | |
| 462 ] | |
| 463 } | |
| 464 ); | |
| 465 ScopedEntry entry(GetEntryFromString(json)); | |
| 466 EXPECT_TRUE(entry.get() != NULL); | |
| 467 | |
| 468 GPUInfo gpu_info; | 185 GPUInfo gpu_info; |
| 469 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; | 186 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)"; |
| 470 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info)); | 187 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.4.2", gpu_info)); |
| 471 | |
| 472 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; | 188 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; |
| 473 EXPECT_TRUE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 189 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 474 | |
| 475 gpu_info.gl_version = "4.0 NVIDIA-8.24.11 310.90.9b01"; | 190 gpu_info.gl_version = "4.0 NVIDIA-8.24.11 310.90.9b01"; |
| 476 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 191 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 477 | |
| 478 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; | 192 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; |
| 479 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info)); | 193 EXPECT_FALSE(entry.Contains(kOsWin, "6.1", gpu_info)); |
| 480 } | 194 } |
| 481 | 195 |
| 482 TEST_F(GpuControlListEntryTest, GlVendorEqual) { | 196 TEST_F(GpuControlListEntryTest, GlVendorEqual) { |
| 483 const std::string json = LONG_STRING_CONST( | 197 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlVendorEqual); |
| 484 { | |
| 485 "id": 1, | |
| 486 "gl_vendor": "NVIDIA", | |
| 487 "features": [ | |
| 488 "test_feature_0" | |
| 489 ] | |
| 490 } | |
| 491 ); | |
| 492 ScopedEntry entry(GetEntryFromString(json)); | |
| 493 EXPECT_TRUE(entry.get() != NULL); | |
| 494 | |
| 495 GPUInfo gpu_info; | 198 GPUInfo gpu_info; |
| 496 gpu_info.gl_vendor = "NVIDIA"; | 199 gpu_info.gl_vendor = "NVIDIA"; |
| 497 EXPECT_TRUE(entry->Contains( | 200 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 498 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 499 | |
| 500 // Case sensitive. | 201 // Case sensitive. |
| 501 gpu_info.gl_vendor = "NVidia"; | 202 gpu_info.gl_vendor = "NVidia"; |
| 502 EXPECT_FALSE(entry->Contains( | 203 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 503 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 504 | |
| 505 gpu_info.gl_vendor = "NVIDIA-x"; | 204 gpu_info.gl_vendor = "NVIDIA-x"; |
| 506 EXPECT_FALSE(entry->Contains( | 205 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 507 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 508 } | 206 } |
| 509 | 207 |
| 510 TEST_F(GpuControlListEntryTest, GlVendorWithDot) { | 208 TEST_F(GpuControlListEntryTest, GlVendorWithDot) { |
| 511 const std::string json = LONG_STRING_CONST( | 209 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlVendorWithDot); |
| 512 { | |
| 513 "id": 1, | |
| 514 "gl_vendor": "X\\.Org.*", | |
| 515 "features": [ | |
| 516 "test_feature_0" | |
| 517 ] | |
| 518 } | |
| 519 ); | |
| 520 ScopedEntry entry(GetEntryFromString(json)); | |
| 521 EXPECT_TRUE(entry.get() != NULL); | |
| 522 | |
| 523 GPUInfo gpu_info; | 210 GPUInfo gpu_info; |
| 524 gpu_info.gl_vendor = "X.Org R300 Project"; | 211 gpu_info.gl_vendor = "X.Org R300 Project"; |
| 525 EXPECT_TRUE(entry->Contains( | 212 EXPECT_TRUE(entry.Contains(kOsLinux, "", gpu_info)); |
| 526 GpuControlList::kOsLinux, "", gpu_info)); | |
| 527 | |
| 528 gpu_info.gl_vendor = "X.Org"; | 213 gpu_info.gl_vendor = "X.Org"; |
| 529 EXPECT_TRUE(entry->Contains( | 214 EXPECT_TRUE(entry.Contains(kOsLinux, "", gpu_info)); |
| 530 GpuControlList::kOsLinux, "", gpu_info)); | |
| 531 } | 215 } |
| 532 | 216 |
| 533 TEST_F(GpuControlListEntryTest, GlRendererContains) { | 217 TEST_F(GpuControlListEntryTest, GlRendererContains) { |
| 534 const std::string json = LONG_STRING_CONST( | 218 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlRendererContains); |
| 535 { | |
| 536 "id": 1, | |
| 537 "gl_renderer": ".*GeForce.*", | |
| 538 "features": [ | |
| 539 "test_feature_0" | |
| 540 ] | |
| 541 } | |
| 542 ); | |
| 543 ScopedEntry entry(GetEntryFromString(json)); | |
| 544 EXPECT_TRUE(entry.get() != NULL); | |
| 545 | |
| 546 GPUInfo gpu_info; | 219 GPUInfo gpu_info; |
| 547 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | 220 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 548 EXPECT_TRUE(entry->Contains( | 221 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 549 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 550 | |
| 551 // Case sensitive. | 222 // Case sensitive. |
| 552 gpu_info.gl_renderer = "NVIDIA GEFORCE GT 120 OpenGL Engine"; | 223 gpu_info.gl_renderer = "NVIDIA GEFORCE GT 120 OpenGL Engine"; |
| 553 EXPECT_FALSE(entry->Contains( | 224 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 554 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 555 | |
| 556 gpu_info.gl_renderer = "GeForce GT 120 OpenGL Engine"; | 225 gpu_info.gl_renderer = "GeForce GT 120 OpenGL Engine"; |
| 557 EXPECT_TRUE(entry->Contains( | 226 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 558 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 559 | |
| 560 gpu_info.gl_renderer = "NVIDIA GeForce"; | 227 gpu_info.gl_renderer = "NVIDIA GeForce"; |
| 561 EXPECT_TRUE(entry->Contains( | 228 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 562 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 563 | |
| 564 gpu_info.gl_renderer = "NVIDIA Ge Force"; | 229 gpu_info.gl_renderer = "NVIDIA Ge Force"; |
| 565 EXPECT_FALSE(entry->Contains( | 230 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 566 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 567 } | 231 } |
| 568 | 232 |
| 569 TEST_F(GpuControlListEntryTest, GlRendererCaseInsensitive) { | 233 TEST_F(GpuControlListEntryTest, GlRendererCaseInsensitive) { |
| 570 const std::string json = LONG_STRING_CONST( | 234 const Entry& entry = |
| 571 { | 235 GetEntry(kGpuControlListEntryTest_GlRendererCaseInsensitive); |
| 572 "id": 1, | |
| 573 "gl_renderer": "(?i).*software.*", | |
| 574 "features": [ | |
| 575 "test_feature_0" | |
| 576 ] | |
| 577 } | |
| 578 ); | |
| 579 ScopedEntry entry(GetEntryFromString(json)); | |
| 580 EXPECT_TRUE(entry.get() != NULL); | |
| 581 | |
| 582 GPUInfo gpu_info; | 236 GPUInfo gpu_info; |
| 583 gpu_info.gl_renderer = "software rasterizer"; | 237 gpu_info.gl_renderer = "software rasterizer"; |
| 584 EXPECT_TRUE(entry->Contains( | 238 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 585 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 586 | |
| 587 gpu_info.gl_renderer = "Software Rasterizer"; | 239 gpu_info.gl_renderer = "Software Rasterizer"; |
| 588 EXPECT_TRUE(entry->Contains( | 240 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 589 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 590 } | 241 } |
| 591 | 242 |
| 592 TEST_F(GpuControlListEntryTest, GlExtensionsEndWith) { | 243 TEST_F(GpuControlListEntryTest, GlExtensionsEndWith) { |
| 593 const std::string json = LONG_STRING_CONST( | 244 const Entry& entry = GetEntry(kGpuControlListEntryTest_GlExtensionsEndWith); |
| 594 { | |
| 595 "id": 1, | |
| 596 "gl_extensions": ".*GL_SUN_slice_accum", | |
| 597 "features": [ | |
| 598 "test_feature_0" | |
| 599 ] | |
| 600 } | |
| 601 ); | |
| 602 ScopedEntry entry(GetEntryFromString(json)); | |
| 603 EXPECT_TRUE(entry.get() != NULL); | |
| 604 | |
| 605 GPUInfo gpu_info; | 245 GPUInfo gpu_info; |
| 606 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap " | 246 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap " |
| 607 "GL_SGIX_shadow " | 247 "GL_SGIX_shadow " |
| 608 "GL_SUN_slice_accum"; | 248 "GL_SUN_slice_accum"; |
| 609 EXPECT_TRUE(entry->Contains( | 249 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 610 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 611 | |
| 612 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap " | 250 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap " |
| 613 "GL_SUN_slice_accum " | 251 "GL_SUN_slice_accum " |
| 614 "GL_SGIX_shadow"; | 252 "GL_SGIX_shadow"; |
| 615 EXPECT_FALSE(entry->Contains( | 253 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 616 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 617 } | |
| 618 | |
| 619 TEST_F(GpuControlListEntryTest, DisabledEntry) { | |
| 620 const std::string json = LONG_STRING_CONST( | |
| 621 { | |
| 622 "id": 1, | |
| 623 "disabled": true, | |
| 624 "features": [ | |
| 625 "test_feature_0" | |
| 626 ] | |
| 627 } | |
| 628 ); | |
| 629 ScopedEntry entry(GetEntryFromString(json)); | |
| 630 EXPECT_TRUE(entry.get() != NULL); | |
| 631 EXPECT_TRUE(entry->disabled()); | |
| 632 } | 254 } |
| 633 | 255 |
| 634 TEST_F(GpuControlListEntryTest, OptimusEntry) { | 256 TEST_F(GpuControlListEntryTest, OptimusEntry) { |
| 635 const std::string json = LONG_STRING_CONST( | 257 const Entry& entry = GetEntry(kGpuControlListEntryTest_OptimusEntry); |
| 636 { | 258 EXPECT_EQ(kOsLinux, entry.conditions.os_type); |
| 637 "id": 1, | |
| 638 "os": { | |
| 639 "type": "linux" | |
| 640 }, | |
| 641 "multi_gpu_style": "optimus", | |
| 642 "features": [ | |
| 643 "test_feature_0" | |
| 644 ] | |
| 645 } | |
| 646 ); | |
| 647 GPUInfo gpu_info; | 259 GPUInfo gpu_info; |
| 648 gpu_info.optimus = true; | 260 gpu_info.optimus = true; |
| 649 | 261 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info)); |
| 650 ScopedEntry entry(GetEntryFromString(json)); | |
| 651 EXPECT_TRUE(entry.get() != NULL); | |
| 652 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
| 653 EXPECT_TRUE(entry->Contains( | |
| 654 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
| 655 } | 262 } |
| 656 | 263 |
| 657 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) { | 264 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) { |
| 658 const std::string json = LONG_STRING_CONST( | 265 const Entry& entry = GetEntry(kGpuControlListEntryTest_AMDSwitchableEntry); |
| 659 { | 266 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 660 "id": 1, | |
| 661 "os": { | |
| 662 "type": "macosx" | |
| 663 }, | |
| 664 "multi_gpu_style": "amd_switchable", | |
| 665 "features": [ | |
| 666 "test_feature_0" | |
| 667 ] | |
| 668 } | |
| 669 ); | |
| 670 GPUInfo gpu_info; | 267 GPUInfo gpu_info; |
| 671 gpu_info.amd_switchable = true; | 268 gpu_info.amd_switchable = true; |
| 672 | 269 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6", gpu_info)); |
| 673 ScopedEntry entry(GetEntryFromString(json)); | |
| 674 EXPECT_TRUE(entry.get() != NULL); | |
| 675 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
| 676 EXPECT_TRUE(entry->Contains( | |
| 677 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
| 678 } | 270 } |
| 679 | 271 |
| 680 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) { | 272 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) { |
| 681 const std::string json = LONG_STRING_CONST( | 273 const Entry& entry = GetEntry(kGpuControlListEntryTest_DriverVendorBeginWith); |
| 682 { | |
| 683 "id": 1, | |
| 684 "driver_vendor": "NVIDIA.*", | |
| 685 "features": [ | |
| 686 "test_feature_0" | |
| 687 ] | |
| 688 } | |
| 689 ); | |
| 690 ScopedEntry entry(GetEntryFromString(json)); | |
| 691 EXPECT_TRUE(entry.get() != NULL); | |
| 692 | |
| 693 GPUInfo gpu_info; | 274 GPUInfo gpu_info; |
| 694 gpu_info.driver_vendor = "NVIDIA Corporation"; | 275 gpu_info.driver_vendor = "NVIDIA Corporation"; |
| 695 EXPECT_TRUE(entry->Contains( | 276 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 696 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 697 | |
| 698 // Case sensitive. | 277 // Case sensitive. |
| 699 gpu_info.driver_vendor = "NVidia Corporation"; | 278 gpu_info.driver_vendor = "NVidia Corporation"; |
| 700 EXPECT_FALSE(entry->Contains( | 279 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 701 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 702 | |
| 703 gpu_info.driver_vendor = "NVIDIA"; | 280 gpu_info.driver_vendor = "NVIDIA"; |
| 704 EXPECT_TRUE(entry->Contains( | 281 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 705 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 706 | |
| 707 gpu_info.driver_vendor = "USA NVIDIA"; | 282 gpu_info.driver_vendor = "USA NVIDIA"; |
| 708 EXPECT_FALSE(entry->Contains( | 283 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 709 GpuControlList::kOsMacosx, "10.9", gpu_info)); | |
| 710 } | 284 } |
| 711 | 285 |
| 712 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) { | 286 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) { |
| 713 const std::string json = LONG_STRING_CONST( | 287 const Entry& entry = |
| 714 { | 288 GetEntry(kGpuControlListEntryTest_LexicalDriverVersionEntry); |
| 715 "id": 1, | 289 EXPECT_EQ(kOsLinux, entry.conditions.os_type); |
| 716 "os": { | |
| 717 "type": "linux" | |
| 718 }, | |
| 719 "vendor_id": "0x1002", | |
| 720 "driver_version": { | |
| 721 "op": "=", | |
| 722 "style": "lexical", | |
| 723 "value": "8.76" | |
| 724 }, | |
| 725 "features": [ | |
| 726 "test_feature_0" | |
| 727 ] | |
| 728 } | |
| 729 ); | |
| 730 GPUInfo gpu_info; | 290 GPUInfo gpu_info; |
| 731 gpu_info.gpu.vendor_id = 0x1002; | 291 gpu_info.gpu.vendor_id = 0x1002; |
| 732 | |
| 733 ScopedEntry entry(GetEntryFromString(json)); | |
| 734 EXPECT_TRUE(entry.get() != NULL); | |
| 735 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
| 736 | |
| 737 gpu_info.driver_version = "8.76"; | 292 gpu_info.driver_version = "8.76"; |
| 738 EXPECT_TRUE(entry->Contains( | 293 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info)); |
| 739 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
| 740 | |
| 741 gpu_info.driver_version = "8.768"; | 294 gpu_info.driver_version = "8.768"; |
| 742 EXPECT_TRUE(entry->Contains( | 295 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info)); |
| 743 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
| 744 | |
| 745 gpu_info.driver_version = "8.76.8"; | 296 gpu_info.driver_version = "8.76.8"; |
| 746 EXPECT_TRUE(entry->Contains( | 297 EXPECT_TRUE(entry.Contains(kOsLinux, "10.6", gpu_info)); |
| 747 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
| 748 } | 298 } |
| 749 | 299 |
| 750 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) { | 300 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) { |
| 751 const std::string json = LONG_STRING_CONST( | 301 const Entry& entry = GetEntry(kGpuControlListEntryTest_NeedsMoreInfoEntry); |
| 752 { | |
| 753 "id": 1, | |
| 754 "vendor_id": "0x8086", | |
| 755 "driver_version": { | |
| 756 "op": "<", | |
| 757 "value": "10.7" | |
| 758 }, | |
| 759 "features": [ | |
| 760 "test_feature_1" | |
| 761 ] | |
| 762 } | |
| 763 ); | |
| 764 ScopedEntry entry(GetEntryFromString(json)); | |
| 765 EXPECT_TRUE(entry.get() != NULL); | |
| 766 | |
| 767 GPUInfo gpu_info; | 302 GPUInfo gpu_info; |
| 768 gpu_info.gpu.vendor_id = 0x8086; | 303 gpu_info.gpu.vendor_id = 0x8086; |
| 769 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info, true)); | 304 EXPECT_TRUE(entry.NeedsMoreInfo(gpu_info, true)); |
| 770 | |
| 771 gpu_info.driver_version = "10.6"; | 305 gpu_info.driver_version = "10.6"; |
| 772 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, true)); | 306 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, true)); |
| 773 } | 307 } |
| 774 | 308 |
| 775 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) { | 309 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) { |
| 776 const std::string json = LONG_STRING_CONST( | 310 const Entry& entry = |
| 777 { | 311 GetEntry(kGpuControlListEntryTest_NeedsMoreInfoForExceptionsEntry); |
| 778 "id": 1, | |
| 779 "vendor_id": "0x8086", | |
| 780 "exceptions": [ | |
| 781 { | |
| 782 "gl_renderer": ".*mesa.*" | |
| 783 } | |
| 784 ], | |
| 785 "features": [ | |
| 786 "test_feature_1" | |
| 787 ] | |
| 788 } | |
| 789 ); | |
| 790 ScopedEntry entry(GetEntryFromString(json)); | |
| 791 EXPECT_TRUE(entry.get() != NULL); | |
| 792 | |
| 793 GPUInfo gpu_info; | 312 GPUInfo gpu_info; |
| 794 gpu_info.gpu.vendor_id = 0x8086; | 313 gpu_info.gpu.vendor_id = 0x8086; |
| 795 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info, true)); | 314 EXPECT_TRUE(entry.NeedsMoreInfo(gpu_info, true)); |
| 796 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, false)); | 315 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, false)); |
| 797 | |
| 798 gpu_info.gl_renderer = "mesa"; | 316 gpu_info.gl_renderer = "mesa"; |
| 799 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, true)); | 317 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, true)); |
| 800 } | 318 } |
| 801 | 319 |
| 802 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForGlVersionEntry) { | 320 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForGlVersionEntry) { |
| 803 const std::string json = LONG_STRING_CONST( | 321 const Entry& entry = |
| 804 { | 322 GetEntry(kGpuControlListEntryTest_NeedsMoreInfoForGlVersionEntry); |
| 805 "id" : 1, | 323 GPUInfo gpu_info; |
| 806 "gl_type": "gl", | 324 EXPECT_TRUE(entry.NeedsMoreInfo(gpu_info, true)); |
| 807 "gl_version": { | 325 EXPECT_TRUE(entry.Contains(kOsLinux, std::string(), gpu_info)); |
| 808 "op": "<", | |
| 809 "value" : "3.5" | |
| 810 }, | |
| 811 "features" : [ | |
| 812 "test_feature_1" | |
| 813 ] | |
| 814 } | |
| 815 ); | |
| 816 ScopedEntry entry(GetEntryFromString(json)); | |
| 817 EXPECT_TRUE(entry.get() != NULL); | |
| 818 | |
| 819 GPUInfo gpu_info; | |
| 820 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info, true)); | |
| 821 EXPECT_TRUE( | |
| 822 entry->Contains(GpuControlList::kOsUnknown, std::string(), gpu_info)); | |
| 823 | |
| 824 gpu_info.gl_version = "3.1 Mesa 11.1.0"; | 326 gpu_info.gl_version = "3.1 Mesa 11.1.0"; |
| 825 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, false)); | 327 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, false)); |
| 826 EXPECT_TRUE( | 328 EXPECT_TRUE(entry.Contains(kOsLinux, std::string(), gpu_info)); |
| 827 entry->Contains(GpuControlList::kOsUnknown, std::string(), gpu_info)); | |
| 828 | |
| 829 gpu_info.gl_version = "4.1 Mesa 12.1.0"; | 329 gpu_info.gl_version = "4.1 Mesa 12.1.0"; |
| 830 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, false)); | 330 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, false)); |
| 831 EXPECT_FALSE( | 331 EXPECT_FALSE(entry.Contains(kOsLinux, std::string(), gpu_info)); |
| 832 entry->Contains(GpuControlList::kOsUnknown, std::string(), gpu_info)); | |
| 833 | |
| 834 gpu_info.gl_version = "OpenGL ES 2.0 Mesa 12.1.0"; | 332 gpu_info.gl_version = "OpenGL ES 2.0 Mesa 12.1.0"; |
| 835 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info, false)); | 333 EXPECT_FALSE(entry.NeedsMoreInfo(gpu_info, false)); |
| 836 EXPECT_FALSE( | 334 EXPECT_FALSE(entry.Contains(kOsLinux, std::string(), gpu_info)); |
| 837 entry->Contains(GpuControlList::kOsUnknown, std::string(), gpu_info)); | |
| 838 } | 335 } |
| 839 | 336 |
| 840 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) { | 337 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) { |
| 841 const std::string json = LONG_STRING_CONST( | 338 const Entry& entry = GetEntry(kGpuControlListEntryTest_FeatureTypeAllEntry); |
| 842 { | 339 |
| 843 "id": 1, | 340 EXPECT_EQ(3u, entry.feature_size); |
| 844 "features": [ | 341 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_0)); |
| 845 "all" | 342 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_1)); |
| 846 ] | 343 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_2)); |
| 847 } | |
| 848 ); | |
| 849 ScopedEntry entry(GetEntryFromString(json, true)); | |
| 850 EXPECT_TRUE(entry.get() != NULL); | |
| 851 EXPECT_EQ(3u, entry->features().size()); | |
| 852 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0)); | |
| 853 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1)); | |
| 854 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2)); | |
| 855 } | 344 } |
| 856 | 345 |
| 857 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntryWithExceptions) { | 346 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntryWithExceptions) { |
| 858 const std::string json = LONG_STRING_CONST( | 347 const Entry& entry = |
| 859 { | 348 GetEntry(kGpuControlListEntryTest_FeatureTypeAllEntryWithExceptions); |
| 860 "id": 1, | 349 EXPECT_EQ(2u, entry.feature_size); |
| 861 "features": [ | 350 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_1)); |
| 862 "all", | 351 EXPECT_EQ(1u, CountFeature(entry, TEST_FEATURE_2)); |
| 863 {"exceptions" : [ | |
| 864 "test_feature_0" | |
| 865 ]} | |
| 866 ] | |
| 867 } | |
| 868 ); | |
| 869 bool supports_feature_type_all = true; | |
| 870 ScopedEntry entry(GetEntryFromString(json, supports_feature_type_all)); | |
| 871 EXPECT_TRUE(entry.get() != NULL); | |
| 872 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1)); | |
| 873 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2)); | |
| 874 EXPECT_EQ(2u, entry->features().size()); | |
| 875 | |
| 876 supports_feature_type_all = false; | |
| 877 entry = ScopedEntry(GetEntryFromString(json, supports_feature_type_all)); | |
| 878 EXPECT_TRUE(entry.get() == NULL); | |
| 879 } | |
| 880 | |
| 881 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntryWithUnknownField) { | |
| 882 const std::string json = LONG_STRING_CONST( | |
| 883 { | |
| 884 "id": 1, | |
| 885 "features": [ | |
| 886 "all", { | |
| 887 "exceptions" : [ | |
| 888 "test_feature_0" | |
| 889 ], | |
| 890 "unknown_field" : 0 | |
| 891 } | |
| 892 ] | |
| 893 } | |
| 894 ); | |
| 895 bool supports_feature_type_all = true; | |
| 896 ScopedEntry entry(GetEntryFromString(json, supports_feature_type_all)); | |
| 897 EXPECT_TRUE(entry.get() == NULL); | |
| 898 | |
| 899 supports_feature_type_all = false; | |
| 900 entry = ScopedEntry(GetEntryFromString(json, supports_feature_type_all)); | |
| 901 EXPECT_TRUE(entry.get() == NULL); | |
| 902 } | |
| 903 | |
| 904 TEST_F(GpuControlListEntryTest, InvalidVendorIdEntry) { | |
| 905 const std::string json = LONG_STRING_CONST( | |
| 906 { | |
| 907 "id": 1, | |
| 908 "vendor_id": "0x0000", | |
| 909 "features": [ | |
| 910 "test_feature_1" | |
| 911 ] | |
| 912 } | |
| 913 ); | |
| 914 ScopedEntry entry(GetEntryFromString(json)); | |
| 915 EXPECT_TRUE(entry.get() == NULL); | |
| 916 } | |
| 917 | |
| 918 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) { | |
| 919 const std::string json = LONG_STRING_CONST( | |
| 920 { | |
| 921 "id": 1, | |
| 922 "vendor_id": "0x10de", | |
| 923 "device_id": ["0x1023", "0x0000"], | |
| 924 "features": [ | |
| 925 "test_feature_1" | |
| 926 ] | |
| 927 } | |
| 928 ); | |
| 929 ScopedEntry entry(GetEntryFromString(json)); | |
| 930 EXPECT_TRUE(entry.get() == NULL); | |
| 931 } | 352 } |
| 932 | 353 |
| 933 TEST_F(GpuControlListEntryTest, SingleActiveGPU) { | 354 TEST_F(GpuControlListEntryTest, SingleActiveGPU) { |
| 934 const std::string json = LONG_STRING_CONST( | 355 const Entry& entry = GetEntry(kGpuControlListEntryTest_SingleActiveGPU); |
| 935 { | 356 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 936 "id": 1, | 357 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6", gpu_info())); |
| 937 "os": { | |
| 938 "type": "macosx" | |
| 939 }, | |
| 940 "vendor_id": "0x10de", | |
| 941 "device_id": ["0x0640"], | |
| 942 "multi_gpu_category": "active", | |
| 943 "features": [ | |
| 944 "test_feature_0" | |
| 945 ] | |
| 946 } | |
| 947 ); | |
| 948 ScopedEntry entry(GetEntryFromString(json)); | |
| 949 EXPECT_TRUE(entry.get() != NULL); | |
| 950 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
| 951 EXPECT_TRUE(entry->Contains( | |
| 952 GpuControlList::kOsMacosx, "10.6", gpu_info())); | |
| 953 } | 358 } |
| 954 | 359 |
| 955 TEST_F(GpuControlListEntryTest, MachineModelName) { | 360 TEST_F(GpuControlListEntryTest, MachineModelName) { |
| 956 const std::string json = LONG_STRING_CONST( | 361 const Entry& entry = GetEntry(kGpuControlListEntryTest_MachineModelName); |
| 957 { | 362 EXPECT_EQ(kOsAndroid, entry.conditions.os_type); |
| 958 "id": 1, | 363 GPUInfo gpu_info; |
| 959 "os": { | |
| 960 "type": "android" | |
| 961 }, | |
| 962 "machine_model_name": [ | |
| 963 "Nexus 4", "XT1032", "GT-.*", "SCH-.*" | |
| 964 ], | |
| 965 "features": [ | |
| 966 "test_feature_0" | |
| 967 ] | |
| 968 } | |
| 969 ); | |
| 970 ScopedEntry entry(GetEntryFromString(json)); | |
| 971 EXPECT_TRUE(entry.get() != NULL); | |
| 972 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType()); | |
| 973 GPUInfo gpu_info; | |
| 974 | |
| 975 gpu_info.machine_model_name = "Nexus 4"; | 364 gpu_info.machine_model_name = "Nexus 4"; |
| 976 EXPECT_TRUE(entry->Contains( | 365 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 977 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 978 | |
| 979 gpu_info.machine_model_name = "XT1032"; | 366 gpu_info.machine_model_name = "XT1032"; |
| 980 EXPECT_TRUE(entry->Contains( | 367 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 981 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 982 | |
| 983 gpu_info.machine_model_name = "XT1032i"; | 368 gpu_info.machine_model_name = "XT1032i"; |
| 984 EXPECT_FALSE(entry->Contains( | 369 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 985 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 986 | |
| 987 gpu_info.machine_model_name = "Nexus 5"; | 370 gpu_info.machine_model_name = "Nexus 5"; |
| 988 EXPECT_FALSE(entry->Contains( | 371 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 989 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 990 | |
| 991 gpu_info.machine_model_name = "Nexus"; | 372 gpu_info.machine_model_name = "Nexus"; |
| 992 EXPECT_FALSE(entry->Contains( | 373 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 993 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 994 | |
| 995 gpu_info.machine_model_name = ""; | 374 gpu_info.machine_model_name = ""; |
| 996 EXPECT_FALSE(entry->Contains( | 375 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 997 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 998 | |
| 999 gpu_info.machine_model_name = "GT-N7100"; | 376 gpu_info.machine_model_name = "GT-N7100"; |
| 1000 EXPECT_TRUE(entry->Contains( | 377 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1001 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 1002 | |
| 1003 gpu_info.machine_model_name = "GT-I9300"; | 378 gpu_info.machine_model_name = "GT-I9300"; |
| 1004 EXPECT_TRUE(entry->Contains( | 379 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1005 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 1006 | |
| 1007 gpu_info.machine_model_name = "SCH-I545"; | 380 gpu_info.machine_model_name = "SCH-I545"; |
| 1008 EXPECT_TRUE(entry->Contains( | 381 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1009 GpuControlList::kOsAndroid, "4.1", gpu_info)); | |
| 1010 } | 382 } |
| 1011 | 383 |
| 1012 TEST_F(GpuControlListEntryTest, MachineModelNameException) { | 384 TEST_F(GpuControlListEntryTest, MachineModelNameException) { |
| 1013 const std::string json = LONG_STRING_CONST( | 385 const Entry& entry = |
| 1014 { | 386 GetEntry(kGpuControlListEntryTest_MachineModelNameException); |
| 1015 "id": 1, | 387 EXPECT_EQ(kOsAny, entry.conditions.os_type); |
| 1016 "exceptions": [ | 388 GPUInfo gpu_info; |
| 1017 { | |
| 1018 "os": { | |
| 1019 "type": "android" | |
| 1020 }, | |
| 1021 "machine_model_name": ["Nexus.*"] | |
| 1022 } | |
| 1023 ], | |
| 1024 "features": [ | |
| 1025 "test_feature_0" | |
| 1026 ] | |
| 1027 } | |
| 1028 ); | |
| 1029 ScopedEntry entry(GetEntryFromString(json)); | |
| 1030 EXPECT_TRUE(entry.get() != NULL); | |
| 1031 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | |
| 1032 GPUInfo gpu_info; | |
| 1033 | |
| 1034 gpu_info.machine_model_name = "Nexus 4"; | 389 gpu_info.machine_model_name = "Nexus 4"; |
| 1035 EXPECT_FALSE(entry->Contains( | 390 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1036 GpuControlList::kOsAndroid, "4.1", gpu_info)); | 391 EXPECT_TRUE(entry.Contains(kOsLinux, "4.1", gpu_info)); |
| 1037 EXPECT_TRUE(entry->Contains( | |
| 1038 GpuControlList::kOsLinux, "4.1", gpu_info)); | |
| 1039 | |
| 1040 gpu_info.machine_model_name = "Nexus 7"; | 392 gpu_info.machine_model_name = "Nexus 7"; |
| 1041 EXPECT_FALSE(entry->Contains( | 393 EXPECT_FALSE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1042 GpuControlList::kOsAndroid, "4.1", gpu_info)); | 394 EXPECT_TRUE(entry.Contains(kOsLinux, "4.1", gpu_info)); |
| 1043 EXPECT_TRUE(entry->Contains( | |
| 1044 GpuControlList::kOsLinux, "4.1", gpu_info)); | |
| 1045 | |
| 1046 gpu_info.machine_model_name = ""; | 395 gpu_info.machine_model_name = ""; |
| 1047 EXPECT_TRUE(entry->Contains( | 396 EXPECT_TRUE(entry.Contains(kOsAndroid, "4.1", gpu_info)); |
| 1048 GpuControlList::kOsAndroid, "4.1", gpu_info)); | 397 EXPECT_TRUE(entry.Contains(kOsLinux, "4.1", gpu_info)); |
| 1049 EXPECT_TRUE(entry->Contains( | |
| 1050 GpuControlList::kOsLinux, "4.1", gpu_info)); | |
| 1051 } | 398 } |
| 1052 | 399 |
| 1053 TEST_F(GpuControlListEntryTest, MachineModelVersion) { | 400 TEST_F(GpuControlListEntryTest, MachineModelVersion) { |
| 1054 const std::string json = LONG_STRING_CONST( | 401 const Entry& entry = GetEntry(kGpuControlListEntryTest_MachineModelVersion); |
| 1055 { | |
| 1056 "id": 1, | |
| 1057 "os": { | |
| 1058 "type": "macosx" | |
| 1059 }, | |
| 1060 "machine_model_name": ["MacBookPro"], | |
| 1061 "machine_model_version": { | |
| 1062 "op": "=", | |
| 1063 "value": "7.1" | |
| 1064 }, | |
| 1065 "features": [ | |
| 1066 "test_feature_0" | |
| 1067 ] | |
| 1068 } | |
| 1069 ); | |
| 1070 ScopedEntry entry(GetEntryFromString(json)); | |
| 1071 EXPECT_TRUE(entry.get() != NULL); | |
| 1072 GPUInfo gpu_info; | 402 GPUInfo gpu_info; |
| 1073 gpu_info.machine_model_name = "MacBookPro"; | 403 gpu_info.machine_model_name = "MacBookPro"; |
| 1074 gpu_info.machine_model_version = "7.1"; | 404 gpu_info.machine_model_version = "7.1"; |
| 1075 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | 405 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 1076 EXPECT_TRUE(entry->Contains( | 406 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6", gpu_info)); |
| 1077 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
| 1078 } | 407 } |
| 1079 | 408 |
| 1080 TEST_F(GpuControlListEntryTest, MachineModelVersionException) { | 409 TEST_F(GpuControlListEntryTest, MachineModelVersionException) { |
| 1081 const std::string json = LONG_STRING_CONST( | 410 const Entry& entry = |
| 1082 { | 411 GetEntry(kGpuControlListEntryTest_MachineModelVersionException); |
| 1083 "id": 1, | 412 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 1084 "os": { | |
| 1085 "type": "macosx" | |
| 1086 }, | |
| 1087 "machine_model_name": ["MacBookPro"], | |
| 1088 "exceptions": [ | |
| 1089 { | |
| 1090 "machine_model_version": { | |
| 1091 "op": ">", | |
| 1092 "value": "7.1" | |
| 1093 } | |
| 1094 } | |
| 1095 ], | |
| 1096 "features": [ | |
| 1097 "test_feature_0" | |
| 1098 ] | |
| 1099 } | |
| 1100 ); | |
| 1101 ScopedEntry entry(GetEntryFromString(json)); | |
| 1102 EXPECT_TRUE(entry.get() != NULL); | |
| 1103 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
| 1104 | |
| 1105 GPUInfo gpu_info; | 413 GPUInfo gpu_info; |
| 1106 gpu_info.machine_model_name = "MacBookPro"; | 414 gpu_info.machine_model_name = "MacBookPro"; |
| 1107 gpu_info.machine_model_version = "7.0"; | 415 gpu_info.machine_model_version = "7.0"; |
| 1108 EXPECT_TRUE(entry->Contains( | 416 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6", gpu_info)); |
| 1109 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
| 1110 | |
| 1111 gpu_info.machine_model_version = "7.2"; | 417 gpu_info.machine_model_version = "7.2"; |
| 1112 EXPECT_FALSE(entry->Contains( | 418 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.6", gpu_info)); |
| 1113 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
| 1114 | |
| 1115 gpu_info.machine_model_version = ""; | 419 gpu_info.machine_model_version = ""; |
| 1116 EXPECT_TRUE(entry->Contains( | 420 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.6", gpu_info)); |
| 1117 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
| 1118 } | 421 } |
| 1119 | 422 |
| 1120 class GpuControlListEntryDualGPUTest : public GpuControlListEntryTest { | 423 class GpuControlListEntryDualGPUTest : public GpuControlListEntryTest { |
| 1121 public: | 424 public: |
| 1122 GpuControlListEntryDualGPUTest() { } | 425 GpuControlListEntryDualGPUTest() { } |
| 1123 ~GpuControlListEntryDualGPUTest() override {} | 426 ~GpuControlListEntryDualGPUTest() override {} |
| 1124 | 427 |
| 1125 void SetUp() override { | 428 void SetUp() override { |
| 1126 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as | 429 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as |
| 1127 // secondary, and initially Intel is active. | 430 // secondary, and initially Intel is active. |
| 1128 gpu_info_.gpu.vendor_id = 0x10de; | 431 gpu_info_.gpu.vendor_id = 0x10de; |
| 1129 gpu_info_.gpu.device_id = 0x0640; | 432 gpu_info_.gpu.device_id = 0x0640; |
| 1130 gpu_info_.gpu.active = false; | 433 gpu_info_.gpu.active = false; |
| 1131 GPUInfo::GPUDevice second_gpu; | 434 GPUInfo::GPUDevice second_gpu; |
| 1132 second_gpu.vendor_id = 0x8086; | 435 second_gpu.vendor_id = 0x8086; |
| 1133 second_gpu.device_id = 0x0166; | 436 second_gpu.device_id = 0x0166; |
| 1134 second_gpu.active = true; | 437 second_gpu.active = true; |
| 1135 gpu_info_.secondary_gpus.push_back(second_gpu); | 438 gpu_info_.secondary_gpus.push_back(second_gpu); |
| 1136 } | 439 } |
| 1137 | 440 |
| 1138 void ActivatePrimaryGPU() { | 441 void ActivatePrimaryGPU() { |
| 1139 gpu_info_.gpu.active = true; | 442 gpu_info_.gpu.active = true; |
| 1140 gpu_info_.secondary_gpus[0].active = false; | 443 gpu_info_.secondary_gpus[0].active = false; |
| 1141 } | 444 } |
| 1142 | 445 |
| 1143 void EntryShouldApply(const std::string& entry_json) const { | 446 void EntryShouldApply(const Entry& entry) const { |
| 1144 EXPECT_TRUE(EntryApplies(entry_json)); | 447 EXPECT_TRUE(EntryApplies(entry)); |
| 1145 } | 448 } |
| 1146 | 449 |
| 1147 void EntryShouldNotApply(const std::string& entry_json) const { | 450 void EntryShouldNotApply(const Entry& entry) const { |
| 1148 EXPECT_FALSE(EntryApplies(entry_json)); | 451 EXPECT_FALSE(EntryApplies(entry)); |
| 1149 } | 452 } |
| 1150 | 453 |
| 1151 private: | 454 private: |
| 1152 bool EntryApplies(const std::string& entry_json) const { | 455 bool EntryApplies(const Entry& entry) const { |
| 1153 ScopedEntry entry(GetEntryFromString(entry_json)); | 456 EXPECT_EQ(kOsMacosx, entry.conditions.os_type); |
| 1154 EXPECT_TRUE(entry.get()); | 457 return entry.Contains(kOsMacosx, "10.6", gpu_info()); |
| 1155 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
| 1156 return entry->Contains(GpuControlList::kOsMacosx, "10.6", gpu_info()); | |
| 1157 } | 458 } |
| 1158 }; | 459 }; |
| 1159 | 460 |
| 1160 TEST_F(GpuControlListEntryDualGPUTest, CategoryAny) { | 461 TEST_F(GpuControlListEntryDualGPUTest, CategoryAny) { |
| 1161 const std::string json_intel = LONG_STRING_CONST( | 462 const Entry& entry_intel = |
| 1162 { | 463 GetEntry(kGpuControlListEntryDualGPUTest_CategoryAny_Intel); |
| 1163 "id": 1, | 464 EntryShouldApply(entry_intel); |
| 1164 "os": { | 465 const Entry& entry_nvidia = |
| 1165 "type": "macosx" | 466 GetEntry(kGpuControlListEntryDualGPUTest_CategoryAny_NVidia); |
| 1166 }, | 467 EntryShouldApply(entry_nvidia); |
| 1167 "vendor_id": "0x8086", | |
| 1168 "device_id": ["0x0166"], | |
| 1169 "multi_gpu_category": "any", | |
| 1170 "features": [ | |
| 1171 "test_feature_0" | |
| 1172 ] | |
| 1173 } | |
| 1174 ); | |
| 1175 EntryShouldApply(json_intel); | |
| 1176 | |
| 1177 const std::string json_nvidia = LONG_STRING_CONST( | |
| 1178 { | |
| 1179 "id": 1, | |
| 1180 "os": { | |
| 1181 "type": "macosx" | |
| 1182 }, | |
| 1183 "vendor_id": "0x10de", | |
| 1184 "device_id": ["0x0640"], | |
| 1185 "multi_gpu_category": "any", | |
| 1186 "features": [ | |
| 1187 "test_feature_0" | |
| 1188 ] | |
| 1189 } | |
| 1190 ); | |
| 1191 EntryShouldApply(json_nvidia); | |
| 1192 } | 468 } |
| 1193 | 469 |
| 1194 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) { | 470 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) { |
| 1195 const std::string json_secondary = LONG_STRING_CONST( | 471 const Entry& entry_secondary = |
| 1196 { | 472 GetEntry(kGpuControlListEntryDualGPUTest_CategorySecondary); |
| 1197 "id": 1, | 473 EntryShouldApply(entry_secondary); |
| 1198 "os": { | 474 const Entry& entry_primary = |
| 1199 "type": "macosx" | 475 GetEntry(kGpuControlListEntryDualGPUTest_CategoryPrimary); |
| 1200 }, | 476 EntryShouldNotApply(entry_primary); |
| 1201 "vendor_id": "0x8086", | 477 const Entry& entry_default = |
| 1202 "device_id": ["0x0166"], | 478 GetEntry(kGpuControlListEntryDualGPUTest_CategoryDefault); |
| 1203 "multi_gpu_category": "secondary", | |
| 1204 "features": [ | |
| 1205 "test_feature_0" | |
| 1206 ] | |
| 1207 } | |
| 1208 ); | |
| 1209 EntryShouldApply(json_secondary); | |
| 1210 | |
| 1211 const std::string json_primary = LONG_STRING_CONST( | |
| 1212 { | |
| 1213 "id": 1, | |
| 1214 "os": { | |
| 1215 "type": "macosx" | |
| 1216 }, | |
| 1217 "vendor_id": "0x8086", | |
| 1218 "device_id": ["0x0166"], | |
| 1219 "multi_gpu_category": "primary", | |
| 1220 "features": [ | |
| 1221 "test_feature_0" | |
| 1222 ] | |
| 1223 } | |
| 1224 ); | |
| 1225 EntryShouldNotApply(json_primary); | |
| 1226 | |
| 1227 const std::string json_default = LONG_STRING_CONST( | |
| 1228 { | |
| 1229 "id": 1, | |
| 1230 "os": { | |
| 1231 "type": "macosx" | |
| 1232 }, | |
| 1233 "vendor_id": "0x8086", | |
| 1234 "device_id": ["0x0166"], | |
| 1235 "features": [ | |
| 1236 "test_feature_0" | |
| 1237 ] | |
| 1238 } | |
| 1239 ); | |
| 1240 // Default is active, and the secondary Intel GPU is active. | 479 // Default is active, and the secondary Intel GPU is active. |
| 1241 EntryShouldApply(json_default); | 480 EntryShouldApply(entry_default); |
| 1242 } | 481 } |
| 1243 | 482 |
| 1244 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) { | 483 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) { |
| 1245 const std::string json = LONG_STRING_CONST( | 484 const Entry& entry = |
| 1246 { | 485 GetEntry(kGpuControlListEntryDualGPUTest_ActiveSecondaryGPU); |
| 1247 "id": 1, | 486 // By default, secondary GPU is active. |
| 1248 "os": { | 487 EntryShouldApply(entry); |
| 1249 "type": "macosx" | 488 ActivatePrimaryGPU(); |
| 1250 }, | 489 EntryShouldNotApply(entry); |
| 1251 "vendor_id": "0x8086", | |
| 1252 "device_id": ["0x0166", "0x0168"], | |
| 1253 "multi_gpu_category": "active", | |
| 1254 "features": [ | |
| 1255 "test_feature_0" | |
| 1256 ] | |
| 1257 } | |
| 1258 ); | |
| 1259 // By default, secondary GPU is active. | |
| 1260 EntryShouldApply(json); | |
| 1261 | |
| 1262 ActivatePrimaryGPU(); | |
| 1263 EntryShouldNotApply(json); | |
| 1264 } | 490 } |
| 1265 | 491 |
| 1266 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActiveSecondaryGPU) { | 492 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActiveSecondaryGPU) { |
| 1267 const std::string json = LONG_STRING_CONST( | 493 const Entry& entry = |
| 1268 { | 494 GetEntry(kGpuControlListEntryDualGPUTest_VendorOnlyActiveSecondaryGPU); |
| 1269 "id": 1, | 495 // By default, secondary GPU is active. |
| 1270 "os": { | 496 EntryShouldApply(entry); |
| 1271 "type": "macosx" | 497 ActivatePrimaryGPU(); |
| 1272 }, | 498 EntryShouldNotApply(entry); |
| 1273 "vendor_id": "0x8086", | |
| 1274 "multi_gpu_category": "active", | |
| 1275 "features": [ | |
| 1276 "test_feature_0" | |
| 1277 ] | |
| 1278 } | |
| 1279 ); | |
| 1280 // By default, secondary GPU is active. | |
| 1281 EntryShouldApply(json); | |
| 1282 | |
| 1283 ActivatePrimaryGPU(); | |
| 1284 EntryShouldNotApply(json); | |
| 1285 } | 499 } |
| 1286 | 500 |
| 1287 TEST_F(GpuControlListEntryDualGPUTest, ActivePrimaryGPU) { | 501 TEST_F(GpuControlListEntryDualGPUTest, ActivePrimaryGPU) { |
| 1288 const std::string json = LONG_STRING_CONST( | 502 const Entry& entry = |
| 1289 { | 503 GetEntry(kGpuControlListEntryDualGPUTest_ActivePrimaryGPU); |
| 1290 "id": 1, | 504 // By default, secondary GPU is active. |
| 1291 "os": { | 505 EntryShouldNotApply(entry); |
| 1292 "type": "macosx" | 506 ActivatePrimaryGPU(); |
| 1293 }, | 507 EntryShouldApply(entry); |
| 1294 "vendor_id": "0x10de", | |
| 1295 "device_id": ["0x0640"], | |
| 1296 "multi_gpu_category": "active", | |
| 1297 "features": [ | |
| 1298 "test_feature_0" | |
| 1299 ] | |
| 1300 } | |
| 1301 ); | |
| 1302 // By default, secondary GPU is active. | |
| 1303 EntryShouldNotApply(json); | |
| 1304 | |
| 1305 ActivatePrimaryGPU(); | |
| 1306 EntryShouldApply(json); | |
| 1307 } | 508 } |
| 1308 | 509 |
| 1309 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActivePrimaryGPU) { | 510 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActivePrimaryGPU) { |
| 1310 const std::string json = LONG_STRING_CONST( | 511 const Entry& entry = |
| 1311 { | 512 GetEntry(kGpuControlListEntryDualGPUTest_VendorOnlyActivePrimaryGPU); |
| 1312 "id": 1, | 513 // By default, secondary GPU is active. |
| 1313 "os": { | 514 EntryShouldNotApply(entry); |
| 1314 "type": "macosx" | 515 ActivatePrimaryGPU(); |
| 1315 }, | 516 EntryShouldApply(entry); |
| 1316 "vendor_id": "0x10de", | 517 } |
| 1317 "multi_gpu_category": "active", | 518 |
| 1318 "features": [ | 519 TEST_F(GpuControlListEntryTest, PixelShaderVersion) { |
| 1319 "test_feature_0" | 520 const Entry& entry = GetEntry(kGpuControlListEntryTest_PixelShaderVersion); |
| 1320 ] | 521 EXPECT_EQ(kOsAny, entry.conditions.os_type); |
| 1321 } | 522 GPUInfo gpu_info; |
| 1322 ); | 523 gpu_info.pixel_shader_version = "3.2"; |
| 1323 // By default, secondary GPU is active. | 524 EXPECT_TRUE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 1324 EntryShouldNotApply(json); | 525 gpu_info.pixel_shader_version = "4.9"; |
| 1325 | 526 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.9", gpu_info)); |
| 1326 ActivatePrimaryGPU(); | 527 } |
| 1327 EntryShouldApply(json); | 528 |
| 1328 } | 529 TEST_F(GpuControlListEntryTest, OsVersionZero) { |
| 1329 | 530 { |
| 1330 TEST_F(GpuControlListEntryTest, LinuxKernelVersion) { | 531 const Entry& entry = GetEntry(kGpuControlListEntryTest_OsVersionZeroLT); |
|
Ken Russell (switch to Gerrit)
2017/03/31 02:37:06
Any loss in coverage due to removal of this test?
Zhenyao Mo
2017/03/31 21:17:00
Thanks for catching this. This can no longer be t
| |
| 1331 const std::string json = LONG_STRING_CONST( | 532 // All forms of version 0 is considered invalid. |
| 1332 { | 533 EXPECT_FALSE(entry.Contains(kOsAndroid, "0", gpu_info())); |
| 1333 "id": 1, | 534 EXPECT_FALSE(entry.Contains(kOsAndroid, "0.0", gpu_info())); |
| 1334 "os": { | 535 EXPECT_FALSE(entry.Contains(kOsAndroid, "0.00.0", gpu_info())); |
| 1335 "type": "linux", | 536 } |
| 1336 "version": { | 537 { |
| 1337 "op": "<", | 538 const Entry& entry = GetEntry(kGpuControlListEntryTest_OsVersionZeroAny); |
| 1338 "value": "3.19.1" | 539 EXPECT_TRUE(entry.Contains(kOsAndroid, "0", gpu_info())); |
| 1339 } | 540 EXPECT_TRUE(entry.Contains(kOsAndroid, "0.0", gpu_info())); |
| 1340 }, | 541 EXPECT_TRUE(entry.Contains(kOsAndroid, "0.00.0", gpu_info())); |
| 1341 "vendor_id": "0x8086", | 542 } |
| 1342 "features": [ | 543 } |
| 1343 "test_feature_0" | 544 |
| 1344 ] | 545 TEST_F(GpuControlListEntryTest, OsComparison) { |
| 1345 } | 546 { |
| 1346 ); | 547 const Entry& entry = GetEntry(kGpuControlListEntryTest_OsComparisonAny); |
| 1347 ScopedEntry entry(GetEntryFromString(json)); | 548 const GpuControlList::OsType os_type[] = {kOsWin, kOsLinux, kOsMacosx, |
| 1348 EXPECT_TRUE(entry.get() != NULL); | 549 kOsChromeOS, kOsAndroid}; |
| 1349 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | 550 for (size_t i = 0; i < arraysize(os_type); ++i) { |
| 1350 | 551 EXPECT_TRUE(entry.Contains(os_type[i], std::string(), gpu_info())); |
| 552 EXPECT_TRUE(entry.Contains(os_type[i], "7.8", gpu_info())); | |
| 553 } | |
| 554 } | |
| 555 { | |
| 556 const Entry& entry = GetEntry(kGpuControlListEntryTest_OsComparisonGE); | |
| 557 EXPECT_FALSE(entry.Contains(kOsMacosx, "10.8.3", gpu_info())); | |
| 558 EXPECT_FALSE(entry.Contains(kOsLinux, "10", gpu_info())); | |
| 559 EXPECT_FALSE(entry.Contains(kOsChromeOS, "13", gpu_info())); | |
| 560 EXPECT_FALSE(entry.Contains(kOsAndroid, "7", gpu_info())); | |
| 561 EXPECT_FALSE(entry.Contains(kOsWin, std::string(), gpu_info())); | |
| 562 EXPECT_TRUE(entry.Contains(kOsWin, "6", gpu_info())); | |
| 563 EXPECT_TRUE(entry.Contains(kOsWin, "6.1", gpu_info())); | |
| 564 EXPECT_TRUE(entry.Contains(kOsWin, "7", gpu_info())); | |
| 565 EXPECT_FALSE(entry.Contains(kOsWin, "5", gpu_info())); | |
| 566 } | |
| 567 } | |
| 568 | |
| 569 TEST_F(GpuControlListEntryTest, ExceptionWithoutVendorId) { | |
| 570 const Entry& entry = | |
| 571 GetEntry(kGpuControlListEntryTest_ExceptionWithoutVendorId); | |
| 572 EXPECT_EQ(0x8086u, entry.exceptions[0].vendor_id); | |
| 573 EXPECT_EQ(0x8086u, entry.exceptions[1].vendor_id); | |
| 1351 GPUInfo gpu_info; | 574 GPUInfo gpu_info; |
| 1352 gpu_info.gpu.vendor_id = 0x8086; | 575 gpu_info.gpu.vendor_id = 0x8086; |
| 1353 | 576 gpu_info.gpu.device_id = 0x2a02; |
| 1354 EXPECT_TRUE(entry->Contains(GpuControlList::kOsLinux, | 577 gpu_info.driver_version = "9.1"; |
| 1355 "3.13.0-63-generic", | 578 EXPECT_FALSE(entry.Contains(kOsLinux, "2.1", gpu_info)); |
| 1356 gpu_info)); | 579 gpu_info.driver_version = "9.0"; |
| 1357 EXPECT_FALSE(entry->Contains(GpuControlList::kOsLinux, | 580 EXPECT_TRUE(entry.Contains(kOsLinux, "2.1", gpu_info)); |
| 1358 "3.19.2-1-generic", | 581 } |
| 1359 gpu_info)); | 582 |
| 1360 } | 583 TEST_F(GpuControlListEntryTest, MultiGpuStyleAMDSwitchable) { |
| 1361 | 584 GPUInfo gpu_info; |
| 1362 TEST_F(GpuControlListEntryTest, PixelShaderVersion) { | 585 gpu_info.amd_switchable = true; |
| 1363 const std::string json = LONG_STRING_CONST( | 586 gpu_info.gpu.vendor_id = 0x1002; |
| 1364 {"id" : 1, "pixel_shader_version" : {"op" : "<", "value" : "4.1"}}); | 587 gpu_info.gpu.device_id = 0x6760; |
| 1365 ScopedEntry entry(GetEntryFromString(json)); | 588 GPUInfo::GPUDevice integrated_gpu; |
| 1366 EXPECT_TRUE(entry.get() != NULL); | 589 integrated_gpu.vendor_id = 0x8086; |
| 1367 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | 590 integrated_gpu.device_id = 0x0116; |
| 1368 | 591 gpu_info.secondary_gpus.push_back(integrated_gpu); |
| 1369 GPUInfo gpu_info; | 592 |
| 1370 gpu_info.pixel_shader_version = "3.2"; | 593 { // amd_switchable_discrete entry |
| 1371 EXPECT_TRUE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 594 const Entry& entry = |
| 1372 gpu_info.pixel_shader_version = "4.9"; | 595 GetEntry(kGpuControlListEntryTest_MultiGpuStyleAMDSwitchableDiscrete); |
| 1373 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info)); | 596 // Integrated GPU is active |
| 597 gpu_info.gpu.active = false; | |
| 598 gpu_info.secondary_gpus[0].active = true; | |
| 599 EXPECT_FALSE(entry.Contains(kOsWin, "6.0", gpu_info)); | |
| 600 // Discrete GPU is active | |
| 601 gpu_info.gpu.active = true; | |
| 602 gpu_info.secondary_gpus[0].active = false; | |
| 603 EXPECT_TRUE(entry.Contains(kOsWin, "6.0", gpu_info)); | |
| 604 } | |
| 605 | |
| 606 { // amd_switchable_integrated entry | |
| 607 const Entry& entry = | |
| 608 GetEntry(kGpuControlListEntryTest_MultiGpuStyleAMDSwitchableIntegrated); | |
| 609 // Discrete GPU is active | |
| 610 gpu_info.gpu.active = true; | |
| 611 gpu_info.secondary_gpus[0].active = false; | |
| 612 EXPECT_FALSE(entry.Contains(kOsWin, "6.0", gpu_info)); | |
| 613 // Integrated GPU is active | |
| 614 gpu_info.gpu.active = false; | |
| 615 gpu_info.secondary_gpus[0].active = true; | |
| 616 EXPECT_TRUE(entry.Contains(kOsWin, "6.0", gpu_info)); | |
| 617 // For non AMD switchable | |
| 618 gpu_info.amd_switchable = false; | |
| 619 EXPECT_FALSE(entry.Contains(kOsWin, "6.0", gpu_info)); | |
| 620 } | |
| 621 } | |
| 622 | |
| 623 TEST_F(GpuControlListEntryTest, InProcessGPU) { | |
| 624 const Entry& entry = GetEntry(kGpuControlListEntryTest_InProcessGPU); | |
| 625 GPUInfo gpu_info; | |
| 626 gpu_info.in_process_gpu = true; | |
| 627 EXPECT_TRUE(entry.Contains(kOsWin, "6.1", gpu_info)); | |
| 628 gpu_info.in_process_gpu = false; | |
| 629 EXPECT_FALSE(entry.Contains(kOsWin, "6.1", gpu_info)); | |
| 630 } | |
| 631 | |
| 632 TEST_F(GpuControlListEntryTest, SameGPUTwiceTest) { | |
| 633 const Entry& entry = GetEntry(kGpuControlListEntryTest_SameGPUTwiceTest); | |
| 634 GPUInfo gpu_info; | |
| 635 gpu_info.gpu.vendor_id = 0x8086; | |
| 636 // Real case on Intel GMA* on Windows | |
| 637 gpu_info.secondary_gpus.push_back(gpu_info.gpu); | |
| 638 EXPECT_TRUE(entry.Contains(kOsWin, "6.1", gpu_info)); | |
| 639 } | |
| 640 | |
| 641 TEST_F(GpuControlListEntryTest, NVidiaNumberingScheme) { | |
| 642 const Entry& entry = GetEntry(kGpuControlListEntryTest_NVidiaNumberingScheme); | |
| 643 GPUInfo gpu_info; | |
| 644 gpu_info.gl_vendor = "NVIDIA"; | |
| 645 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | |
| 646 gpu_info.gpu.vendor_id = 0x10de; | |
| 647 gpu_info.gpu.device_id = 0x0640; | |
| 648 // test the same driver version number | |
| 649 gpu_info.driver_version = "8.17.12.6973"; | |
| 650 EXPECT_TRUE(entry.Contains(kOsWin, "7.0", gpu_info)); | |
| 651 // test a lower driver version number | |
| 652 gpu_info.driver_version = "8.15.11.8647"; | |
| 653 EXPECT_TRUE(entry.Contains(kOsWin, "7.0", gpu_info)); | |
| 654 // test a higher driver version number | |
| 655 gpu_info.driver_version = "9.18.13.2723"; | |
| 656 EXPECT_FALSE(entry.Contains(kOsWin, "7.0", gpu_info)); | |
| 657 } | |
| 658 | |
| 659 TEST_F(GpuControlListEntryTest, DirectRendering) { | |
| 660 const Entry& entry = GetEntry(kGpuControlListEntryTest_DirectRendering); | |
| 661 GPUInfo gpu_info; | |
| 662 gpu_info.direct_rendering = true; | |
| 663 EXPECT_FALSE(entry.Contains(kOsLinux, "7.0", gpu_info)); | |
| 664 gpu_info.direct_rendering = false; | |
| 665 EXPECT_TRUE(entry.Contains(kOsLinux, "7.0", gpu_info)); | |
| 1374 } | 666 } |
| 1375 | 667 |
| 1376 } // namespace gpu | 668 } // namespace gpu |
| 1377 | |
| OLD | NEW |