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 "gpu/config/gpu_control_list_jsons.h" | |
9 #include "gpu/config/gpu_info.h" | |
10 #include "gpu/config/gpu_switching_list.h" | |
11 #include "gpu/config/gpu_switching_option.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 #define LONG_STRING_CONST(...) #__VA_ARGS__ | |
15 | |
16 const char kOsVersion[] = "10.6.4"; | |
17 | |
18 namespace gpu { | |
19 | |
20 class GpuSwitchingListTest : public testing::Test { | |
21 public: | |
22 GpuSwitchingListTest() { } | |
23 | |
24 virtual ~GpuSwitchingListTest() { } | |
25 | |
26 const GPUInfo& gpu_info() const { | |
27 return gpu_info_; | |
28 } | |
29 | |
30 protected: | |
31 virtual void SetUp() { | |
32 gpu_info_.gpu.vendor_id = 0x10de; | |
33 gpu_info_.gpu.device_id = 0x0640; | |
34 gpu_info_.driver_vendor = "NVIDIA"; | |
35 gpu_info_.driver_version = "1.6.18"; | |
36 gpu_info_.driver_date = "7-14-2009"; | |
37 gpu_info_.machine_model = "MacBookPro 7.1"; | |
38 gpu_info_.gl_vendor = "NVIDIA Corporation"; | |
39 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | |
40 gpu_info_.performance_stats.graphics = 5.0; | |
41 gpu_info_.performance_stats.gaming = 5.0; | |
42 gpu_info_.performance_stats.overall = 5.0; | |
43 } | |
44 | |
45 virtual void TearDown() { | |
46 } | |
47 | |
48 private: | |
49 GPUInfo gpu_info_; | |
50 }; | |
51 | |
52 TEST_F(GpuSwitchingListTest, CurrentSwitchingListValidation) { | |
53 scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create()); | |
54 EXPECT_TRUE(switching_list->LoadList( | |
55 kGpuSwitchingListJson, GpuControlList::kAllOs)); | |
56 } | |
57 | |
58 TEST_F(GpuSwitchingListTest, GpuSwitching) { | |
59 const std::string json = LONG_STRING_CONST( | |
60 { | |
61 "name": "gpu switching list", | |
62 "version": "0.1", | |
63 "entries": [ | |
64 { | |
65 "id": 1, | |
66 "os": { | |
67 "type": "macosx" | |
68 }, | |
69 "features": [ | |
70 "force_discrete" | |
71 ] | |
72 }, | |
73 { | |
74 "id": 2, | |
75 "os": { | |
76 "type": "win" | |
77 }, | |
78 "features": [ | |
79 "force_integrated" | |
80 ] | |
81 } | |
82 ] | |
83 } | |
84 ); | |
85 scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create()); | |
86 EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs)); | |
87 std::set<int> switching = switching_list->MakeDecision( | |
88 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
89 EXPECT_EQ(1u, switching.size()); | |
90 EXPECT_EQ(1u, switching.count(GPU_SWITCHING_OPTION_FORCE_DISCRETE)); | |
91 std::vector<uint32> entries; | |
92 switching_list->GetDecisionEntries(&entries, false); | |
93 ASSERT_EQ(1u, entries.size()); | |
94 EXPECT_EQ(1u, entries[0]); | |
95 | |
96 switching_list.reset(GpuSwitchingList::Create()); | |
97 EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs)); | |
98 switching = switching_list->MakeDecision( | |
99 GpuControlList::kOsWin, kOsVersion, gpu_info()); | |
100 EXPECT_EQ(1u, switching.size()); | |
101 EXPECT_EQ(1u, switching.count(GPU_SWITCHING_OPTION_FORCE_INTEGRATED)); | |
102 switching_list->GetDecisionEntries(&entries, false); | |
103 ASSERT_EQ(1u, entries.size()); | |
104 EXPECT_EQ(2u, entries[0]); | |
105 } | |
106 | |
107 } // namespace gpu | |
108 | |
OLD | NEW |