Chromium Code Reviews| 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> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "gpu/config/gpu_control_list.h" | 10 #include "gpu/config/gpu_control_list.h" |
| 11 #include "gpu/config/gpu_control_list_testing_data.h" | |
| 11 #include "gpu/config/gpu_info.h" | 12 #include "gpu/config/gpu_info.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 const char kOsVersion[] = "10.6.4"; | 15 const char kOsVersion[] = "10.6.4"; |
| 15 const uint32_t kIntelVendorId = 0x8086; | 16 const uint32_t kIntelVendorId = 0x8086; |
| 16 const uint32_t kNvidiaVendorId = 0x10de; | 17 const uint32_t kNvidiaVendorId = 0x10de; |
| 17 const uint32_t kAmdVendorId = 0x10de; | |
| 18 | 18 |
| 19 #define LONG_STRING_CONST(...) #__VA_ARGS__ | 19 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
| 20 | 20 |
| 21 #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()) |
| 22 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ | 22 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \ |
| 23 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) | 23 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1) |
| 24 | 24 |
| 25 namespace gpu { | 25 namespace gpu { |
| 26 | 26 |
| 27 enum TestFeatureType { | |
| 28 TEST_FEATURE_0 = 1, | |
| 29 TEST_FEATURE_1 = 1 << 2, | |
| 30 TEST_FEATURE_2 = 1 << 3, | |
| 31 }; | |
| 32 | |
| 33 class GpuControlListTest : public testing::Test { | 27 class GpuControlListTest : public testing::Test { |
| 34 public: | 28 public: |
| 35 GpuControlListTest() { } | 29 typedef GpuControlList::Entry Entry; |
| 36 | 30 |
| 31 GpuControlListTest() {} | |
| 37 ~GpuControlListTest() override {} | 32 ~GpuControlListTest() override {} |
| 38 | 33 |
| 39 const GPUInfo& gpu_info() const { | 34 const GPUInfo& gpu_info() const { |
| 40 return gpu_info_; | 35 return gpu_info_; |
| 41 } | 36 } |
| 42 | 37 |
| 43 GpuControlList* Create() { | 38 GpuControlList* Create(size_t entry_count, const Entry* entries) { |
|
piman
2017/03/30 23:44:41
nit: return std::unique_ptr<GpuControlList>
Zhenyao Mo
2017/03/31 19:14:15
Done.
| |
| 44 GpuControlList* rt = new GpuControlList(); | 39 GpuControlListData data("0.1", entry_count, entries); |
| 40 GpuControlList* rt = new GpuControlList(data); | |
| 45 rt->AddSupportedFeature("test_feature_0", TEST_FEATURE_0); | 41 rt->AddSupportedFeature("test_feature_0", TEST_FEATURE_0); |
| 46 rt->AddSupportedFeature("test_feature_1", TEST_FEATURE_1); | 42 rt->AddSupportedFeature("test_feature_1", TEST_FEATURE_1); |
| 47 rt->AddSupportedFeature("test_feature_2", TEST_FEATURE_2); | 43 rt->AddSupportedFeature("test_feature_2", TEST_FEATURE_2); |
| 48 return rt; | 44 return rt; |
| 49 } | 45 } |
| 50 | 46 |
| 51 protected: | 47 protected: |
| 52 void SetUp() override { | 48 void SetUp() override { |
| 53 gpu_info_.gpu.vendor_id = kNvidiaVendorId; | 49 gpu_info_.gpu.vendor_id = kNvidiaVendorId; |
| 54 gpu_info_.gpu.device_id = 0x0640; | 50 gpu_info_.gpu.device_id = 0x0640; |
| 55 gpu_info_.driver_vendor = "NVIDIA"; | 51 gpu_info_.driver_vendor = "NVIDIA"; |
| 56 gpu_info_.driver_version = "1.6.18"; | 52 gpu_info_.driver_version = "1.6.18"; |
| 57 gpu_info_.driver_date = "7-14-2009"; | 53 gpu_info_.driver_date = "7-14-2009"; |
| 58 gpu_info_.machine_model_name = "MacBookPro"; | 54 gpu_info_.machine_model_name = "MacBookPro"; |
| 59 gpu_info_.machine_model_version = "7.1"; | 55 gpu_info_.machine_model_version = "7.1"; |
| 60 gpu_info_.gl_vendor = "NVIDIA Corporation"; | 56 gpu_info_.gl_vendor = "NVIDIA Corporation"; |
| 61 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | 57 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 62 } | 58 } |
| 63 | 59 |
| 64 void TearDown() override {} | 60 void TearDown() override {} |
| 65 | 61 |
| 66 private: | 62 private: |
| 67 GPUInfo gpu_info_; | 63 GPUInfo gpu_info_; |
| 68 }; | 64 }; |
| 69 | 65 |
| 70 TEST_F(GpuControlListTest, DefaultControlListSettings) { | 66 TEST_F(GpuControlListTest, NeedsMoreInfo) { |
| 71 std::unique_ptr<GpuControlList> control_list(Create()); | 67 const Entry kEntries[1] = { |
| 72 // Default control list settings: all feature are allowed. | 68 kGpuControlListTestingEntries[kGpuControlListTest_NeedsMoreInfo]}; |
| 73 std::set<int> features = control_list->MakeDecision( | 69 std::unique_ptr<GpuControlList> control_list(Create(1, kEntries)); |
| 74 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 75 EXPECT_EMPTY_SET(features); | |
| 76 } | |
| 77 | 70 |
| 78 TEST_F(GpuControlListTest, EmptyControlList) { | |
| 79 // Empty list: all features are allowed. | |
| 80 const std::string empty_list_json = LONG_STRING_CONST( | |
| 81 { | |
| 82 "name": "gpu control list", | |
| 83 "version": "2.5", | |
| 84 "entries": [ | |
| 85 ] | |
| 86 } | |
| 87 ); | |
| 88 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 89 | |
| 90 EXPECT_TRUE(control_list->LoadList(empty_list_json, | |
| 91 GpuControlList::kAllOs)); | |
| 92 EXPECT_EQ("2.5", control_list->version()); | |
| 93 std::set<int> features = control_list->MakeDecision( | |
| 94 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 95 EXPECT_EMPTY_SET(features); | |
| 96 } | |
| 97 | |
| 98 TEST_F(GpuControlListTest, DetailedEntryAndInvalidJson) { | |
| 99 // exact setting. | |
| 100 const std::string exact_list_json = LONG_STRING_CONST( | |
| 101 { | |
| 102 "name": "gpu control list", | |
| 103 "version": "0.1", | |
| 104 "entries": [ | |
| 105 { | |
| 106 "id": 5, | |
| 107 "os": { | |
| 108 "type": "macosx", | |
| 109 "version": { | |
| 110 "op": "=", | |
| 111 "value": "10.6.4" | |
| 112 } | |
| 113 }, | |
| 114 "vendor_id": "0x10de", | |
| 115 "device_id": ["0x0640"], | |
| 116 "driver_version": { | |
| 117 "op": "=", | |
| 118 "value": "1.6.18" | |
| 119 }, | |
| 120 "features": [ | |
| 121 "test_feature_0" | |
| 122 ] | |
| 123 } | |
| 124 ] | |
| 125 } | |
| 126 ); | |
| 127 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 128 | |
| 129 EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs)); | |
| 130 std::set<int> features = control_list->MakeDecision( | |
| 131 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 132 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 133 | |
| 134 // Invalid json input should not change the current control_list settings. | |
| 135 const std::string invalid_json = "invalid"; | |
| 136 | |
| 137 EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs)); | |
| 138 features = control_list->MakeDecision( | |
| 139 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 140 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 141 std::vector<uint32_t> entries; | |
| 142 control_list->GetDecisionEntries(&entries, false); | |
| 143 ASSERT_EQ(1u, entries.size()); | |
| 144 EXPECT_EQ(5u, entries[0]); | |
| 145 EXPECT_EQ(5u, control_list->max_entry_id()); | |
| 146 } | |
| 147 | |
| 148 TEST_F(GpuControlListTest, VendorOnAllOsEntry) { | |
| 149 // ControlList a vendor on all OS. | |
| 150 const std::string vendor_json = LONG_STRING_CONST( | |
| 151 { | |
| 152 "name": "gpu control list", | |
| 153 "version": "0.1", | |
| 154 "entries": [ | |
| 155 { | |
| 156 "id": 1, | |
| 157 "vendor_id": "0x10de", | |
| 158 "features": [ | |
| 159 "test_feature_0" | |
| 160 ] | |
| 161 } | |
| 162 ] | |
| 163 } | |
| 164 ); | |
| 165 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 166 | |
| 167 // ControlList entries won't be filtered to the current OS only upon loading. | |
| 168 EXPECT_TRUE(control_list->LoadList(vendor_json, GpuControlList::kAllOs)); | |
| 169 std::set<int> features = control_list->MakeDecision( | |
| 170 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 171 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 172 features = control_list->MakeDecision( | |
| 173 GpuControlList::kOsWin, kOsVersion, gpu_info()); | |
| 174 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 175 features = control_list->MakeDecision( | |
| 176 GpuControlList::kOsLinux, kOsVersion, gpu_info()); | |
| 177 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 178 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) || \ | |
| 179 defined(OS_OPENBSD) | |
| 180 // ControlList entries will be filtered to the current OS only upon loading. | |
| 181 EXPECT_TRUE(control_list->LoadList( | |
| 182 vendor_json, GpuControlList::kCurrentOsOnly)); | |
| 183 features = control_list->MakeDecision( | |
| 184 GpuControlList::kOsMacosx, kOsVersion, gpu_info()); | |
| 185 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 186 features = control_list->MakeDecision( | |
| 187 GpuControlList::kOsWin, kOsVersion, gpu_info()); | |
| 188 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 189 features = control_list->MakeDecision( | |
| 190 GpuControlList::kOsLinux, kOsVersion, gpu_info()); | |
| 191 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 192 #endif | |
| 193 } | |
| 194 | |
| 195 TEST_F(GpuControlListTest, UnknownField) { | |
| 196 const std::string unknown_field_json = LONG_STRING_CONST( | |
| 197 { | |
| 198 "name": "gpu control list", | |
| 199 "version": "0.1", | |
| 200 "entries": [ | |
| 201 { | |
| 202 "id": 1, | |
| 203 "unknown_field": 0, | |
| 204 "features": [ | |
| 205 "test_feature_1" | |
| 206 ] | |
| 207 }, | |
| 208 { | |
| 209 "id": 2, | |
| 210 "features": [ | |
| 211 "test_feature_0" | |
| 212 ] | |
| 213 } | |
| 214 ] | |
| 215 } | |
| 216 ); | |
| 217 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 218 | |
| 219 EXPECT_FALSE(control_list->LoadList( | |
| 220 unknown_field_json, GpuControlList::kAllOs)); | |
| 221 } | |
| 222 | |
| 223 TEST_F(GpuControlListTest, UnknownExceptionField) { | |
| 224 const std::string unknown_exception_field_json = LONG_STRING_CONST( | |
| 225 { | |
| 226 "name": "gpu control list", | |
| 227 "version": "0.1", | |
| 228 "entries": [ | |
| 229 { | |
| 230 "id": 1, | |
| 231 "unknown_field": 0, | |
| 232 "features": [ | |
| 233 "test_feature_2" | |
| 234 ] | |
| 235 }, | |
| 236 { | |
| 237 "id": 2, | |
| 238 "exceptions": [ | |
| 239 { | |
| 240 "unknown_field": 0 | |
| 241 } | |
| 242 ], | |
| 243 "features": [ | |
| 244 "test_feature_1" | |
| 245 ] | |
| 246 }, | |
| 247 { | |
| 248 "id": 3, | |
| 249 "features": [ | |
| 250 "test_feature_0" | |
| 251 ] | |
| 252 } | |
| 253 ] | |
| 254 } | |
| 255 ); | |
| 256 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 257 | |
| 258 EXPECT_FALSE(control_list->LoadList( | |
| 259 unknown_exception_field_json, GpuControlList::kAllOs)); | |
| 260 } | |
| 261 | |
| 262 TEST_F(GpuControlListTest, DisabledEntry) { | |
| 263 const std::string disabled_json = LONG_STRING_CONST( | |
| 264 { | |
| 265 "name": "gpu control list", | |
| 266 "version": "0.1", | |
| 267 "entries": [ | |
| 268 { | |
| 269 "id": 1, | |
| 270 "disabled": true, | |
| 271 "features": [ | |
| 272 "test_feature_0" | |
| 273 ] | |
| 274 } | |
| 275 ] | |
| 276 } | |
| 277 ); | |
| 278 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 279 EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs)); | |
| 280 std::set<int> features = control_list->MakeDecision( | |
| 281 GpuControlList::kOsWin, kOsVersion, gpu_info()); | |
| 282 EXPECT_EMPTY_SET(features); | |
| 283 std::vector<uint32_t> flag_entries; | |
| 284 control_list->GetDecisionEntries(&flag_entries, false); | |
| 285 EXPECT_EQ(0u, flag_entries.size()); | |
| 286 control_list->GetDecisionEntries(&flag_entries, true); | |
| 287 EXPECT_EQ(1u, flag_entries.size()); | |
| 288 } | |
| 289 | |
| 290 TEST_F(GpuControlListTest, NeedsMoreInfo) { | |
| 291 const std::string json = LONG_STRING_CONST( | |
| 292 { | |
| 293 "name": "gpu control list", | |
| 294 "version": "0.1", | |
| 295 "entries": [ | |
| 296 { | |
| 297 "id": 1, | |
| 298 "os": { | |
| 299 "type": "win" | |
| 300 }, | |
| 301 "vendor_id": "0x10de", | |
| 302 "driver_version": { | |
| 303 "op": "<", | |
| 304 "value": "12" | |
| 305 }, | |
| 306 "features": [ | |
| 307 "test_feature_0" | |
| 308 ] | |
| 309 } | |
| 310 ] | |
| 311 } | |
| 312 ); | |
| 313 GPUInfo gpu_info; | 71 GPUInfo gpu_info; |
| 314 gpu_info.gpu.vendor_id = kNvidiaVendorId; | 72 gpu_info.gpu.vendor_id = kNvidiaVendorId; |
| 315 | 73 |
| 316 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 317 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 318 | |
| 319 std::set<int> features = control_list->MakeDecision( | 74 std::set<int> features = control_list->MakeDecision( |
| 320 GpuControlList::kOsWin, kOsVersion, gpu_info); | 75 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 321 EXPECT_EMPTY_SET(features); | 76 EXPECT_EMPTY_SET(features); |
| 322 EXPECT_TRUE(control_list->needs_more_info()); | 77 EXPECT_TRUE(control_list->needs_more_info()); |
| 323 std::vector<uint32_t> decision_entries; | 78 std::vector<uint32_t> decision_entries; |
| 324 control_list->GetDecisionEntries(&decision_entries, false); | 79 control_list->GetDecisionEntries(&decision_entries); |
| 325 EXPECT_EQ(0u, decision_entries.size()); | 80 EXPECT_EQ(0u, decision_entries.size()); |
| 326 | 81 |
| 327 gpu_info.driver_version = "11"; | 82 gpu_info.driver_version = "11"; |
| 328 features = control_list->MakeDecision( | 83 features = control_list->MakeDecision( |
| 329 GpuControlList::kOsWin, kOsVersion, gpu_info); | 84 GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 330 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 85 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
| 331 EXPECT_FALSE(control_list->needs_more_info()); | 86 EXPECT_FALSE(control_list->needs_more_info()); |
| 332 control_list->GetDecisionEntries(&decision_entries, false); | 87 control_list->GetDecisionEntries(&decision_entries); |
| 333 EXPECT_EQ(1u, decision_entries.size()); | 88 EXPECT_EQ(1u, decision_entries.size()); |
| 334 } | 89 } |
| 335 | 90 |
| 336 TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) { | 91 TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) { |
| 337 const std::string json = LONG_STRING_CONST( | 92 const Entry kEntries[1] = { |
| 338 { | 93 kGpuControlListTestingEntries |
| 339 "name": "gpu control list", | 94 [kGpuControlListTest_NeedsMoreInfoForExceptions]}; |
| 340 "version": "0.1", | 95 std::unique_ptr<GpuControlList> control_list(Create(1, kEntries)); |
| 341 "entries": [ | 96 |
| 342 { | |
| 343 "id": 1, | |
| 344 "os": { | |
| 345 "type": "linux" | |
| 346 }, | |
| 347 "vendor_id": "0x8086", | |
| 348 "exceptions": [ | |
| 349 { | |
| 350 "gl_renderer": ".*mesa.*" | |
| 351 } | |
| 352 ], | |
| 353 "features": [ | |
| 354 "test_feature_0" | |
| 355 ] | |
| 356 } | |
| 357 ] | |
| 358 } | |
| 359 ); | |
| 360 GPUInfo gpu_info; | 97 GPUInfo gpu_info; |
| 361 gpu_info.gpu.vendor_id = kIntelVendorId; | 98 gpu_info.gpu.vendor_id = kIntelVendorId; |
| 362 | 99 |
| 363 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 364 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 365 | |
| 366 // The case this entry does not apply. | 100 // The case this entry does not apply. |
| 367 std::set<int> features = control_list->MakeDecision( | 101 std::set<int> features = control_list->MakeDecision( |
| 368 GpuControlList::kOsMacosx, kOsVersion, gpu_info); | 102 GpuControlList::kOsMacosx, kOsVersion, gpu_info); |
| 369 EXPECT_EMPTY_SET(features); | 103 EXPECT_EMPTY_SET(features); |
| 370 EXPECT_FALSE(control_list->needs_more_info()); | 104 EXPECT_FALSE(control_list->needs_more_info()); |
| 371 | 105 |
| 372 // The case this entry might apply, but need more info. | 106 // The case this entry might apply, but need more info. |
| 373 features = control_list->MakeDecision( | 107 features = control_list->MakeDecision( |
| 374 GpuControlList::kOsLinux, kOsVersion, gpu_info); | 108 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 375 // Ignore exceptions if main entry info matches | 109 // Ignore exceptions if main entry info matches |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 388 gpu_info.gl_renderer = "my renderer"; | 122 gpu_info.gl_renderer = "my renderer"; |
| 389 features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion, | 123 features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion, |
| 390 gpu_info); | 124 gpu_info); |
| 391 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 125 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
| 392 EXPECT_FALSE(control_list->needs_more_info()); | 126 EXPECT_FALSE(control_list->needs_more_info()); |
| 393 } | 127 } |
| 394 | 128 |
| 395 TEST_F(GpuControlListTest, IgnorableEntries) { | 129 TEST_F(GpuControlListTest, IgnorableEntries) { |
| 396 // If an entry will not change the control_list decisions, then it should not | 130 // If an entry will not change the control_list decisions, then it should not |
| 397 // trigger the needs_more_info flag. | 131 // trigger the needs_more_info flag. |
| 398 const std::string json = LONG_STRING_CONST( | 132 const Entry kEntries[2] = { |
| 399 { | 133 kGpuControlListTestingEntries[kGpuControlListTest_IgnorableEntries_0], |
| 400 "name": "gpu control list", | 134 kGpuControlListTestingEntries[kGpuControlListTest_IgnorableEntries_1]}; |
| 401 "version": "0.1", | 135 std::unique_ptr<GpuControlList> control_list(Create(2, kEntries)); |
| 402 "entries": [ | 136 |
| 403 { | |
| 404 "id": 1, | |
| 405 "os": { | |
| 406 "type": "linux" | |
| 407 }, | |
| 408 "vendor_id": "0x8086", | |
| 409 "features": [ | |
| 410 "test_feature_0" | |
| 411 ] | |
| 412 }, | |
| 413 { | |
| 414 "id": 2, | |
| 415 "os": { | |
| 416 "type": "linux" | |
| 417 }, | |
| 418 "vendor_id": "0x8086", | |
| 419 "driver_version": { | |
| 420 "op": "<", | |
| 421 "value": "10.7" | |
| 422 }, | |
| 423 "features": [ | |
| 424 "test_feature_0" | |
| 425 ] | |
| 426 } | |
| 427 ] | |
| 428 } | |
| 429 ); | |
| 430 GPUInfo gpu_info; | 137 GPUInfo gpu_info; |
| 431 gpu_info.gpu.vendor_id = kIntelVendorId; | 138 gpu_info.gpu.vendor_id = kIntelVendorId; |
| 432 | 139 |
| 433 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 434 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 435 std::set<int> features = control_list->MakeDecision( | 140 std::set<int> features = control_list->MakeDecision( |
| 436 GpuControlList::kOsLinux, kOsVersion, gpu_info); | 141 GpuControlList::kOsLinux, kOsVersion, gpu_info); |
| 437 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | 142 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); |
| 438 EXPECT_FALSE(control_list->needs_more_info()); | 143 EXPECT_FALSE(control_list->needs_more_info()); |
| 439 } | 144 } |
| 440 | 145 |
| 441 TEST_F(GpuControlListTest, ExceptionWithoutVendorId) { | |
| 442 const std::string json = LONG_STRING_CONST( | |
| 443 { | |
| 444 "name": "gpu control list", | |
| 445 "version": "0.1", | |
| 446 "entries": [ | |
| 447 { | |
| 448 "id": 1, | |
| 449 "os": { | |
| 450 "type": "linux" | |
| 451 }, | |
| 452 "vendor_id": "0x8086", | |
| 453 "exceptions": [ | |
| 454 { | |
| 455 "device_id": ["0x2a06"], | |
| 456 "driver_version": { | |
| 457 "op": ">=", | |
| 458 "value": "8.1" | |
| 459 } | |
| 460 }, | |
| 461 { | |
| 462 "device_id": ["0x2a02"], | |
| 463 "driver_version": { | |
| 464 "op": ">=", | |
| 465 "value": "9.1" | |
| 466 } | |
| 467 } | |
| 468 ], | |
| 469 "features": [ | |
| 470 "test_feature_0" | |
| 471 ] | |
| 472 } | |
| 473 ] | |
| 474 } | |
| 475 ); | |
| 476 GPUInfo gpu_info; | |
| 477 gpu_info.gpu.vendor_id = kIntelVendorId; | |
| 478 gpu_info.gpu.device_id = 0x2a02; | |
| 479 gpu_info.driver_version = "9.1"; | |
| 480 | |
| 481 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 482 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 483 | |
| 484 std::set<int> features = control_list->MakeDecision( | |
| 485 GpuControlList::kOsLinux, kOsVersion, gpu_info); | |
| 486 EXPECT_EMPTY_SET(features); | |
| 487 | |
| 488 gpu_info.driver_version = "9.0"; | |
| 489 features = control_list->MakeDecision( | |
| 490 GpuControlList::kOsLinux, kOsVersion, gpu_info); | |
| 491 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 492 } | |
| 493 | |
| 494 TEST_F(GpuControlListTest, AMDSwitchable) { | |
| 495 GPUInfo gpu_info; | |
| 496 gpu_info.amd_switchable = true; | |
| 497 gpu_info.gpu.vendor_id = kAmdVendorId; | |
| 498 gpu_info.gpu.device_id = 0x6760; | |
| 499 GPUInfo::GPUDevice integrated_gpu; | |
| 500 integrated_gpu.vendor_id = kIntelVendorId; | |
| 501 integrated_gpu.device_id = 0x0116; | |
| 502 gpu_info.secondary_gpus.push_back(integrated_gpu); | |
| 503 | |
| 504 { // amd_switchable_discrete entry | |
| 505 const std::string json= LONG_STRING_CONST( | |
| 506 { | |
| 507 "name": "gpu control list", | |
| 508 "version": "0.1", | |
| 509 "entries": [ | |
| 510 { | |
| 511 "id": 1, | |
| 512 "os": { | |
| 513 "type": "win" | |
| 514 }, | |
| 515 "multi_gpu_style": "amd_switchable_discrete", | |
| 516 "features": [ | |
| 517 "test_feature_0" | |
| 518 ] | |
| 519 } | |
| 520 ] | |
| 521 } | |
| 522 ); | |
| 523 | |
| 524 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 525 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 526 | |
| 527 // Integrated GPU is active | |
| 528 gpu_info.gpu.active = false; | |
| 529 gpu_info.secondary_gpus[0].active = true; | |
| 530 std::set<int> features = control_list->MakeDecision( | |
| 531 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 532 EXPECT_EMPTY_SET(features); | |
| 533 | |
| 534 // Discrete GPU is active | |
| 535 gpu_info.gpu.active = true; | |
| 536 gpu_info.secondary_gpus[0].active = false; | |
| 537 features = control_list->MakeDecision( | |
| 538 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 539 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 540 } | |
| 541 | |
| 542 { // amd_switchable_integrated entry | |
| 543 const std::string json= LONG_STRING_CONST( | |
| 544 { | |
| 545 "name": "gpu control list", | |
| 546 "version": "0.1", | |
| 547 "entries": [ | |
| 548 { | |
| 549 "id": 1, | |
| 550 "os": { | |
| 551 "type": "win" | |
| 552 }, | |
| 553 "multi_gpu_style": "amd_switchable_integrated", | |
| 554 "features": [ | |
| 555 "test_feature_0" | |
| 556 ] | |
| 557 } | |
| 558 ] | |
| 559 } | |
| 560 ); | |
| 561 | |
| 562 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 563 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 564 | |
| 565 // Discrete GPU is active | |
| 566 gpu_info.gpu.active = true; | |
| 567 gpu_info.secondary_gpus[0].active = false; | |
| 568 std::set<int> features = control_list->MakeDecision( | |
| 569 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 570 EXPECT_EMPTY_SET(features); | |
| 571 | |
| 572 // Integrated GPU is active | |
| 573 gpu_info.gpu.active = false; | |
| 574 gpu_info.secondary_gpus[0].active = true; | |
| 575 features = control_list->MakeDecision( | |
| 576 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 577 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 578 | |
| 579 // For non AMD switchable | |
| 580 gpu_info.amd_switchable = false; | |
| 581 features = control_list->MakeDecision( | |
| 582 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 583 EXPECT_EMPTY_SET(features); | |
| 584 } | |
| 585 } | |
| 586 | |
| 587 TEST_F(GpuControlListTest, DisabledExtensionTest) { | 146 TEST_F(GpuControlListTest, DisabledExtensionTest) { |
| 588 // exact setting. | 147 // exact setting. |
| 589 const std::string exact_list_json = LONG_STRING_CONST( | 148 const Entry kEntries[2] = {kGpuControlListTestingEntries |
| 590 { | 149 [kGpuControlListTest_DisabledExtensionTest_0], |
| 591 "name": "gpu control list", | 150 kGpuControlListTestingEntries |
| 592 "version": "0.1", | 151 [kGpuControlListTest_DisabledExtensionTest_1]}; |
| 593 "entries": [ | 152 std::unique_ptr<GpuControlList> control_list(Create(2, kEntries)); |
| 594 { | |
| 595 "id": 1, | |
| 596 "os": { | |
| 597 "type": "win" | |
| 598 }, | |
| 599 "disabled_extensions": [ | |
| 600 "test_extension2", | |
| 601 "test_extension1" | |
| 602 ] | |
| 603 }, | |
| 604 { | |
| 605 "id": 2, | |
| 606 "os": { | |
| 607 "type": "win" | |
| 608 }, | |
| 609 "disabled_extensions": [ | |
| 610 "test_extension3", | |
| 611 "test_extension2" | |
| 612 ] | |
| 613 } | |
| 614 ] | |
| 615 } | |
| 616 ); | |
| 617 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 618 | 153 |
| 619 EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs)); | |
| 620 GPUInfo gpu_info; | 154 GPUInfo gpu_info; |
| 621 control_list->MakeDecision(GpuControlList::kOsWin, kOsVersion, gpu_info); | 155 control_list->MakeDecision(GpuControlList::kOsWin, kOsVersion, gpu_info); |
| 622 | 156 |
| 623 std::vector<std::string> disabled_extensions = | 157 std::vector<std::string> disabled_extensions = |
| 624 control_list->GetDisabledExtensions(); | 158 control_list->GetDisabledExtensions(); |
| 625 | 159 |
| 626 ASSERT_EQ(3u, disabled_extensions.size()); | 160 ASSERT_EQ(3u, disabled_extensions.size()); |
| 627 ASSERT_STREQ("test_extension1", disabled_extensions[0].c_str()); | 161 ASSERT_STREQ("test_extension1", disabled_extensions[0].c_str()); |
| 628 ASSERT_STREQ("test_extension2", disabled_extensions[1].c_str()); | 162 ASSERT_STREQ("test_extension2", disabled_extensions[1].c_str()); |
| 629 ASSERT_STREQ("test_extension3", disabled_extensions[2].c_str()); | 163 ASSERT_STREQ("test_extension3", disabled_extensions[2].c_str()); |
| 630 } | 164 } |
| 631 | 165 |
| 632 TEST_F(GpuControlListTest, DisabledInProcessGPUTest) { | |
| 633 const std::string exact_list_json = LONG_STRING_CONST( | |
| 634 { | |
| 635 "name": "gpu control list", | |
| 636 "version": "0.1", | |
| 637 "entries": [ | |
| 638 { | |
| 639 "id": 1, | |
| 640 "os": { | |
| 641 "type": "win" | |
| 642 }, | |
| 643 "in_process_gpu": true, | |
| 644 "features": [ | |
| 645 "test_feature_0" | |
| 646 ] | |
| 647 } | |
| 648 ] | |
| 649 } | |
| 650 ); | |
| 651 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 652 | |
| 653 EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs)); | |
| 654 GPUInfo gpu_info; | |
| 655 | |
| 656 gpu_info.in_process_gpu = true; | |
| 657 std::set<int> features = control_list->MakeDecision( | |
| 658 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 659 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 660 | |
| 661 gpu_info.in_process_gpu = false; | |
| 662 features = control_list->MakeDecision( | |
| 663 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 664 EXPECT_EMPTY_SET(features); | |
| 665 } | |
| 666 | |
| 667 TEST_F(GpuControlListTest, SameGPUTwiceTest) { | |
| 668 const std::string json = LONG_STRING_CONST( | |
| 669 { | |
| 670 "name": "gpu control list", | |
| 671 "version": "0.1", | |
| 672 "entries": [ | |
| 673 { | |
| 674 "id": 1, | |
| 675 "os": { | |
| 676 "type": "win" | |
| 677 }, | |
| 678 "vendor_id": "0x8086", | |
| 679 "features": [ | |
| 680 "test_feature_0" | |
| 681 ] | |
| 682 } | |
| 683 ] | |
| 684 } | |
| 685 ); | |
| 686 GPUInfo gpu_info; | |
| 687 gpu_info.gpu.vendor_id = kIntelVendorId; | |
| 688 // Real case on Intel GMA* on Windows | |
| 689 gpu_info.secondary_gpus.push_back(gpu_info.gpu); | |
| 690 | |
| 691 std::unique_ptr<GpuControlList> control_list(Create()); | |
| 692 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs)); | |
| 693 std::set<int> features = control_list->MakeDecision( | |
| 694 GpuControlList::kOsWin, kOsVersion, gpu_info); | |
| 695 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0); | |
| 696 EXPECT_FALSE(control_list->needs_more_info()); | |
| 697 } | |
| 698 | |
| 699 } // namespace gpu | 166 } // namespace gpu |
| OLD | NEW |