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