| Index: content/browser/gpu/gpu_control_list_unittest.cc
|
| ===================================================================
|
| --- content/browser/gpu/gpu_control_list_unittest.cc (revision 0)
|
| +++ content/browser/gpu/gpu_control_list_unittest.cc (revision 0)
|
| @@ -0,0 +1,1315 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <vector>
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "content/browser/gpu/gpu_control_list.h"
|
| +#include "content/public/common/gpu_info.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +const char kOsVersion[] = "10.6.4";
|
| +const uint32 kIntelVendorId = 0x8086;
|
| +const uint32 kIntelDeviceId = 0x0166; // 3rd Gen Core Graphics
|
| +const uint32 kNvidiaVendorId = 0x10de;
|
| +const uint32 kNvidiaDeviceId = 0x0fd5; // GeForce GT 650M
|
| +
|
| +namespace content {
|
| +
|
| +enum TestFeatureType {
|
| + TEST_FEATURE_0 = 1,
|
| + TEST_FEATURE_1 = 1 << 2,
|
| + TEST_FEATURE_2 = 1 << 3,
|
| +};
|
| +
|
| +class GpuControlListTest : public testing::Test {
|
| + public:
|
| + GpuControlListTest() { }
|
| +
|
| + virtual ~GpuControlListTest() { }
|
| +
|
| + const GPUInfo& gpu_info() const {
|
| + return gpu_info_;
|
| + }
|
| +
|
| + GpuControlList* Create() {
|
| + GpuControlList* rt = new GpuControlList();
|
| + rt->AddFeature("test_feature_0", TEST_FEATURE_0);
|
| + rt->AddFeature("test_feature_1", TEST_FEATURE_1);
|
| + rt->AddFeature("test_feature_2", TEST_FEATURE_2);
|
| + return rt;
|
| + }
|
| +
|
| + protected:
|
| + virtual void SetUp() {
|
| + gpu_info_.gpu.vendor_id = kNvidiaVendorId;
|
| + gpu_info_.gpu.device_id = 0x0640;
|
| + gpu_info_.driver_vendor = "NVIDIA";
|
| + gpu_info_.driver_version = "1.6.18";
|
| + gpu_info_.driver_date = "7-14-2009";
|
| + gpu_info_.machine_model = "MacBookPro 7.1";
|
| + gpu_info_.gl_vendor = "NVIDIA Corporation";
|
| + gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
|
| + gpu_info_.performance_stats.graphics = 5.0;
|
| + gpu_info_.performance_stats.gaming = 5.0;
|
| + gpu_info_.performance_stats.overall = 5.0;
|
| + }
|
| +
|
| + virtual void TearDown() {
|
| + }
|
| +
|
| + private:
|
| + GPUInfo gpu_info_;
|
| +};
|
| +
|
| +TEST_F(GpuControlListTest, DefaultControlListSettings) {
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + // Default control list settings: all feature are allowed.
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, EmptyControlList) {
|
| + // Empty list: all features are allowed.
|
| + const std::string empty_list_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"2.5\",\n"
|
| + " \"entries\": [\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(empty_list_json,
|
| + GpuControlList::kAllOs));
|
| + EXPECT_EQ("2.5", control_list->GetVersion());
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, DetailedEntryAndInvalidJson) {
|
| + // exact setting.
|
| + const std::string exact_list_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 5,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"macosx\",\n"
|
| + " \"version\": {\n"
|
| + " \"op\": \"=\",\n"
|
| + " \"number\": \"10.6.4\"\n"
|
| + " }\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x10de\",\n"
|
| + " \"device_id\": [\"0x0640\"],\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"=\",\n"
|
| + " \"number\": \"1.6.18\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + // Invalid json input should not change the current control_list settings.
|
| + const std::string invalid_json = "invalid";
|
| +
|
| + EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs));
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + std::vector<uint32> entries;
|
| + control_list->GetDecisionEntries(&entries, false);
|
| + ASSERT_EQ(1u, entries.size());
|
| + EXPECT_EQ(5u, entries[0]);
|
| + EXPECT_EQ(5u, control_list->max_entry_id());
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, VendorOnAllOsEntry) {
|
| + // ControlList a vendor on all OS.
|
| + const std::string vendor_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"vendor_id\": \"0x10de\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + // ControlList entries won't be filtered to the current OS only upon loading.
|
| + EXPECT_TRUE(control_list->LoadList(vendor_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) || \
|
| + defined(OS_OPENBSD)
|
| + // ControlList entries will be filtered to the current OS only upon loading.
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + vendor_json, GpuControlList::kCurrentOsOnly));
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +#endif
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, VendorOnLinuxEntry) {
|
| + // ControlList a vendor on Linux only.
|
| + const std::string vendor_linux_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x10de\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + vendor_linux_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, AllExceptNVidiaOnLinuxEntry) {
|
| + // ControlList all cards in Linux except NVIDIA.
|
| + const std::string linux_except_nvidia_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"exceptions\": [\n"
|
| + " {\n"
|
| + " \"vendor_id\": \"0x10de\"\n"
|
| + " }\n"
|
| + " ],\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + linux_except_nvidia_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, AllExceptIntelOnLinuxEntry) {
|
| + // ControlList all cards in Linux except Intel.
|
| + const std::string linux_except_intel_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"exceptions\": [\n"
|
| + " {\n"
|
| + " \"vendor_id\": \"0x8086\"\n"
|
| + " }\n"
|
| + " ],\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + linux_except_intel_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, DateOnWindowsEntry) {
|
| + // ControlList all drivers earlier than 2010-5-8 in Windows.
|
| + const std::string date_windows_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"win\"\n"
|
| + " },\n"
|
| + " \"driver_date\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"number\": \"2010.5.8\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.driver_date = "7-14-2009";
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + date_windows_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_date = "07-14-2009";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_date = "1-1-2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_date = "05-07-2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_date = "5-8-2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_date = "5-9-2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_date = "6-2-2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, MultipleDevicesEntry) {
|
| + const std::string devices_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"vendor_id\": \"0x10de\",\n"
|
| + " \"device_id\": [\"0x1023\", \"0x0640\"],\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(devices_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, ChromeOSEntry) {
|
| + const std::string devices_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"chromeos\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(devices_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsChromeOS, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, ChromeVersionEntry) {
|
| + const std::string browser_version_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"browser_version\": {\n"
|
| + " \"op\": \">=\",\n"
|
| + " \"number\": \"10\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list9(Create());
|
| + EXPECT_TRUE(control_list9->LoadList(
|
| + "9.0", browser_version_json, GpuControlList::kAllOs));
|
| + int features = control_list9->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +
|
| + scoped_ptr<GpuControlList> control_list10(Create());
|
| + EXPECT_TRUE(control_list10->LoadList(
|
| + "10.0", browser_version_json, GpuControlList::kAllOs));
|
| + features = control_list10->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, MalformedVendor) {
|
| + // vendor_id is defined as list instead of string.
|
| + const std::string malformed_vendor_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"vendor_id\": \"[0x10de]\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_FALSE(control_list->LoadList(
|
| + malformed_vendor_json, GpuControlList::kAllOs));
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, UnknownField) {
|
| + const std::string unknown_field_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"unknown_field\": 0,\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_1\"\n"
|
| + " ]\n"
|
| + " },\n"
|
| + " {\n"
|
| + " \"id\": 2,\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + unknown_field_json, GpuControlList::kAllOs));
|
| + EXPECT_EQ(1u, control_list->num_entries());
|
| + EXPECT_TRUE(control_list->contains_unknown_fields());
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, UnknownExceptionField) {
|
| + const std::string unknown_exception_field_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"unknown_field\": 0,\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_2\"\n"
|
| + " ]\n"
|
| + " },\n"
|
| + " {\n"
|
| + " \"id\": 2,\n"
|
| + " \"exceptions\": [\n"
|
| + " {\n"
|
| + " \"unknown_field\": 0\n"
|
| + " }\n"
|
| + " ],\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_1\"\n"
|
| + " ]\n"
|
| + " },\n"
|
| + " {\n"
|
| + " \"id\": 3,\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + unknown_exception_field_json, GpuControlList::kAllOs));
|
| + EXPECT_EQ(1u, control_list->num_entries());
|
| + EXPECT_TRUE(control_list->contains_unknown_fields());
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, UnknownFeature) {
|
| + const std::string unknown_feature_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"features\": [\n"
|
| + " \"some_unknown_feature\",\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| +
|
| + EXPECT_TRUE(control_list->LoadList(
|
| + unknown_feature_json, GpuControlList::kAllOs));
|
| + EXPECT_EQ(1u, control_list->num_entries());
|
| + EXPECT_TRUE(control_list->contains_unknown_fields());
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, GlVendor) {
|
| + const std::string gl_vendor_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"gl_vendor\": {\n"
|
| + " \"op\": \"beginwith\",\n"
|
| + " \"value\": \"NVIDIA\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(gl_vendor_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, GlRenderer) {
|
| + const std::string gl_renderer_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"gl_renderer\": {\n"
|
| + " \"op\": \"contains\",\n"
|
| + " \"value\": \"GeForce\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(gl_renderer_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, PerfGraphics) {
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"perf_graphics\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"value\": \"6.0\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, PerfGaming) {
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"perf_gaming\": {\n"
|
| + " \"op\": \"<=\",\n"
|
| + " \"value\": \"4.0\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, PerfOverall) {
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"perf_overall\": {\n"
|
| + " \"op\": \"between\",\n"
|
| + " \"value\": \"1.0\",\n"
|
| + " \"value2\": \"9.0\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, DisabledEntry) {
|
| + const std::string disabled_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"disabled\": true,\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsWin, kOsVersion, gpu_info());
|
| + EXPECT_EQ(features, 0);
|
| + std::vector<uint32> flag_entries;
|
| + control_list->GetDecisionEntries(&flag_entries, false);
|
| + EXPECT_EQ(0u, flag_entries.size());
|
| + control_list->GetDecisionEntries(&flag_entries, true);
|
| + EXPECT_EQ(1u, flag_entries.size());
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, Optimus) {
|
| + const std::string optimus_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"multi_gpu_style\": \"optimus\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.optimus = true;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(optimus_json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, AMDSwitchable) {
|
| + const std::string amd_switchable_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"macosx\"\n"
|
| + " },\n"
|
| + " \"multi_gpu_style\": \"amd_switchable\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.amd_switchable = true;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(amd_switchable_json,
|
| + GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, LexicalDriverVersion) {
|
| + const std::string lexical_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x1002\",\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"style\": \"lexical\",\n"
|
| + " \"number\": \"8.201\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = 0x1002;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs));
|
| +
|
| + gpu_info.driver_version = "8.001.100";
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.109";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.10900";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.109.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.2";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.20";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.200";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.20.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "8.2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "8.21";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "8.21.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "9.002";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "9.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "12";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "12.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, LexicalDriverVersion2) {
|
| + const std::string lexical_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x1002\",\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"style\": \"lexical\",\n"
|
| + " \"number\": \"9.002\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = 0x1002;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs));
|
| +
|
| + gpu_info.driver_version = "8.001.100";
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.109";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.10900";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.109.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.2";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.20";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.200";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.20.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.2010";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.21";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.21.100";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "9.002";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "9.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "12";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + gpu_info.driver_version = "12.201";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, LexicalDriverVersion3) {
|
| + const std::string lexical_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x1002\",\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"=\",\n"
|
| + " \"style\": \"lexical\",\n"
|
| + " \"number\": \"8.76\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = 0x1002;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(lexical_json, GpuControlList::kAllOs));
|
| +
|
| + gpu_info.driver_version = "8.76";
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.768";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +
|
| + gpu_info.driver_version = "8.76.8";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, MultipleGPUsAny) {
|
| + const std::string multi_gpu_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"macosx\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"device_id\": [\"0x0166\"],\n"
|
| + " \"multi_gpu_category\": \"any\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = kNvidiaVendorId;
|
| + gpu_info.gpu.device_id = kNvidiaDeviceId;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(multi_gpu_json,
|
| + GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + GPUInfo::GPUDevice gpu_device;
|
| + gpu_device.vendor_id = kIntelVendorId;
|
| + gpu_device.device_id = kIntelDeviceId;
|
| + gpu_info.secondary_gpus.push_back(gpu_device);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, MultipleGPUsSecondary) {
|
| + const std::string multi_gpu_json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"macosx\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"device_id\": [\"0x0166\"],\n"
|
| + " \"multi_gpu_category\": \"secondary\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = kNvidiaVendorId;
|
| + gpu_info.gpu.device_id = kNvidiaDeviceId;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(multi_gpu_json,
|
| + GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| +
|
| + GPUInfo::GPUDevice gpu_device;
|
| + gpu_device.vendor_id = kIntelVendorId;
|
| + gpu_device.device_id = kIntelDeviceId;
|
| + gpu_info.secondary_gpus.push_back(gpu_device);
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, NeedsMoreInfo) {
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"number\": \"10.7\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = kIntelVendorId;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| +
|
| + // The case this entry does not apply.
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +
|
| + // The case this entry might apply, but need more info.
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_TRUE(control_list->needs_more_info());
|
| +
|
| + // The case we have full info, and this entry applies.
|
| + gpu_info.driver_version = "10.6";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +
|
| + // The case we have full info, and this entry does not apply.
|
| + gpu_info.driver_version = "10.8";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) {
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"exceptions\": [\n"
|
| + " {\n"
|
| + " \"gl_renderer\": {\n"
|
| + " \"op\": \"contains\",\n"
|
| + " \"value\": \"mesa\"\n"
|
| + " }\n"
|
| + " }\n"
|
| + " ],\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = kIntelVendorId;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| +
|
| + // The case this entry does not apply.
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsMacosx, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +
|
| + // The case this entry might apply, but need more info.
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_TRUE(control_list->needs_more_info());
|
| +
|
| + // The case we have full info, and the exception applies (so the entry
|
| + // does not apply).
|
| + gpu_info.gl_renderer = "mesa";
|
| + features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +
|
| + // The case we have full info, and this entry applies.
|
| + gpu_info.gl_renderer = "my renderer";
|
| + features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion,
|
| + gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +}
|
| +
|
| +TEST_F(GpuControlListTest, IgnorableEntries) {
|
| + // If an entry will not change the control_list decisions, then it should not
|
| + // trigger the needs_more_info flag.
|
| + const std::string json =
|
| + "{\n"
|
| + " \"name\": \"gpu control list\",\n"
|
| + " \"version\": \"0.1\",\n"
|
| + " \"entries\": [\n"
|
| + " {\n"
|
| + " \"id\": 1,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " },\n"
|
| + " {\n"
|
| + " \"id\": 2,\n"
|
| + " \"os\": {\n"
|
| + " \"type\": \"linux\"\n"
|
| + " },\n"
|
| + " \"vendor_id\": \"0x8086\",\n"
|
| + " \"driver_version\": {\n"
|
| + " \"op\": \"<\",\n"
|
| + " \"number\": \"10.7\"\n"
|
| + " },\n"
|
| + " \"features\": [\n"
|
| + " \"test_feature_0\"\n"
|
| + " ]\n"
|
| + " }\n"
|
| + " ]\n"
|
| + "}";
|
| +
|
| + GPUInfo gpu_info;
|
| + gpu_info.gpu.vendor_id = kIntelVendorId;
|
| +
|
| + scoped_ptr<GpuControlList> control_list(Create());
|
| + EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
|
| + int features = control_list->MakeDecision(
|
| + GpuControlList::kOsLinux, kOsVersion, gpu_info);
|
| + EXPECT_EQ(TEST_FEATURE_0, features);
|
| + EXPECT_FALSE(control_list->needs_more_info());
|
| +}
|
| +
|
| +} // namespace content
|
| +
|
|
|
| Property changes on: content/browser/gpu/gpu_control_list_unittest.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|