Home | History | Annotate | Download | only in config
      1 // Copyright (c) 2012 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 "gpu/config/gpu_info.h"
      6 #include "gpu/config/gpu_test_config.h"
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace gpu {
     10 
     11 class GPUTestConfigTest : public testing::Test {
     12  public:
     13   GPUTestConfigTest() { }
     14 
     15   virtual ~GPUTestConfigTest() { }
     16 
     17  protected:
     18   virtual void SetUp() { }
     19 
     20   virtual void TearDown() { }
     21 };
     22 
     23 TEST_F(GPUTestConfigTest, EmptyValues) {
     24   GPUTestConfig config;
     25   EXPECT_EQ(GPUTestConfig::kOsUnknown, config.os());
     26   EXPECT_EQ(0u, config.gpu_vendor().size());
     27   EXPECT_EQ(0u, config.gpu_device_id());
     28   EXPECT_EQ(GPUTestConfig::kBuildTypeUnknown, config.build_type());
     29 }
     30 
     31 TEST_F(GPUTestConfigTest, SetGPUInfo) {
     32   GPUInfo gpu_info;
     33   gpu_info.gpu.vendor_id = 0x10de;
     34   gpu_info.gpu.device_id = 0x0640;
     35   GPUTestBotConfig config;
     36   EXPECT_TRUE(config.SetGPUInfo(gpu_info));
     37   EXPECT_EQ(1u, config.gpu_vendor().size());
     38   EXPECT_EQ(gpu_info.gpu.vendor_id, config.gpu_vendor()[0]);
     39   EXPECT_EQ(gpu_info.gpu.device_id, config.gpu_device_id());
     40 
     41   gpu_info.gpu.vendor_id = 0x8086;
     42   gpu_info.gpu.device_id = 0x0046;
     43   EXPECT_TRUE(config.SetGPUInfo(gpu_info));
     44   EXPECT_EQ(1u, config.gpu_vendor().size());
     45   EXPECT_EQ(gpu_info.gpu.vendor_id, config.gpu_vendor()[0]);
     46   EXPECT_EQ(gpu_info.gpu.device_id, config.gpu_device_id());
     47 }
     48 
     49 TEST_F(GPUTestConfigTest, IsValid) {
     50   {
     51     GPUTestConfig config;
     52     config.set_gpu_device_id(0x0640);
     53     EXPECT_FALSE(config.IsValid());
     54     config.AddGPUVendor(0x10de);
     55     EXPECT_TRUE(config.IsValid());
     56   }
     57 
     58   {
     59     GPUTestBotConfig config;
     60     config.set_build_type(GPUTestConfig::kBuildTypeRelease);
     61     config.set_os(GPUTestConfig::kOsWin7);
     62     config.set_gpu_device_id(0x0640);
     63     EXPECT_FALSE(config.IsValid());
     64     config.AddGPUVendor(0x10de);
     65     EXPECT_TRUE(config.IsValid());
     66 
     67     config.set_gpu_device_id(0);
     68     EXPECT_FALSE(config.IsValid());
     69     config.set_gpu_device_id(0x0640);
     70     EXPECT_TRUE(config.IsValid());
     71 
     72     config.set_os(GPUTestConfig::kOsWin);
     73     EXPECT_FALSE(config.IsValid());
     74     config.set_os(GPUTestConfig::kOsWin7 | GPUTestConfig::kOsWinXP);
     75     EXPECT_FALSE(config.IsValid());
     76     config.set_os(GPUTestConfig::kOsWin7);
     77     EXPECT_TRUE(config.IsValid());
     78 
     79     config.set_build_type(GPUTestConfig::kBuildTypeUnknown);
     80     EXPECT_FALSE(config.IsValid());
     81     config.set_build_type(GPUTestConfig::kBuildTypeRelease);
     82     EXPECT_TRUE(config.IsValid());
     83   }
     84 }
     85 
     86 TEST_F(GPUTestConfigTest, Matches) {
     87   GPUTestBotConfig config;
     88   config.set_os(GPUTestConfig::kOsWin7);
     89   config.set_build_type(GPUTestConfig::kBuildTypeRelease);
     90   config.AddGPUVendor(0x10de);
     91   config.set_gpu_device_id(0x0640);
     92   EXPECT_TRUE(config.IsValid());
     93 
     94   {  // os matching
     95     GPUTestConfig config2;
     96     EXPECT_TRUE(config.Matches(config2));
     97     config2.set_os(GPUTestConfig::kOsWin);
     98     EXPECT_TRUE(config.Matches(config2));
     99     config2.set_os(GPUTestConfig::kOsWin7);
    100     EXPECT_TRUE(config.Matches(config2));
    101     config2.set_os(GPUTestConfig::kOsMac);
    102     EXPECT_FALSE(config.Matches(config2));
    103     config2.set_os(GPUTestConfig::kOsWin7 | GPUTestConfig::kOsLinux);
    104     EXPECT_TRUE(config.Matches(config2));
    105   }
    106 
    107   {  // gpu vendor matching
    108     {
    109       GPUTestConfig config2;
    110       config2.AddGPUVendor(0x10de);
    111       EXPECT_TRUE(config.Matches(config2));
    112       config2.AddGPUVendor(0x1004);
    113       EXPECT_TRUE(config.Matches(config2));
    114     }
    115     {
    116       GPUTestConfig config2;
    117       config2.AddGPUVendor(0x8086);
    118       EXPECT_FALSE(config.Matches(config2));
    119     }
    120   }
    121 
    122   {  // build type matching
    123     GPUTestConfig config2;
    124     config2.set_build_type(GPUTestConfig::kBuildTypeRelease);
    125     EXPECT_TRUE(config.Matches(config2));
    126     config2.set_build_type(GPUTestConfig::kBuildTypeRelease |
    127                            GPUTestConfig::kBuildTypeDebug);
    128     EXPECT_TRUE(config.Matches(config2));
    129     config2.set_build_type(GPUTestConfig::kBuildTypeDebug);
    130     EXPECT_FALSE(config.Matches(config2));
    131   }
    132 
    133   {  // exact matching
    134     GPUTestConfig config2;
    135     config2.set_os(GPUTestConfig::kOsWin7);
    136     config2.set_build_type(GPUTestConfig::kBuildTypeRelease);
    137     config2.AddGPUVendor(0x10de);
    138     config2.set_gpu_device_id(0x0640);
    139     EXPECT_TRUE(config.Matches(config2));
    140     config2.set_gpu_device_id(0x0641);
    141     EXPECT_FALSE(config.Matches(config2));
    142   }
    143 }
    144 
    145 TEST_F(GPUTestConfigTest, StringMatches) {
    146   GPUTestBotConfig config;
    147   config.set_os(GPUTestConfig::kOsWin7);
    148   config.set_build_type(GPUTestConfig::kBuildTypeRelease);
    149   config.AddGPUVendor(0x10de);
    150   config.set_gpu_device_id(0x0640);
    151   EXPECT_TRUE(config.IsValid());
    152 
    153   EXPECT_TRUE(config.Matches(std::string()));
    154 
    155   // os matching
    156   EXPECT_TRUE(config.Matches("WIN"));
    157   EXPECT_TRUE(config.Matches("WIN7"));
    158   EXPECT_FALSE(config.Matches("MAC"));
    159   EXPECT_TRUE(config.Matches("WIN7 LINUX"));
    160 
    161   // gpu vendor matching
    162   EXPECT_TRUE(config.Matches("NVIDIA"));
    163   EXPECT_TRUE(config.Matches("NVIDIA AMD"));
    164   EXPECT_FALSE(config.Matches("INTEL"));
    165 
    166   // build type matching
    167   EXPECT_TRUE(config.Matches("RELEASE"));
    168   EXPECT_TRUE(config.Matches("RELEASE DEBUG"));
    169   EXPECT_FALSE(config.Matches("DEBUG"));
    170 
    171   // exact matching
    172   EXPECT_TRUE(config.Matches("WIN7 RELEASE NVIDIA 0X0640"));
    173   EXPECT_FALSE(config.Matches("WIN7 RELEASE NVIDIA 0X0641"));
    174 }
    175 
    176 TEST_F(GPUTestConfigTest, OverlapsWith) {
    177   {  // os
    178     // win vs win7
    179     GPUTestConfig config;
    180     config.set_os(GPUTestConfig::kOsWin);
    181     GPUTestConfig config2;
    182     config2.set_os(GPUTestConfig::kOsWin7);
    183     EXPECT_TRUE(config.OverlapsWith(config2));
    184     EXPECT_TRUE(config2.OverlapsWith(config));
    185     // win vs win7+linux
    186     config2.set_os(GPUTestConfig::kOsWin7 | GPUTestConfig::kOsLinux);
    187     EXPECT_TRUE(config.OverlapsWith(config2));
    188     EXPECT_TRUE(config2.OverlapsWith(config));
    189     // win vs mac
    190     config2.set_os(GPUTestConfig::kOsMac);
    191     EXPECT_FALSE(config.OverlapsWith(config2));
    192     EXPECT_FALSE(config2.OverlapsWith(config));
    193     // win vs unknown
    194     config2.set_os(GPUTestConfig::kOsUnknown);
    195     EXPECT_TRUE(config.OverlapsWith(config2));
    196     EXPECT_TRUE(config2.OverlapsWith(config));
    197   }
    198 
    199   {  // gpu vendor
    200     GPUTestConfig config;
    201     config.AddGPUVendor(0x10de);
    202     // nvidia vs unknown
    203     GPUTestConfig config2;
    204     EXPECT_TRUE(config.OverlapsWith(config2));
    205     EXPECT_TRUE(config2.OverlapsWith(config));
    206     // nvidia vs intel
    207     config2.AddGPUVendor(0x1086);
    208     EXPECT_FALSE(config.OverlapsWith(config2));
    209     EXPECT_FALSE(config2.OverlapsWith(config));
    210     // nvidia vs nvidia+intel
    211     config2.AddGPUVendor(0x10de);
    212     EXPECT_TRUE(config.OverlapsWith(config2));
    213     EXPECT_TRUE(config2.OverlapsWith(config));
    214   }
    215 
    216   {  // build type
    217     // release vs debug
    218     GPUTestConfig config;
    219     config.set_build_type(GPUTestConfig::kBuildTypeRelease);
    220     GPUTestConfig config2;
    221     config2.set_build_type(GPUTestConfig::kBuildTypeDebug);
    222     EXPECT_FALSE(config.OverlapsWith(config2));
    223     EXPECT_FALSE(config2.OverlapsWith(config));
    224     // release vs release+debug
    225     config2.set_build_type(GPUTestConfig::kBuildTypeRelease |
    226                            GPUTestConfig::kBuildTypeDebug);
    227     EXPECT_TRUE(config.OverlapsWith(config2));
    228     EXPECT_TRUE(config2.OverlapsWith(config));
    229     // release vs unknown
    230     config2.set_build_type(GPUTestConfig::kBuildTypeUnknown);
    231     EXPECT_TRUE(config.OverlapsWith(config2));
    232     EXPECT_TRUE(config2.OverlapsWith(config));
    233   }
    234 
    235   {  // win7 vs nvidia
    236     GPUTestConfig config;
    237     config.set_os(GPUTestConfig::kOsWin7);
    238     GPUTestConfig config2;
    239     config2.AddGPUVendor(0x10de);
    240     EXPECT_TRUE(config.OverlapsWith(config2));
    241     EXPECT_TRUE(config2.OverlapsWith(config));
    242   }
    243 }
    244 
    245 TEST_F(GPUTestConfigTest, LoadCurrentConfig) {
    246   GPUTestBotConfig config;
    247   GPUInfo gpu_info;
    248   gpu_info.gpu.vendor_id = 0x10de;
    249   gpu_info.gpu.device_id = 0x0640;
    250   EXPECT_TRUE(config.LoadCurrentConfig(&gpu_info));
    251   EXPECT_TRUE(config.IsValid());
    252 }
    253 
    254 }  // namespace gpu
    255 
    256