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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/config/gpu_control_list.h" | 8 #include "gpu/config/gpu_control_list.h" |
9 #include "gpu/config/gpu_info.h" | 9 #include "gpu/config/gpu_info.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 const char kOsVersion[] = "10.6.4"; | 12 const char kOsVersion[] = "10.6.4"; |
13 const uint32 kIntelVendorId = 0x8086; | 13 const uint32 kIntelVendorId = 0x8086; |
14 const uint32 kNvidiaVendorId = 0x10de; | 14 const uint32 kNvidiaVendorId = 0x10de; |
| 15 const uint32 kAmdVendorId = 0x10de; |
15 | 16 |
16 #define LONG_STRING_CONST(...) #__VA_ARGS__ | 17 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
17 | 18 |
18 #define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size()) | 19 #define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size()) |
19 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ | 20 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ |
20 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) | 21 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) |
21 | 22 |
22 namespace gpu { | 23 namespace gpu { |
23 | 24 |
24 enum TestFeatureType { | 25 enum TestFeatureType { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 std::set<int> features = control_list->MakeDecision( | 442 std::set<int> features = control_list->MakeDecision( |
442 GpuControlList::kOsLinux, kOsVersion, gpu_info); | 443 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
443 EXPECT_EMPTY_SET(features); | 444 EXPECT_EMPTY_SET(features); |
444 | 445 |
445 gpu_info.driver_version = "9.0"; | 446 gpu_info.driver_version = "9.0"; |
446 features = control_list->MakeDecision( | 447 features = control_list->MakeDecision( |
447 GpuControlList::kOsLinux, kOsVersion, gpu_info); | 448 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
448 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 449 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
449 } | 450 } |
450 | 451 |
| 452 TEST_F(GpuControlListTest, AMDSwitchable) { |
| 453 GPUInfo gpu_info; |
| 454 gpu_info.amd_switchable = true; |
| 455 gpu_info.gpu.vendor_id = kAmdVendorId; |
| 456 gpu_info.gpu.device_id = 0x6760; |
| 457 GPUInfo::GPUDevice integrated_gpu; |
| 458 integrated_gpu.vendor_id = kIntelVendorId; |
| 459 integrated_gpu.device_id = 0x0116; |
| 460 gpu_info.secondary_gpus.push_back(integrated_gpu); |
| 461 |
| 462 { // amd_switchable_discrete entry |
| 463 const std::string json= LONG_STRING_CONST( |
| 464 { |
| 465 "name": "gpu control list", |
| 466 "version": "0.1", |
| 467 "entries": [ |
| 468 { |
| 469 "id": 1, |
| 470 "os": { |
| 471 "type": "win" |
| 472 }, |
| 473 "multi_gpu_style": "amd_switchable_discrete", |
| 474 "features": [ |
| 475 "test_feature_0" |
| 476 ] |
| 477 } |
| 478 ] |
| 479 } |
| 480 ); |
| 481 |
| 482 scoped_ptr<GpuControlList> control_list(Create()); |
| 483 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 484 |
| 485 // Integrated GPU is active |
| 486 gpu_info.gpu.active = false; |
| 487 gpu_info.secondary_gpus[0].active = true; |
| 488 std::set<int> features = control_list->MakeDecision( |
| 489 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 490 EXPECT_EMPTY_SET(features); |
| 491 |
| 492 // Discrete GPU is active |
| 493 gpu_info.gpu.active = true; |
| 494 gpu_info.secondary_gpus[0].active = false; |
| 495 features = control_list->MakeDecision( |
| 496 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 497 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
| 498 } |
| 499 |
| 500 { // amd_switchable_integrated entry |
| 501 const std::string json= LONG_STRING_CONST( |
| 502 { |
| 503 "name": "gpu control list", |
| 504 "version": "0.1", |
| 505 "entries": [ |
| 506 { |
| 507 "id": 1, |
| 508 "os": { |
| 509 "type": "win" |
| 510 }, |
| 511 "multi_gpu_style": "amd_switchable_integrated", |
| 512 "features": [ |
| 513 "test_feature_0" |
| 514 ] |
| 515 } |
| 516 ] |
| 517 } |
| 518 ); |
| 519 |
| 520 scoped_ptr<GpuControlList> control_list(Create()); |
| 521 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
| 522 |
| 523 // Discrete GPU is active |
| 524 gpu_info.gpu.active = true; |
| 525 gpu_info.secondary_gpus[0].active = false; |
| 526 std::set<int> features = control_list->MakeDecision( |
| 527 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 528 EXPECT_EMPTY_SET(features); |
| 529 |
| 530 // Integrated GPU is active |
| 531 gpu_info.gpu.active = false; |
| 532 gpu_info.secondary_gpus[0].active = true; |
| 533 features = control_list->MakeDecision( |
| 534 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 535 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
| 536 |
| 537 // For non AMD switchable |
| 538 gpu_info.amd_switchable = false; |
| 539 features = control_list->MakeDecision( |
| 540 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 541 EXPECT_EMPTY_SET(features); |
| 542 } |
| 543 } |
| 544 |
451 } // namespace gpu | 545 } // namespace gpu |
452 | 546 |
OLD | NEW |