Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / gpu / config / gpu_control_list_unittest.cc
index 33c6973..f968183 100644 (file)
@@ -12,6 +12,7 @@
 const char kOsVersion[] = "10.6.4";
 const uint32 kIntelVendorId = 0x8086;
 const uint32 kNvidiaVendorId = 0x10de;
+const uint32 kAmdVendorId = 0x10de;
 
 #define LONG_STRING_CONST(...) #__VA_ARGS__
 
@@ -31,7 +32,7 @@ class GpuControlListTest : public testing::Test {
  public:
   GpuControlListTest() { }
 
-  virtual ~GpuControlListTest() { }
+  ~GpuControlListTest() override {}
 
   const GPUInfo& gpu_info() const {
     return gpu_info_;
@@ -46,7 +47,7 @@ class GpuControlListTest : public testing::Test {
   }
 
  protected:
-  virtual void SetUp() {
+  void SetUp() override {
     gpu_info_.gpu.vendor_id = kNvidiaVendorId;
     gpu_info_.gpu.device_id = 0x0640;
     gpu_info_.driver_vendor = "NVIDIA";
@@ -61,8 +62,7 @@ class GpuControlListTest : public testing::Test {
     gpu_info_.performance_stats.overall = 5.0;
   }
 
-  virtual void TearDown() {
-  }
+  void TearDown() override {}
 
  private:
   GPUInfo gpu_info_;
@@ -288,6 +288,52 @@ TEST_F(GpuControlListTest, DisabledEntry) {
   EXPECT_EQ(1u, flag_entries.size());
 }
 
+TEST_F(GpuControlListTest, NeedsMoreInfo) {
+  const std::string json = LONG_STRING_CONST(
+      {
+        "name": "gpu control list",
+        "version": "0.1",
+        "entries": [
+          {
+            "id": 1,
+            "os": {
+              "type": "win"
+            },
+            "vendor_id": "0x10de",
+            "driver_version": {
+              "op": "<",
+              "value": "12"
+            },
+            "features": [
+              "test_feature_0"
+            ]
+          }
+        ]
+      }
+  );
+  GPUInfo gpu_info;
+  gpu_info.gpu.vendor_id = kNvidiaVendorId;
+
+  scoped_ptr<GpuControlList> control_list(Create());
+  EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
+
+  std::set<int> features = control_list->MakeDecision(
+      GpuControlList::kOsWin, kOsVersion, gpu_info);
+  EXPECT_EMPTY_SET(features);
+  EXPECT_TRUE(control_list->needs_more_info());
+  std::vector<uint32> decision_entries;
+  control_list->GetDecisionEntries(&decision_entries, false);
+  EXPECT_EQ(0u, decision_entries.size());
+
+  gpu_info.driver_version = "11";
+  features = control_list->MakeDecision(
+      GpuControlList::kOsWin, kOsVersion, gpu_info);
+  EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
+  EXPECT_FALSE(control_list->needs_more_info());
+  control_list->GetDecisionEntries(&decision_entries, false);
+  EXPECT_EQ(1u, decision_entries.size());
+}
+
 TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) {
   const std::string json = LONG_STRING_CONST(
       {
@@ -302,10 +348,7 @@ TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) {
             "vendor_id": "0x8086",
             "exceptions": [
               {
-                "gl_renderer": {
-                  "op": "contains",
-                  "value": "mesa"
-                }
+                "gl_renderer": ".*mesa.*"
               }
             ],
             "features": [
@@ -448,5 +491,98 @@ TEST_F(GpuControlListTest, ExceptionWithoutVendorId) {
   EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
 }
 
+TEST_F(GpuControlListTest, AMDSwitchable) {
+  GPUInfo gpu_info;
+  gpu_info.amd_switchable = true;
+  gpu_info.gpu.vendor_id = kAmdVendorId;
+  gpu_info.gpu.device_id = 0x6760;
+  GPUInfo::GPUDevice integrated_gpu;
+  integrated_gpu.vendor_id = kIntelVendorId;
+  integrated_gpu.device_id = 0x0116;
+  gpu_info.secondary_gpus.push_back(integrated_gpu);
+
+  {  // amd_switchable_discrete entry
+    const std::string json= LONG_STRING_CONST(
+        {
+          "name": "gpu control list",
+          "version": "0.1",
+          "entries": [
+            {
+              "id": 1,
+              "os": {
+                "type": "win"
+              },
+              "multi_gpu_style": "amd_switchable_discrete",
+              "features": [
+                "test_feature_0"
+              ]
+            }
+          ]
+        }
+    );
+
+    scoped_ptr<GpuControlList> control_list(Create());
+    EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
+
+    // Integrated GPU is active
+    gpu_info.gpu.active = false;
+    gpu_info.secondary_gpus[0].active = true;
+    std::set<int> features = control_list->MakeDecision(
+        GpuControlList::kOsWin, kOsVersion, gpu_info);
+    EXPECT_EMPTY_SET(features);
+
+    // Discrete GPU is active
+    gpu_info.gpu.active = true;
+    gpu_info.secondary_gpus[0].active = false;
+    features = control_list->MakeDecision(
+        GpuControlList::kOsWin, kOsVersion, gpu_info);
+    EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
+  }
+
+  {  // amd_switchable_integrated entry
+    const std::string json= LONG_STRING_CONST(
+        {
+          "name": "gpu control list",
+          "version": "0.1",
+          "entries": [
+            {
+              "id": 1,
+              "os": {
+                "type": "win"
+              },
+              "multi_gpu_style": "amd_switchable_integrated",
+              "features": [
+                "test_feature_0"
+              ]
+            }
+          ]
+        }
+    );
+
+    scoped_ptr<GpuControlList> control_list(Create());
+    EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
+
+    // Discrete GPU is active
+    gpu_info.gpu.active = true;
+    gpu_info.secondary_gpus[0].active = false;
+    std::set<int> features = control_list->MakeDecision(
+        GpuControlList::kOsWin, kOsVersion, gpu_info);
+    EXPECT_EMPTY_SET(features);
+
+    // Integrated GPU is active
+    gpu_info.gpu.active = false;
+    gpu_info.secondary_gpus[0].active = true;
+    features = control_list->MakeDecision(
+        GpuControlList::kOsWin, kOsVersion, gpu_info);
+    EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
+
+    // For non AMD switchable
+    gpu_info.amd_switchable = false;
+    features = control_list->MakeDecision(
+        GpuControlList::kOsWin, kOsVersion, gpu_info);
+    EXPECT_EMPTY_SET(features);
+  }
+}
+
 }  // namespace gpu