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