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 <stdint.h> |
| 6 |
5 #include <vector> | 7 #include <vector> |
6 | 8 |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/config/gpu_control_list.h" | 10 #include "gpu/config/gpu_control_list.h" |
9 #include "gpu/config/gpu_info.h" | 11 #include "gpu/config/gpu_info.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 const char kOsVersion[] = "10.6.4"; | 14 const char kOsVersion[] = "10.6.4"; |
13 const uint32 kIntelVendorId = 0x8086; | 15 const uint32_t kIntelVendorId = 0x8086; |
14 const uint32 kNvidiaVendorId = 0x10de; | 16 const uint32_t kNvidiaVendorId = 0x10de; |
15 const uint32 kAmdVendorId = 0x10de; | 17 const uint32_t kAmdVendorId = 0x10de; |
16 | 18 |
17 #define LONG_STRING_CONST(...) #__VA_ARGS__ | 19 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
18 | 20 |
19 #define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size()) | 21 #define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size()) |
20 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ | 22 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ |
21 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) | 23 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) |
22 | 24 |
23 namespace gpu { | 25 namespace gpu { |
24 | 26 |
25 enum TestFeatureType { | 27 enum TestFeatureType { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | 131 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
130 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 132 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
131 | 133 |
132 // Invalid json input should not change the current control_list settings. | 134 // Invalid json input should not change the current control_list settings. |
133 const std::string invalid_json = "invalid"; | 135 const std::string invalid_json = "invalid"; |
134 | 136 |
135 EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs)); | 137 EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs)); |
136 features = control_list->MakeDecision( | 138 features = control_list->MakeDecision( |
137 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | 139 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); |
138 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 140 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
139 std::vector<uint32> entries; | 141 std::vector<uint32_t> entries; |
140 control_list->GetDecisionEntries(&entries, false); | 142 control_list->GetDecisionEntries(&entries, false); |
141 ASSERT_EQ(1u, entries.size()); | 143 ASSERT_EQ(1u, entries.size()); |
142 EXPECT_EQ(5u, entries[0]); | 144 EXPECT_EQ(5u, entries[0]); |
143 EXPECT_EQ(5u, control_list->max_entry_id()); | 145 EXPECT_EQ(5u, control_list->max_entry_id()); |
144 } | 146 } |
145 | 147 |
146 TEST_F(GpuControlListTest, VendorOnAllOsEntry) { | 148 TEST_F(GpuControlListTest, VendorOnAllOsEntry) { |
147 // ControlList a vendor on all OS. | 149 // ControlList a vendor on all OS. |
148 const std::string vendor_json = LONG_STRING_CONST( | 150 const std::string vendor_json = LONG_STRING_CONST( |
149 { | 151 { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 ] | 273 ] |
272 } | 274 } |
273 ] | 275 ] |
274 } | 276 } |
275 ); | 277 ); |
276 scoped_ptr<GpuControlList> control_list(Create()); | 278 scoped_ptr<GpuControlList> control_list(Create()); |
277 EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs)); | 279 EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs)); |
278 std::set<int> features = control_list->MakeDecision( | 280 std::set<int> features = control_list->MakeDecision( |
279 GpuControlList::kOsWin, kOsVersion, gpu_info()); | 281 GpuControlList::kOsWin, kOsVersion, gpu_info()); |
280 EXPECT_EMPTY_SET(features); | 282 EXPECT_EMPTY_SET(features); |
281 std::vector<uint32> flag_entries; | 283 std::vector<uint32_t> flag_entries; |
282 control_list->GetDecisionEntries(&flag_entries, false); | 284 control_list->GetDecisionEntries(&flag_entries, false); |
283 EXPECT_EQ(0u, flag_entries.size()); | 285 EXPECT_EQ(0u, flag_entries.size()); |
284 control_list->GetDecisionEntries(&flag_entries, true); | 286 control_list->GetDecisionEntries(&flag_entries, true); |
285 EXPECT_EQ(1u, flag_entries.size()); | 287 EXPECT_EQ(1u, flag_entries.size()); |
286 } | 288 } |
287 | 289 |
288 TEST_F(GpuControlListTest, NeedsMoreInfo) { | 290 TEST_F(GpuControlListTest, NeedsMoreInfo) { |
289 const std::string json = LONG_STRING_CONST( | 291 const std::string json = LONG_STRING_CONST( |
290 { | 292 { |
291 "name": "gpu control list", | 293 "name": "gpu control list", |
(...skipping 19 matching lines...) Expand all Loading... |
311 GPUInfo gpu_info; | 313 GPUInfo gpu_info; |
312 gpu_info.gpu.vendor_id = kNvidiaVendorId; | 314 gpu_info.gpu.vendor_id = kNvidiaVendorId; |
313 | 315 |
314 scoped_ptr<GpuControlList> control_list(Create()); | 316 scoped_ptr<GpuControlList> control_list(Create()); |
315 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | 317 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); |
316 | 318 |
317 std::set<int> features = control_list->MakeDecision( | 319 std::set<int> features = control_list->MakeDecision( |
318 GpuControlList::kOsWin, kOsVersion, gpu_info); | 320 GpuControlList::kOsWin, kOsVersion, gpu_info); |
319 EXPECT_EMPTY_SET(features); | 321 EXPECT_EMPTY_SET(features); |
320 EXPECT_TRUE(control_list->needs_more_info()); | 322 EXPECT_TRUE(control_list->needs_more_info()); |
321 std::vector<uint32> decision_entries; | 323 std::vector<uint32_t> decision_entries; |
322 control_list->GetDecisionEntries(&decision_entries, false); | 324 control_list->GetDecisionEntries(&decision_entries, false); |
323 EXPECT_EQ(0u, decision_entries.size()); | 325 EXPECT_EQ(0u, decision_entries.size()); |
324 | 326 |
325 gpu_info.driver_version = "11"; | 327 gpu_info.driver_version = "11"; |
326 features = control_list->MakeDecision( | 328 features = control_list->MakeDecision( |
327 GpuControlList::kOsWin, kOsVersion, gpu_info); | 329 GpuControlList::kOsWin, kOsVersion, gpu_info); |
328 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 330 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
329 EXPECT_FALSE(control_list->needs_more_info()); | 331 EXPECT_FALSE(control_list->needs_more_info()); |
330 control_list->GetDecisionEntries(&decision_entries, false); | 332 control_list->GetDecisionEntries(&decision_entries, false); |
331 EXPECT_EQ(1u, decision_entries.size()); | 333 EXPECT_EQ(1u, decision_entries.size()); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 GpuControlList::kOsWin, kOsVersion, gpu_info); | 658 GpuControlList::kOsWin, kOsVersion, gpu_info); |
657 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 659 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
658 | 660 |
659 gpu_info.in_process_gpu = false; | 661 gpu_info.in_process_gpu = false; |
660 features = control_list->MakeDecision( | 662 features = control_list->MakeDecision( |
661 GpuControlList::kOsWin, kOsVersion, gpu_info); | 663 GpuControlList::kOsWin, kOsVersion, gpu_info); |
662 EXPECT_EMPTY_SET(features); | 664 EXPECT_EMPTY_SET(features); |
663 } | 665 } |
664 | 666 |
665 } // namespace gpu | 667 } // namespace gpu |
OLD | NEW |