Home | History | Annotate | Download | only in config
      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 "gpu/config/gpu_control_list_jsons.h"
      9 #include "gpu/config/gpu_info.h"
     10 #include "gpu/config/gpu_switching_list.h"
     11 #include "gpu/config/gpu_switching_option.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 #define LONG_STRING_CONST(...) #__VA_ARGS__
     15 
     16 const char kOsVersion[] = "10.6.4";
     17 
     18 namespace gpu {
     19 
     20 class GpuSwitchingListTest : public testing::Test {
     21  public:
     22   GpuSwitchingListTest() { }
     23 
     24   virtual ~GpuSwitchingListTest() { }
     25 
     26   const GPUInfo& gpu_info() const {
     27     return gpu_info_;
     28   }
     29 
     30  protected:
     31   virtual void SetUp() {
     32     gpu_info_.gpu.vendor_id = 0x10de;
     33     gpu_info_.gpu.device_id = 0x0640;
     34     gpu_info_.driver_vendor = "NVIDIA";
     35     gpu_info_.driver_version = "1.6.18";
     36     gpu_info_.driver_date = "7-14-2009";
     37     gpu_info_.machine_model = "MacBookPro 7.1";
     38     gpu_info_.gl_vendor = "NVIDIA Corporation";
     39     gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
     40     gpu_info_.performance_stats.graphics = 5.0;
     41     gpu_info_.performance_stats.gaming = 5.0;
     42     gpu_info_.performance_stats.overall = 5.0;
     43   }
     44 
     45   virtual void TearDown() {
     46   }
     47 
     48  private:
     49   GPUInfo gpu_info_;
     50 };
     51 
     52 TEST_F(GpuSwitchingListTest, CurrentSwitchingListValidation) {
     53   scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create());
     54   EXPECT_TRUE(switching_list->LoadList(
     55       kGpuSwitchingListJson, GpuControlList::kAllOs));
     56   EXPECT_FALSE(switching_list->contains_unknown_fields());
     57 }
     58 
     59 TEST_F(GpuSwitchingListTest, GpuSwitching) {
     60   const std::string json = LONG_STRING_CONST(
     61       {
     62         "name": "gpu switching list",
     63         "version": "0.1",
     64         "entries": [
     65           {
     66             "id": 1,
     67             "os": {
     68               "type": "macosx"
     69             },
     70             "features": [
     71               "force_discrete"
     72             ]
     73           },
     74           {
     75             "id": 2,
     76             "os": {
     77               "type": "win"
     78             },
     79             "features": [
     80               "force_integrated"
     81             ]
     82           }
     83         ]
     84       }
     85   );
     86   scoped_ptr<GpuSwitchingList> switching_list(GpuSwitchingList::Create());
     87   EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs));
     88   std::set<int> switching = switching_list->MakeDecision(
     89       GpuControlList::kOsMacosx, kOsVersion, gpu_info());
     90   EXPECT_EQ(1u, switching.size());
     91   EXPECT_EQ(1u, switching.count(GPU_SWITCHING_OPTION_FORCE_DISCRETE));
     92   std::vector<uint32> entries;
     93   switching_list->GetDecisionEntries(&entries, false);
     94   ASSERT_EQ(1u, entries.size());
     95   EXPECT_EQ(1u, entries[0]);
     96 
     97   switching_list.reset(GpuSwitchingList::Create());
     98   EXPECT_TRUE(switching_list->LoadList(json, GpuControlList::kAllOs));
     99   switching = switching_list->MakeDecision(
    100       GpuControlList::kOsWin, kOsVersion, gpu_info());
    101   EXPECT_EQ(1u, switching.size());
    102   EXPECT_EQ(1u, switching.count(GPU_SWITCHING_OPTION_FORCE_INTEGRATED));
    103   switching_list->GetDecisionEntries(&entries, false);
    104   ASSERT_EQ(1u, entries.size());
    105   EXPECT_EQ(2u, entries[0]);
    106 }
    107 
    108 }  // namespace gpu
    109 
    110