OLD | NEW |
(Empty) | |
| 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 <vector> |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "content/browser/gpu/gpu_control_list.h" |
| 9 #include "content/public/common/gpu_info.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 const char kOsVersion[] = "10.6.4"; |
| 13 const uint32 kIntelVendorId = 0x8086; |
| 14 const uint32 kIntelDeviceId = 0x0166; // 3rd Gen Core Graphics |
| 15 const uint32 kNvidiaVendorId = 0x10de; |
| 16 const uint32 kNvidiaDeviceId = 0x0fd5; // GeForce GT 650M |
| 17 |
| 18 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
| 19 |
| 20 namespace content { |
| 21 |
| 22 enum TestFeatureType { |
| 23 TEST_FEATURE_0 = 1, |
| 24 TEST_FEATURE_1 = 1 << 2, |
| 25 TEST_FEATURE_2 = 1 << 3, |
| 26 }; |
| 27 |
| 28 class GpuControlListTest : public testing::Test { |
| 29 public: |
| 30 GpuControlListTest() { } |
| 31 |
| 32 virtual ~GpuControlListTest() { } |
| 33 |
| 34 const GPUInfo& gpu_info() const { |
| 35 return gpu_info_; |
| 36 } |
| 37 |
| 38 GpuControlList* Create() { |
| 39 GpuControlList* rt = new GpuControlList(); |
| 40 rt->AddFeature("test_feature_0", TEST_FEATURE_0); |
| 41 rt->AddFeature("test_feature_1", TEST_FEATURE_1); |
| 42 rt->AddFeature("test_feature_2", TEST_FEATURE_2); |
| 43 return rt; |
| 44 } |
| 45 |
| 46 protected: |
| 47 virtual void SetUp() { |
| 48 gpu_info_.gpu.vendor_id = kNvidiaVendorId; |
| 49 gpu_info_.gpu.device_id = 0x0640; |
| 50 gpu_info_.driver_vendor = "NVIDIA"; |
| 51 gpu_info_.driver_version = "1.6.18"; |
| 52 gpu_info_.driver_date = "7-14-2009"; |
| 53 gpu_info_.machine_model = "MacBookPro 7.1"; |
| 54 gpu_info_.gl_vendor = "NVIDIA Corporation"; |
| 55 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 56 gpu_info_.performance_stats.graphics = 5.0; |
| 57 gpu_info_.performance_stats.gaming = 5.0; |
| 58 gpu_info_.performance_stats.overall = 5.0; |
| 59 } |
| 60 |
| 61 virtual void TearDown() { |
| 62 } |
| 63 |
| 64 private: |
| 65 GPUInfo gpu_info_; |
| 66 }; |
| 67 |
| 68 TEST_F(GpuControlListTest, DefaultControlListSettings) { |
| 69 scoped_ptr<GpuControlList> control_list(Create()); |
| 70 // Default control list settings: all feature are allowed. |
| 71 int features = control_list->MakeDecision( |
| 72 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 73 EXPECT_EQ(0, features); |
| 74 } |
| 75 |
| 76 TEST_F(GpuControlListTest, EmptyControlList) { |
| 77 // Empty list: all features are allowed. |
| 78 const std::string empty_list_json = LONG_STRING_CONST( |
| 79 { |
| 80 "name": "gpu control list", |
| 81 "version": "2.5", |
| 82 "entries": [ |
| 83 ] |
| 84 } |
| 85 ); |
| 86 scoped_ptr<GpuControlList> control_list(Create()); |
| 87 |
| 88 EXPECT_TRUE(control_list->LoadList(empty_list_json, |
| 89 GpuControlList::kAllOs)); |
| 90 EXPECT_EQ("2.5", control_list->GetVersion()); |
| 91 int features = control_list->MakeDecision( |
| 92 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 93 EXPECT_EQ(0, features); |
| 94 } |
| 95 |
| 96 TEST_F(GpuControlListTest, DetailedEntryAndInvalidJson) { |
| 97 // exact setting. |
| 98 const std::string exact_list_json = LONG_STRING_CONST( |
| 99 { |
| 100 "name": "gpu control list", |
| 101 "version": "0.1", |
| 102 "entries": [ |
| 103 { |
| 104 "id": 5, |
| 105 "os": { |
| 106 "type": "macosx", |
| 107 "version": { |
| 108 "op": "=", |
| 109 "number": "10.6.4" |
| 110 } |
| 111 }, |
| 112 "vendor_id": "0x10de", |
| 113 "device_id": ["0x0640"], |
| 114 "driver_version": { |
| 115 "op": "=", |
| 116 "number": "1.6.18" |
| 117 }, |
| 118 "features": [ |
| 119 "test_feature_0" |
| 120 ] |
| 121 } |
| 122 ] |
| 123 } |
| 124 ); |
| 125 scoped_ptr<GpuControlList> control_list(Create()); |
| 126 |
| 127 EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs)); |
| 128 int features = control_list->MakeDecision( |
| 129 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 130 EXPECT_EQ(TEST_FEATURE_0, features); |
| 131 |
| 132 // Invalid json input should not change the current control_list settings. |
| 133 const std::string invalid_json = "invalid"; |
| 134 |
| 135 EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs)); |
| 136 features = control_list->MakeDecision( |
| 137 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 138 EXPECT_EQ(TEST_FEATURE_0, features); |
| 139 std::vector<uint32> entries; |
| 140 control_list->GetDecisionEntries(&entries, false); |
| 141 ASSERT_EQ(1u, entries.size()); |
| 142 EXPECT_EQ(5u, entries[0]); |
| 143 EXPECT_EQ(5u, control_list->max_entry_id()); |
| 144 } |
| 145 |
| 146 TEST_F(GpuControlListTest, VendorOnAllOsEntry) { |
| 147 // ControlList a vendor on all OS. |
| 148 const std::string vendor_json = LONG_STRING_CONST( |
| 149 { |
| 150 "name": "gpu control list", |
| 151 "version": "0.1", |
| 152 "entries": [ |
| 153 { |
| 154 "id": 1, |
| 155 "vendor_id": "0x10de", |
| 156 "features": [ |
| 157 "test_feature_0" |
| 158 ] |
| 159 } |
| 160 ] |
| 161 } |
| 162 ); |
| 163 scoped_ptr<GpuControlList> control_list(Create()); |
| 164 |
| 165 // ControlList entries won't be filtered to the current OS only upon loading. |
| 166 EXPECT_TRUE(control_list->LoadList(vendor_json, GpuControlList::kAllOs)); |
| 167 int features = control_list->MakeDecision( |
| 168 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 169 EXPECT_EQ(TEST_FEATURE_0, features); |
| 170 features = control_list->MakeDecision( |
| 171 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 172 EXPECT_EQ(TEST_FEATURE_0, features); |
| 173 features = control_list->MakeDecision( |
| 174 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 175 EXPECT_EQ(TEST_FEATURE_0, features); |
| 176 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) || \ |
| 177 defined(OS_OPENBSD) |
| 178 // ControlList entries will be filtered to the current OS only upon loading. |
| 179 EXPECT_TRUE(control_list->LoadList( |
| 180 vendor_json, GpuControlList::kCurrentOsOnly)); |
| 181 features = control_list->MakeDecision( |
| 182 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 183 EXPECT_EQ(TEST_FEATURE_0, features); |
| 184 features = control_list->MakeDecision( |
| 185 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 186 EXPECT_EQ(TEST_FEATURE_0, features); |
| 187 features = control_list->MakeDecision( |
| 188 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 189 EXPECT_EQ(TEST_FEATURE_0, features); |
| 190 #endif |
| 191 } |
| 192 |
| 193 TEST_F(GpuControlListTest, VendorOnLinuxEntry) { |
| 194 // ControlList a vendor on Linux only. |
| 195 const std::string vendor_linux_json = LONG_STRING_CONST( |
| 196 { |
| 197 "name": "gpu control list", |
| 198 "version": "0.1", |
| 199 "entries": [ |
| 200 { |
| 201 "id": 1, |
| 202 "os": { |
| 203 "type": "linux" |
| 204 }, |
| 205 "vendor_id": "0x10de", |
| 206 "features": [ |
| 207 "test_feature_0" |
| 208 ] |
| 209 } |
| 210 ] |
| 211 } |
| 212 ); |
| 213 scoped_ptr<GpuControlList> control_list(Create()); |
| 214 |
| 215 EXPECT_TRUE(control_list->LoadList( |
| 216 vendor_linux_json, GpuControlList::kAllOs)); |
| 217 int features = control_list->MakeDecision( |
| 218 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 219 EXPECT_EQ(0, features); |
| 220 features = control_list->MakeDecision( |
| 221 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 222 EXPECT_EQ(0, features); |
| 223 features = control_list->MakeDecision( |
| 224 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 225 EXPECT_EQ(TEST_FEATURE_0, features); |
| 226 } |
| 227 |
| 228 TEST_F(GpuControlListTest, AllExceptNVidiaOnLinuxEntry) { |
| 229 // ControlList all cards in Linux except NVIDIA. |
| 230 const std::string linux_except_nvidia_json = LONG_STRING_CONST( |
| 231 { |
| 232 "name": "gpu control list", |
| 233 "version": "0.1", |
| 234 "entries": [ |
| 235 { |
| 236 "id": 1, |
| 237 "os": { |
| 238 "type": "linux" |
| 239 }, |
| 240 "exceptions": [ |
| 241 { |
| 242 "vendor_id": "0x10de" |
| 243 } |
| 244 ], |
| 245 "features": [ |
| 246 "test_feature_0" |
| 247 ] |
| 248 } |
| 249 ] |
| 250 } |
| 251 ); |
| 252 scoped_ptr<GpuControlList> control_list(Create()); |
| 253 |
| 254 EXPECT_TRUE(control_list->LoadList( |
| 255 linux_except_nvidia_json, GpuControlList::kAllOs)); |
| 256 int features = control_list->MakeDecision( |
| 257 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 258 EXPECT_EQ(0, features); |
| 259 features = control_list->MakeDecision( |
| 260 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 261 EXPECT_EQ(0, features); |
| 262 features = control_list->MakeDecision( |
| 263 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 264 EXPECT_EQ(0, features); |
| 265 } |
| 266 |
| 267 TEST_F(GpuControlListTest, AllExceptIntelOnLinuxEntry) { |
| 268 // ControlList all cards in Linux except Intel. |
| 269 const std::string linux_except_intel_json = LONG_STRING_CONST( |
| 270 { |
| 271 "name": "gpu control list", |
| 272 "version": "0.1", |
| 273 "entries": [ |
| 274 { |
| 275 "id": 1, |
| 276 "os": { |
| 277 "type": "linux" |
| 278 }, |
| 279 "exceptions": [ |
| 280 { |
| 281 "vendor_id": "0x8086" |
| 282 } |
| 283 ], |
| 284 "features": [ |
| 285 "test_feature_0" |
| 286 ] |
| 287 } |
| 288 ] |
| 289 } |
| 290 ); |
| 291 scoped_ptr<GpuControlList> control_list(Create()); |
| 292 |
| 293 EXPECT_TRUE(control_list->LoadList( |
| 294 linux_except_intel_json, GpuControlList::kAllOs)); |
| 295 int features = control_list->MakeDecision( |
| 296 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 297 EXPECT_EQ(0, features); |
| 298 features = control_list->MakeDecision( |
| 299 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 300 EXPECT_EQ(0, features); |
| 301 features = control_list->MakeDecision( |
| 302 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 303 EXPECT_EQ(TEST_FEATURE_0, features); |
| 304 } |
| 305 |
| 306 TEST_F(GpuControlListTest, DateOnWindowsEntry) { |
| 307 // ControlList all drivers earlier than 2010-5-8 in Windows. |
| 308 const std::string date_windows_json = LONG_STRING_CONST( |
| 309 { |
| 310 "name": "gpu control list", |
| 311 "version": "0.1", |
| 312 "entries": [ |
| 313 { |
| 314 "id": 1, |
| 315 "os": { |
| 316 "type": "win" |
| 317 }, |
| 318 "driver_date": { |
| 319 "op": "<", |
| 320 "number": "2010.5.8" |
| 321 }, |
| 322 "features": [ |
| 323 "test_feature_0" |
| 324 ] |
| 325 } |
| 326 ] |
| 327 } |
| 328 ); |
| 329 scoped_ptr<GpuControlList> control_list(Create()); |
| 330 |
| 331 GPUInfo gpu_info; |
| 332 gpu_info.driver_date = "7-14-2009"; |
| 333 |
| 334 EXPECT_TRUE(control_list->LoadList( |
| 335 date_windows_json, GpuControlList::kAllOs)); |
| 336 int features = control_list->MakeDecision( |
| 337 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 338 EXPECT_EQ(0, features); |
| 339 features = control_list->MakeDecision( |
| 340 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 341 EXPECT_EQ(0, features); |
| 342 features = control_list->MakeDecision( |
| 343 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 344 EXPECT_EQ(TEST_FEATURE_0, features); |
| 345 |
| 346 gpu_info.driver_date = "07-14-2009"; |
| 347 features = control_list->MakeDecision( |
| 348 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 349 EXPECT_EQ(TEST_FEATURE_0, features); |
| 350 |
| 351 gpu_info.driver_date = "1-1-2010"; |
| 352 features = control_list->MakeDecision( |
| 353 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 354 EXPECT_EQ(TEST_FEATURE_0, features); |
| 355 |
| 356 gpu_info.driver_date = "05-07-2010"; |
| 357 features = control_list->MakeDecision( |
| 358 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 359 EXPECT_EQ(TEST_FEATURE_0, features); |
| 360 |
| 361 gpu_info.driver_date = "5-8-2010"; |
| 362 features = control_list->MakeDecision( |
| 363 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 364 EXPECT_EQ(0, features); |
| 365 |
| 366 gpu_info.driver_date = "5-9-2010"; |
| 367 features = control_list->MakeDecision( |
| 368 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 369 EXPECT_EQ(0, features); |
| 370 |
| 371 gpu_info.driver_date = "6-2-2010"; |
| 372 features = control_list->MakeDecision( |
| 373 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 374 EXPECT_EQ(0, features); |
| 375 } |
| 376 |
| 377 TEST_F(GpuControlListTest, MultipleDevicesEntry) { |
| 378 const std::string devices_json = LONG_STRING_CONST( |
| 379 { |
| 380 "name": "gpu control list", |
| 381 "version": "0.1", |
| 382 "entries": [ |
| 383 { |
| 384 "id": 1, |
| 385 "vendor_id": "0x10de", |
| 386 "device_id": ["0x1023", "0x0640"], |
| 387 "features": [ |
| 388 "test_feature_0" |
| 389 ] |
| 390 } |
| 391 ] |
| 392 } |
| 393 ); |
| 394 scoped_ptr<GpuControlList> control_list(Create()); |
| 395 |
| 396 EXPECT_TRUE(control_list->LoadList(devices_json, GpuControlList::kAllOs)); |
| 397 int features = control_list->MakeDecision( |
| 398 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
| 399 EXPECT_EQ(TEST_FEATURE_0, features); |
| 400 features = control_list->MakeDecision( |
| 401 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 402 EXPECT_EQ(TEST_FEATURE_0, features); |
| 403 features = control_list->MakeDecision( |
| 404 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 405 EXPECT_EQ(TEST_FEATURE_0, features); |
| 406 } |
| 407 |
| 408 TEST_F(GpuControlListTest, ChromeOSEntry) { |
| 409 const std::string devices_json = LONG_STRING_CONST( |
| 410 { |
| 411 "name": "gpu control list", |
| 412 "version": "0.1", |
| 413 "entries": [ |
| 414 { |
| 415 "id": 1, |
| 416 "os": { |
| 417 "type": "chromeos" |
| 418 }, |
| 419 "features": [ |
| 420 "test_feature_0" |
| 421 ] |
| 422 } |
| 423 ] |
| 424 } |
| 425 ); |
| 426 scoped_ptr<GpuControlList> control_list(Create()); |
| 427 |
| 428 EXPECT_TRUE(control_list->LoadList(devices_json, GpuControlList::kAllOs)); |
| 429 int features = control_list->MakeDecision( |
| 430 GpuControlList::kOsChromeOS, kOsVersion, gpu_info()); |
| 431 EXPECT_EQ(TEST_FEATURE_0, features); |
| 432 features = control_list->MakeDecision( |
| 433 GpuControlList::kOsLinux, kOsVersion, gpu_info()); |
| 434 EXPECT_EQ(0, features); |
| 435 } |
| 436 |
| 437 TEST_F(GpuControlListTest, ChromeVersionEntry) { |
| 438 const std::string browser_version_json = LONG_STRING_CONST( |
| 439 { |
| 440 "name": "gpu control list", |
| 441 "version": "0.1", |
| 442 "entries": [ |
| 443 { |
| 444 "id": 1, |
| 445 "browser_version": { |
| 446 "op": ">=", |
| 447 "number": "10" |
| 448 }, |
| 449 "features": [ |
| 450 "test_feature_0" |
| 451 ] |
| 452 } |
| 453 ] |
| 454 } |
| 455 ); |
| 456 scoped_ptr<GpuControlList> control_list9(Create()); |
| 457 EXPECT_TRUE(control_list9->LoadList( |
| 458 "9.0", browser_version_json, GpuControlList::kAllOs)); |
| 459 int features = control_list9->MakeDecision( |
| 460 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 461 EXPECT_EQ(0, features); |
| 462 |
| 463 scoped_ptr<GpuControlList> control_list10(Create()); |
| 464 EXPECT_TRUE(control_list10->LoadList( |
| 465 "10.0", browser_version_json, GpuControlList::kAllOs)); |
| 466 features = control_list10->MakeDecision( |
| 467 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 468 EXPECT_EQ(TEST_FEATURE_0, features); |
| 469 } |
| 470 |
| 471 TEST_F(GpuControlListTest, MalformedVendor) { |
| 472 // vendor_id is defined as list instead of string. |
| 473 const std::string malformed_vendor_json = LONG_STRING_CONST( |
| 474 { |
| 475 "name": "gpu control list", |
| 476 "version": "0.1", |
| 477 "entries": [ |
| 478 { |
| 479 "id": 1, |
| 480 "vendor_id": "[0x10de]", |
| 481 "features": [ |
| 482 "test_feature_0" |
| 483 ] |
| 484 } |
| 485 ] |
| 486 } |
| 487 ); |
| 488 scoped_ptr<GpuControlList> control_list(Create()); |
| 489 |
| 490 EXPECT_FALSE(control_list->LoadList( |
| 491 malformed_vendor_json, GpuControlList::kAllOs)); |
| 492 } |
| 493 |
| 494 TEST_F(GpuControlListTest, UnknownField) { |
| 495 const std::string unknown_field_json = LONG_STRING_CONST( |
| 496 { |
| 497 "name": "gpu control list", |
| 498 "version": "0.1", |
| 499 "entries": [ |
| 500 { |
| 501 "id": 1, |
| 502 "unknown_field": 0, |
| 503 "features": [ |
| 504 "test_feature_1" |
| 505 ] |
| 506 }, |
| 507 { |
| 508 "id": 2, |
| 509 "features": [ |
| 510 "test_feature_0" |
| 511 ] |
| 512 } |
| 513 ] |
| 514 } |
| 515 ); |
| 516 scoped_ptr<GpuControlList> control_list(Create()); |
| 517 |
| 518 EXPECT_TRUE(control_list->LoadList( |
| 519 unknown_field_json, GpuControlList::kAllOs)); |
| 520 EXPECT_EQ(1u, control_list->num_entries()); |
| 521 EXPECT_TRUE(control_list->contains_unknown_fields()); |
| 522 int features = control_list->MakeDecision( |
| 523 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 524 EXPECT_EQ(TEST_FEATURE_0, features); |
| 525 } |
| 526 |
| 527 TEST_F(GpuControlListTest, UnknownExceptionField) { |
| 528 const std::string unknown_exception_field_json = LONG_STRING_CONST( |
| 529 { |
| 530 "name": "gpu control list", |
| 531 "version": "0.1", |
| 532 "entries": [ |
| 533 { |
| 534 "id": 1, |
| 535 "unknown_field": 0, |
| 536 "features": [ |
| 537 "test_feature_2" |
| 538 ] |
| 539 }, |
| 540 { |
| 541 "id": 2, |
| 542 "exceptions": [ |
| 543 { |
| 544 "unknown_field": 0 |
| 545 } |
| 546 ], |
| 547 "features": [ |
| 548 "test_feature_1" |
| 549 ] |
| 550 }, |
| 551 { |
| 552 "id": 3, |
| 553 "features": [ |
| 554 "test_feature_0" |
| 555 ] |
| 556 } |
| 557 ] |
| 558 } |
| 559 ); |
| 560 scoped_ptr<GpuControlList> control_list(Create()); |
| 561 |
| 562 EXPECT_TRUE(control_list->LoadList( |
| 563 unknown_exception_field_json, GpuControlList::kAllOs)); |
| 564 EXPECT_EQ(1u, control_list->num_entries()); |
| 565 EXPECT_TRUE(control_list->contains_unknown_fields()); |
| 566 int features = control_list->MakeDecision( |
| 567 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 568 EXPECT_EQ(TEST_FEATURE_0, features); |
| 569 } |
| 570 |
| 571 TEST_F(GpuControlListTest, UnknownFeature) { |
| 572 const std::string unknown_feature_json = LONG_STRING_CONST( |
| 573 { |
| 574 "name": "gpu control list", |
| 575 "version": "0.1", |
| 576 "entries": [ |
| 577 { |
| 578 "id": 1, |
| 579 "features": [ |
| 580 "some_unknown_feature", |
| 581 "test_feature_0" |
| 582 ] |
| 583 } |
| 584 ] |
| 585 } |
| 586 ); |
| 587 scoped_ptr<GpuControlList> control_list(Create()); |
| 588 |
| 589 EXPECT_TRUE(control_list->LoadList( |
| 590 unknown_feature_json, GpuControlList::kAllOs)); |
| 591 EXPECT_EQ(1u, control_list->num_entries()); |
| 592 EXPECT_TRUE(control_list->contains_unknown_fields()); |
| 593 int features = control_list->MakeDecision( |
| 594 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 595 EXPECT_EQ(TEST_FEATURE_0, features); |
| 596 } |
| 597 |
| 598 TEST_F(GpuControlListTest, GlVendor) { |
| 599 const std::string gl_vendor_json = LONG_STRING_CONST( |
| 600 { |
| 601 "name": "gpu control list", |
| 602 "version": "0.1", |
| 603 "entries": [ |
| 604 { |
| 605 "id": 1, |
| 606 "gl_vendor": { |
| 607 "op": "beginwith", |
| 608 "value": "NVIDIA" |
| 609 }, |
| 610 "features": [ |
| 611 "test_feature_0" |
| 612 ] |
| 613 } |
| 614 ] |
| 615 } |
| 616 ); |
| 617 scoped_ptr<GpuControlList> control_list(Create()); |
| 618 EXPECT_TRUE(control_list->LoadList(gl_vendor_json, GpuControlList::kAllOs)); |
| 619 int features = control_list->MakeDecision( |
| 620 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 621 EXPECT_EQ(TEST_FEATURE_0, features); |
| 622 } |
| 623 |
| 624 TEST_F(GpuControlListTest, GlRenderer) { |
| 625 const std::string gl_renderer_json = LONG_STRING_CONST( |
| 626 { |
| 627 "name": "gpu control list", |
| 628 "version": "0.1", |
| 629 "entries": [ |
| 630 { |
| 631 "id": 1, |
| 632 "gl_renderer": { |
| 633 "op": "contains", |
| 634 "value": "GeForce" |
| 635 }, |
| 636 "features": [ |
| 637 "test_feature_0" |
| 638 ] |
| 639 } |
| 640 ] |
| 641 } |
| 642 ); |
| 643 |
| 644 scoped_ptr<GpuControlList> control_list(Create()); |
| 645 EXPECT_TRUE(control_list->LoadList(gl_renderer_json, GpuControlList::kAllOs)); |
| 646 int features = control_list->MakeDecision( |
| 647 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 648 EXPECT_EQ(TEST_FEATURE_0, features); |
| 649 } |
| 650 |
| 651 TEST_F(GpuControlListTest, PerfGraphics) { |
| 652 const std::string json = LONG_STRING_CONST( |
| 653 { |
| 654 "name": "gpu control list", |
| 655 "version": "0.1", |
| 656 "entries": [ |
| 657 { |
| 658 "id": 1, |
| 659 "perf_graphics": { |
| 660 "op": "<", |
| 661 "value": "6.0" |
| 662 }, |
| 663 "features": [ |
| 664 "test_feature_0" |
| 665 ] |
| 666 } |
| 667 ] |
| 668 } |
| 669 ); |
| 670 scoped_ptr<GpuControlList> control_list(Create()); |
| 671 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 672 int features = control_list->MakeDecision( |
| 673 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 674 EXPECT_EQ(TEST_FEATURE_0, features); |
| 675 } |
| 676 |
| 677 TEST_F(GpuControlListTest, PerfGaming) { |
| 678 const std::string json = LONG_STRING_CONST( |
| 679 { |
| 680 "name": "gpu control list", |
| 681 "version": "0.1", |
| 682 "entries": [ |
| 683 { |
| 684 "id": 1, |
| 685 "perf_gaming": { |
| 686 "op": "<=", |
| 687 "value": "4.0" |
| 688 }, |
| 689 "features": [ |
| 690 "test_feature_0" |
| 691 ] |
| 692 } |
| 693 ] |
| 694 } |
| 695 ); |
| 696 scoped_ptr<GpuControlList> control_list(Create()); |
| 697 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 698 int features = control_list->MakeDecision( |
| 699 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 700 EXPECT_EQ(0, features); |
| 701 } |
| 702 |
| 703 TEST_F(GpuControlListTest, PerfOverall) { |
| 704 const std::string json = LONG_STRING_CONST( |
| 705 { |
| 706 "name": "gpu control list", |
| 707 "version": "0.1", |
| 708 "entries": [ |
| 709 { |
| 710 "id": 1, |
| 711 "perf_overall": { |
| 712 "op": "between", |
| 713 "value": "1.0", |
| 714 "value2": "9.0" |
| 715 }, |
| 716 "features": [ |
| 717 "test_feature_0" |
| 718 ] |
| 719 } |
| 720 ] |
| 721 } |
| 722 ); |
| 723 scoped_ptr<GpuControlList> control_list(Create()); |
| 724 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 725 int features = control_list->MakeDecision( |
| 726 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 727 EXPECT_EQ(TEST_FEATURE_0, features); |
| 728 } |
| 729 |
| 730 TEST_F(GpuControlListTest, DisabledEntry) { |
| 731 const std::string disabled_json = LONG_STRING_CONST( |
| 732 { |
| 733 "name": "gpu control list", |
| 734 "version": "0.1", |
| 735 "entries": [ |
| 736 { |
| 737 "id": 1, |
| 738 "disabled": true, |
| 739 "features": [ |
| 740 "test_feature_0" |
| 741 ] |
| 742 } |
| 743 ] |
| 744 } |
| 745 ); |
| 746 scoped_ptr<GpuControlList> control_list(Create()); |
| 747 EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs)); |
| 748 int features = control_list->MakeDecision( |
| 749 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
| 750 EXPECT_EQ(features, 0); |
| 751 std::vector<uint32> flag_entries; |
| 752 control_list->GetDecisionEntries(&flag_entries, false); |
| 753 EXPECT_EQ(0u, flag_entries.size()); |
| 754 control_list->GetDecisionEntries(&flag_entries, true); |
| 755 EXPECT_EQ(1u, flag_entries.size()); |
| 756 } |
| 757 |
| 758 TEST_F(GpuControlListTest, Optimus) { |
| 759 const std::string optimus_json = LONG_STRING_CONST( |
| 760 { |
| 761 "name": "gpu control list", |
| 762 "version": "0.1", |
| 763 "entries": [ |
| 764 { |
| 765 "id": 1, |
| 766 "os": { |
| 767 "type": "linux" |
| 768 }, |
| 769 "multi_gpu_style": "optimus", |
| 770 "features": [ |
| 771 "test_feature_0" |
| 772 ] |
| 773 } |
| 774 ] |
| 775 } |
| 776 ); |
| 777 GPUInfo gpu_info; |
| 778 gpu_info.optimus = true; |
| 779 |
| 780 scoped_ptr<GpuControlList> control_list(Create()); |
| 781 EXPECT_TRUE(control_list->LoadList(optimus_json, GpuControlList::kAllOs)); |
| 782 int features = control_list->MakeDecision( |
| 783 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 784 EXPECT_EQ(TEST_FEATURE_0, features); |
| 785 } |
| 786 |
| 787 TEST_F(GpuControlListTest, AMDSwitchable) { |
| 788 const std::string amd_switchable_json = LONG_STRING_CONST( |
| 789 { |
| 790 "name": "gpu control list", |
| 791 "version": "0.1", |
| 792 "entries": [ |
| 793 { |
| 794 "id": 1, |
| 795 "os": { |
| 796 "type": "macosx" |
| 797 }, |
| 798 "multi_gpu_style": "amd_switchable", |
| 799 "features": [ |
| 800 "test_feature_0" |
| 801 ] |
| 802 } |
| 803 ] |
| 804 } |
| 805 ); |
| 806 GPUInfo gpu_info; |
| 807 gpu_info.amd_switchable = true; |
| 808 |
| 809 scoped_ptr<GpuControlList> control_list(Create()); |
| 810 EXPECT_TRUE(control_list->LoadList(amd_switchable_json, |
| 811 GpuControlList::kAllOs)); |
| 812 int features = control_list->MakeDecision( |
| 813 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 814 EXPECT_EQ(TEST_FEATURE_0, features); |
| 815 } |
| 816 |
| 817 TEST_F(GpuControlListTest, LexicalDriverVersion) { |
| 818 const std::string lexical_json = LONG_STRING_CONST( |
| 819 { |
| 820 "name": "gpu control list", |
| 821 "version": "0.1", |
| 822 "entries": [ |
| 823 { |
| 824 "id": 1, |
| 825 "os": { |
| 826 "type": "linux" |
| 827 }, |
| 828 "vendor_id": "0x1002", |
| 829 "driver_version": { |
| 830 "op": "<", |
| 831 "style": "lexical", |
| 832 "number": "8.201" |
| 833 }, |
| 834 "features": [ |
| 835 "test_feature_0" |
| 836 ] |
| 837 } |
| 838 ] |
| 839 } |
| 840 ); |
| 841 GPUInfo gpu_info; |
| 842 gpu_info.gpu.vendor_id = 0x1002; |
| 843 |
| 844 scoped_ptr<GpuControlList> control_list(Create()); |
| 845 EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs)); |
| 846 |
| 847 gpu_info.driver_version = "8.001.100"; |
| 848 int features = control_list->MakeDecision( |
| 849 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 850 EXPECT_EQ(TEST_FEATURE_0, features); |
| 851 |
| 852 gpu_info.driver_version = "8.109"; |
| 853 features = control_list->MakeDecision( |
| 854 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 855 EXPECT_EQ(TEST_FEATURE_0, features); |
| 856 |
| 857 gpu_info.driver_version = "8.10900"; |
| 858 features = control_list->MakeDecision( |
| 859 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 860 EXPECT_EQ(TEST_FEATURE_0, features); |
| 861 |
| 862 gpu_info.driver_version = "8.109.100"; |
| 863 features = control_list->MakeDecision( |
| 864 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 865 EXPECT_EQ(TEST_FEATURE_0, features); |
| 866 |
| 867 gpu_info.driver_version = "8.2"; |
| 868 features = control_list->MakeDecision( |
| 869 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 870 EXPECT_EQ(TEST_FEATURE_0, features); |
| 871 |
| 872 gpu_info.driver_version = "8.20"; |
| 873 features = control_list->MakeDecision( |
| 874 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 875 EXPECT_EQ(TEST_FEATURE_0, features); |
| 876 |
| 877 gpu_info.driver_version = "8.200"; |
| 878 features = control_list->MakeDecision( |
| 879 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 880 EXPECT_EQ(TEST_FEATURE_0, features); |
| 881 |
| 882 gpu_info.driver_version = "8.20.100"; |
| 883 features = control_list->MakeDecision( |
| 884 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 885 EXPECT_EQ(TEST_FEATURE_0, features); |
| 886 |
| 887 gpu_info.driver_version = "8.201"; |
| 888 features = control_list->MakeDecision( |
| 889 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 890 EXPECT_EQ(0, features); |
| 891 |
| 892 gpu_info.driver_version = "8.2010"; |
| 893 features = control_list->MakeDecision( |
| 894 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 895 EXPECT_EQ(0, features); |
| 896 |
| 897 gpu_info.driver_version = "8.21"; |
| 898 features = control_list->MakeDecision( |
| 899 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 900 EXPECT_EQ(0, features); |
| 901 |
| 902 gpu_info.driver_version = "8.21.100"; |
| 903 features = control_list->MakeDecision( |
| 904 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 905 EXPECT_EQ(0, features); |
| 906 |
| 907 gpu_info.driver_version = "9.002"; |
| 908 features = control_list->MakeDecision( |
| 909 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 910 EXPECT_EQ(0, features); |
| 911 |
| 912 gpu_info.driver_version = "9.201"; |
| 913 features = control_list->MakeDecision( |
| 914 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 915 EXPECT_EQ(0, features); |
| 916 |
| 917 gpu_info.driver_version = "12"; |
| 918 features = control_list->MakeDecision( |
| 919 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 920 EXPECT_EQ(0, features); |
| 921 |
| 922 gpu_info.driver_version = "12.201"; |
| 923 features = control_list->MakeDecision( |
| 924 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 925 EXPECT_EQ(0, features); |
| 926 } |
| 927 |
| 928 TEST_F(GpuControlListTest, LexicalDriverVersion2) { |
| 929 const std::string lexical_json = LONG_STRING_CONST( |
| 930 { |
| 931 "name": "gpu control list", |
| 932 "version": "0.1", |
| 933 "entries": [ |
| 934 { |
| 935 "id": 1, |
| 936 "os": { |
| 937 "type": "linux" |
| 938 }, |
| 939 "vendor_id": "0x1002", |
| 940 "driver_version": { |
| 941 "op": "<", |
| 942 "style": "lexical", |
| 943 "number": "9.002" |
| 944 }, |
| 945 "features": [ |
| 946 "test_feature_0" |
| 947 ] |
| 948 } |
| 949 ] |
| 950 } |
| 951 ); |
| 952 GPUInfo gpu_info; |
| 953 gpu_info.gpu.vendor_id = 0x1002; |
| 954 |
| 955 scoped_ptr<GpuControlList> control_list(Create()); |
| 956 EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs)); |
| 957 |
| 958 gpu_info.driver_version = "8.001.100"; |
| 959 int features = control_list->MakeDecision( |
| 960 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 961 EXPECT_EQ(TEST_FEATURE_0, features); |
| 962 |
| 963 gpu_info.driver_version = "8.109"; |
| 964 features = control_list->MakeDecision( |
| 965 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 966 EXPECT_EQ(TEST_FEATURE_0, features); |
| 967 |
| 968 gpu_info.driver_version = "8.10900"; |
| 969 features = control_list->MakeDecision( |
| 970 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 971 EXPECT_EQ(TEST_FEATURE_0, features); |
| 972 |
| 973 gpu_info.driver_version = "8.109.100"; |
| 974 features = control_list->MakeDecision( |
| 975 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 976 EXPECT_EQ(TEST_FEATURE_0, features); |
| 977 |
| 978 gpu_info.driver_version = "8.2"; |
| 979 features = control_list->MakeDecision( |
| 980 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 981 EXPECT_EQ(TEST_FEATURE_0, features); |
| 982 |
| 983 gpu_info.driver_version = "8.20"; |
| 984 features = control_list->MakeDecision( |
| 985 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 986 EXPECT_EQ(TEST_FEATURE_0, features); |
| 987 |
| 988 gpu_info.driver_version = "8.200"; |
| 989 features = control_list->MakeDecision( |
| 990 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 991 EXPECT_EQ(TEST_FEATURE_0, features); |
| 992 |
| 993 gpu_info.driver_version = "8.20.100"; |
| 994 features = control_list->MakeDecision( |
| 995 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 996 EXPECT_EQ(TEST_FEATURE_0, features); |
| 997 |
| 998 gpu_info.driver_version = "8.201"; |
| 999 features = control_list->MakeDecision( |
| 1000 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1001 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1002 |
| 1003 gpu_info.driver_version = "8.2010"; |
| 1004 features = control_list->MakeDecision( |
| 1005 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1006 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1007 |
| 1008 gpu_info.driver_version = "8.21"; |
| 1009 features = control_list->MakeDecision( |
| 1010 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1011 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1012 |
| 1013 gpu_info.driver_version = "8.21.100"; |
| 1014 features = control_list->MakeDecision( |
| 1015 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1016 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1017 |
| 1018 gpu_info.driver_version = "9.002"; |
| 1019 features = control_list->MakeDecision( |
| 1020 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1021 EXPECT_EQ(0, features); |
| 1022 |
| 1023 gpu_info.driver_version = "9.201"; |
| 1024 features = control_list->MakeDecision( |
| 1025 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1026 EXPECT_EQ(0, features); |
| 1027 |
| 1028 gpu_info.driver_version = "12"; |
| 1029 features = control_list->MakeDecision( |
| 1030 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1031 EXPECT_EQ(0, features); |
| 1032 |
| 1033 gpu_info.driver_version = "12.201"; |
| 1034 features = control_list->MakeDecision( |
| 1035 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1036 EXPECT_EQ(0, features); |
| 1037 } |
| 1038 |
| 1039 TEST_F(GpuControlListTest, LexicalDriverVersion3) { |
| 1040 const std::string lexical_json = LONG_STRING_CONST( |
| 1041 { |
| 1042 "name": "gpu control list", |
| 1043 "version": "0.1", |
| 1044 "entries": [ |
| 1045 { |
| 1046 "id": 1, |
| 1047 "os": { |
| 1048 "type": "linux" |
| 1049 }, |
| 1050 "vendor_id": "0x1002", |
| 1051 "driver_version": { |
| 1052 "op": "=", |
| 1053 "style": "lexical", |
| 1054 "number": "8.76" |
| 1055 }, |
| 1056 "features": [ |
| 1057 "test_feature_0" |
| 1058 ] |
| 1059 } |
| 1060 ] |
| 1061 } |
| 1062 ); |
| 1063 GPUInfo gpu_info; |
| 1064 gpu_info.gpu.vendor_id = 0x1002; |
| 1065 |
| 1066 scoped_ptr<GpuControlList> control_list(Create()); |
| 1067 EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs)); |
| 1068 |
| 1069 gpu_info.driver_version = "8.76"; |
| 1070 int features = control_list->MakeDecision( |
| 1071 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1072 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1073 |
| 1074 gpu_info.driver_version = "8.768"; |
| 1075 features = control_list->MakeDecision( |
| 1076 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1077 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1078 |
| 1079 gpu_info.driver_version = "8.76.8"; |
| 1080 features = control_list->MakeDecision( |
| 1081 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1082 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1083 } |
| 1084 |
| 1085 TEST_F(GpuControlListTest, MultipleGPUsAny) { |
| 1086 const std::string multi_gpu_json = LONG_STRING_CONST( |
| 1087 { |
| 1088 "name": "gpu control list", |
| 1089 "version": "0.1", |
| 1090 "entries": [ |
| 1091 { |
| 1092 "id": 1, |
| 1093 "os": { |
| 1094 "type": "macosx" |
| 1095 }, |
| 1096 "vendor_id": "0x8086", |
| 1097 "device_id": ["0x0166"], |
| 1098 "multi_gpu_category": "any", |
| 1099 "features": [ |
| 1100 "test_feature_0" |
| 1101 ] |
| 1102 } |
| 1103 ] |
| 1104 } |
| 1105 ); |
| 1106 GPUInfo gpu_info; |
| 1107 gpu_info.gpu.vendor_id = kNvidiaVendorId; |
| 1108 gpu_info.gpu.device_id = kNvidiaDeviceId; |
| 1109 |
| 1110 scoped_ptr<GpuControlList> control_list(Create()); |
| 1111 EXPECT_TRUE(control_list->LoadList(multi_gpu_json, |
| 1112 GpuControlList::kAllOs)); |
| 1113 int features = control_list->MakeDecision( |
| 1114 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1115 EXPECT_EQ(0, features); |
| 1116 |
| 1117 GPUInfo::GPUDevice gpu_device; |
| 1118 gpu_device.vendor_id = kIntelVendorId; |
| 1119 gpu_device.device_id = kIntelDeviceId; |
| 1120 gpu_info.secondary_gpus.push_back(gpu_device); |
| 1121 features = control_list->MakeDecision( |
| 1122 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1123 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1124 } |
| 1125 |
| 1126 TEST_F(GpuControlListTest, MultipleGPUsSecondary) { |
| 1127 const std::string multi_gpu_json = LONG_STRING_CONST( |
| 1128 { |
| 1129 "name": "gpu control list", |
| 1130 "version": "0.1", |
| 1131 "entries": [ |
| 1132 { |
| 1133 "id": 1, |
| 1134 "os": { |
| 1135 "type": "macosx" |
| 1136 }, |
| 1137 "vendor_id": "0x8086", |
| 1138 "device_id": ["0x0166"], |
| 1139 "multi_gpu_category": "secondary", |
| 1140 "features": [ |
| 1141 "test_feature_0" |
| 1142 ] |
| 1143 } |
| 1144 ] |
| 1145 } |
| 1146 ); |
| 1147 GPUInfo gpu_info; |
| 1148 gpu_info.gpu.vendor_id = kNvidiaVendorId; |
| 1149 gpu_info.gpu.device_id = kNvidiaDeviceId; |
| 1150 |
| 1151 scoped_ptr<GpuControlList> control_list(Create()); |
| 1152 EXPECT_TRUE(control_list->LoadList(multi_gpu_json, |
| 1153 GpuControlList::kAllOs)); |
| 1154 int features = control_list->MakeDecision( |
| 1155 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1156 EXPECT_EQ(0, features); |
| 1157 |
| 1158 GPUInfo::GPUDevice gpu_device; |
| 1159 gpu_device.vendor_id = kIntelVendorId; |
| 1160 gpu_device.device_id = kIntelDeviceId; |
| 1161 gpu_info.secondary_gpus.push_back(gpu_device); |
| 1162 features = control_list->MakeDecision( |
| 1163 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1164 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1165 } |
| 1166 |
| 1167 TEST_F(GpuControlListTest, NeedsMoreInfo) { |
| 1168 const std::string json = LONG_STRING_CONST( |
| 1169 { |
| 1170 "name": "gpu control list", |
| 1171 "version": "0.1", |
| 1172 "entries": [ |
| 1173 { |
| 1174 "id": 1, |
| 1175 "os": { |
| 1176 "type": "linux" |
| 1177 }, |
| 1178 "vendor_id": "0x8086", |
| 1179 "driver_version": { |
| 1180 "op": "<", |
| 1181 "number": "10.7" |
| 1182 }, |
| 1183 "features": [ |
| 1184 "test_feature_0" |
| 1185 ] |
| 1186 } |
| 1187 ] |
| 1188 } |
| 1189 ); |
| 1190 GPUInfo gpu_info; |
| 1191 gpu_info.gpu.vendor_id = kIntelVendorId; |
| 1192 |
| 1193 scoped_ptr<GpuControlList> control_list(Create()); |
| 1194 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 1195 |
| 1196 // The case this entry does not apply. |
| 1197 int features = control_list->MakeDecision( |
| 1198 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1199 EXPECT_EQ(0, features); |
| 1200 EXPECT_FALSE(control_list->needs_more_info()); |
| 1201 |
| 1202 // The case this entry might apply, but need more info. |
| 1203 features = control_list->MakeDecision( |
| 1204 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1205 EXPECT_EQ(0, features); |
| 1206 EXPECT_TRUE(control_list->needs_more_info()); |
| 1207 |
| 1208 // The case we have full info, and this entry applies. |
| 1209 gpu_info.driver_version = "10.6"; |
| 1210 features = control_list->MakeDecision( |
| 1211 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1212 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1213 EXPECT_FALSE(control_list->needs_more_info()); |
| 1214 |
| 1215 // The case we have full info, and this entry does not apply. |
| 1216 gpu_info.driver_version = "10.8"; |
| 1217 features = control_list->MakeDecision( |
| 1218 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1219 EXPECT_EQ(0, features); |
| 1220 EXPECT_FALSE(control_list->needs_more_info()); |
| 1221 } |
| 1222 |
| 1223 TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) { |
| 1224 const std::string json = LONG_STRING_CONST( |
| 1225 { |
| 1226 "name": "gpu control list", |
| 1227 "version": "0.1", |
| 1228 "entries": [ |
| 1229 { |
| 1230 "id": 1, |
| 1231 "os": { |
| 1232 "type": "linux" |
| 1233 }, |
| 1234 "vendor_id": "0x8086", |
| 1235 "exceptions": [ |
| 1236 { |
| 1237 "gl_renderer": { |
| 1238 "op": "contains", |
| 1239 "value": "mesa" |
| 1240 } |
| 1241 } |
| 1242 ], |
| 1243 "features": [ |
| 1244 "test_feature_0" |
| 1245 ] |
| 1246 } |
| 1247 ] |
| 1248 } |
| 1249 ); |
| 1250 GPUInfo gpu_info; |
| 1251 gpu_info.gpu.vendor_id = kIntelVendorId; |
| 1252 |
| 1253 scoped_ptr<GpuControlList> control_list(Create()); |
| 1254 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 1255 |
| 1256 // The case this entry does not apply. |
| 1257 int features = control_list->MakeDecision( |
| 1258 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 1259 EXPECT_EQ(0, features); |
| 1260 EXPECT_FALSE(control_list->needs_more_info()); |
| 1261 |
| 1262 // The case this entry might apply, but need more info. |
| 1263 features = control_list->MakeDecision( |
| 1264 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1265 EXPECT_EQ(0, features); |
| 1266 EXPECT_TRUE(control_list->needs_more_info()); |
| 1267 |
| 1268 // The case we have full info, and the exception applies (so the entry |
| 1269 // does not apply). |
| 1270 gpu_info.gl_renderer = "mesa"; |
| 1271 features = control_list->MakeDecision( |
| 1272 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1273 EXPECT_EQ(0, features); |
| 1274 EXPECT_FALSE(control_list->needs_more_info()); |
| 1275 |
| 1276 // The case we have full info, and this entry applies. |
| 1277 gpu_info.gl_renderer = "my renderer"; |
| 1278 features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion, |
| 1279 gpu_info); |
| 1280 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1281 EXPECT_FALSE(control_list->needs_more_info()); |
| 1282 } |
| 1283 |
| 1284 TEST_F(GpuControlListTest, IgnorableEntries) { |
| 1285 // If an entry will not change the control_list decisions, then it should not |
| 1286 // trigger the needs_more_info flag. |
| 1287 const std::string json = LONG_STRING_CONST( |
| 1288 { |
| 1289 "name": "gpu control list", |
| 1290 "version": "0.1", |
| 1291 "entries": [ |
| 1292 { |
| 1293 "id": 1, |
| 1294 "os": { |
| 1295 "type": "linux" |
| 1296 }, |
| 1297 "vendor_id": "0x8086", |
| 1298 "features": [ |
| 1299 "test_feature_0" |
| 1300 ] |
| 1301 }, |
| 1302 { |
| 1303 "id": 2, |
| 1304 "os": { |
| 1305 "type": "linux" |
| 1306 }, |
| 1307 "vendor_id": "0x8086", |
| 1308 "driver_version": { |
| 1309 "op": "<", |
| 1310 "number": "10.7" |
| 1311 }, |
| 1312 "features": [ |
| 1313 "test_feature_0" |
| 1314 ] |
| 1315 } |
| 1316 ] |
| 1317 } |
| 1318 ); |
| 1319 GPUInfo gpu_info; |
| 1320 gpu_info.gpu.vendor_id = kIntelVendorId; |
| 1321 |
| 1322 scoped_ptr<GpuControlList> control_list(Create()); |
| 1323 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 1324 int features = control_list->MakeDecision( |
| 1325 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 1326 EXPECT_EQ(TEST_FEATURE_0, features); |
| 1327 EXPECT_FALSE(control_list->needs_more_info()); |
| 1328 } |
| 1329 |
| 1330 } // namespace content |
| 1331 |
OLD | NEW |