1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297

gpu / config / gpu_test_config_unittest.cc [blame]

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/config/gpu_info.h"
#include "gpu/config/gpu_test_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gpu {

class GPUTestConfigTest : public testing::Test {
 public:
  GPUTestConfigTest() = default;

  ~GPUTestConfigTest() override = default;

 protected:
  void SetUp() override {}

  void TearDown() override {}
};

TEST_F(GPUTestConfigTest, EmptyValues) {
  GPUTestConfig config;
  EXPECT_EQ(GPUTestConfig::kOsUnknown, config.os());
  EXPECT_EQ(0u, config.gpu_vendor().size());
  EXPECT_EQ(0u, config.gpu_device_id());
  EXPECT_EQ(GPUTestConfig::kBuildTypeUnknown, config.build_type());
  EXPECT_EQ(GPUTestConfig::kAPIUnknown, config.api());
  EXPECT_EQ(GPUTestConfig::kCommandDecoderUnknown, config.command_decoder());
}

TEST_F(GPUTestConfigTest, SetGPUInfo) {
  GPUInfo gpu_info;
  gpu_info.gpu.vendor_id = 0x10de;
  gpu_info.gpu.device_id = 0x0640;
  GPUTestBotConfig config;
  EXPECT_TRUE(config.SetGPUInfo(gpu_info));
  EXPECT_EQ(1u, config.gpu_vendor().size());
  EXPECT_EQ(gpu_info.gpu.vendor_id, config.gpu_vendor()[0]);
  EXPECT_EQ(gpu_info.gpu.device_id, config.gpu_device_id());

  gpu_info.gpu.vendor_id = 0x8086;
  gpu_info.gpu.device_id = 0x0046;
  EXPECT_TRUE(config.SetGPUInfo(gpu_info));
  EXPECT_EQ(1u, config.gpu_vendor().size());
  EXPECT_EQ(gpu_info.gpu.vendor_id, config.gpu_vendor()[0]);
  EXPECT_EQ(gpu_info.gpu.device_id, config.gpu_device_id());
}

TEST_F(GPUTestConfigTest, IsValid) {
  {
    GPUTestConfig config;
    config.set_gpu_device_id(0x0640);
    EXPECT_FALSE(config.IsValid());
    config.AddGPUVendor(0x10de);
    EXPECT_TRUE(config.IsValid());
  }

  {
    GPUTestBotConfig config;
    config.set_build_type(GPUTestConfig::kBuildTypeRelease);
    config.set_os(GPUTestConfig::kOsWin10);
    config.set_gpu_device_id(0x0640);
    EXPECT_FALSE(config.IsValid());
    config.AddGPUVendor(0x10de);
    EXPECT_TRUE(config.IsValid());

    // Device ID of 0 is valid only on macOS.
    config.set_gpu_device_id(0);
    config.set_os(GPUTestConfig::kOsMacBigSur);
    EXPECT_TRUE(config.IsValid());
    config.set_os(GPUTestConfig::kOsWin10);
    EXPECT_FALSE(config.IsValid());

    config.set_gpu_device_id(0x0640);
    EXPECT_TRUE(config.IsValid());

    config.set_os(GPUTestConfig::kOsWin10);
    EXPECT_TRUE(config.IsValid());

    config.set_build_type(GPUTestConfig::kBuildTypeUnknown);
    EXPECT_FALSE(config.IsValid());
    config.set_build_type(GPUTestConfig::kBuildTypeRelease);
    EXPECT_TRUE(config.IsValid());
  }
}

TEST_F(GPUTestConfigTest, Matches) {
  GPUTestBotConfig config;
  config.set_os(GPUTestConfig::kOsWin10);
  config.set_build_type(GPUTestConfig::kBuildTypeRelease);
  config.AddGPUVendor(0x10de);
  config.set_gpu_device_id(0x0640);
  config.set_api(GPUTestConfig::kAPID3D11);
  config.set_command_decoder(GPUTestConfig::kCommandDecoderPassthrough);
  EXPECT_TRUE(config.IsValid());

  {  // os matching
    GPUTestConfig config2;
    EXPECT_TRUE(config.Matches(config2));
    config2.set_os(GPUTestConfig::kOsWin);
    EXPECT_TRUE(config.Matches(config2));
    config2.set_os(GPUTestConfig::kOsWin10);
    EXPECT_TRUE(config.Matches(config2));
    config2.set_os(GPUTestConfig::kOsMac);
    EXPECT_FALSE(config.Matches(config2));
    config2.set_os(GPUTestConfig::kOsWin10 | GPUTestConfig::kOsLinux);
    EXPECT_TRUE(config.Matches(config2));
  }

  {  // gpu vendor matching
    {
      GPUTestConfig config2;
      config2.AddGPUVendor(0x10de);
      EXPECT_TRUE(config.Matches(config2));
      config2.AddGPUVendor(0x1004);
      EXPECT_TRUE(config.Matches(config2));
    }
    {
      GPUTestConfig config2;
      config2.AddGPUVendor(0x8086);
      EXPECT_FALSE(config.Matches(config2));
    }
  }

  {  // build type matching
    GPUTestConfig config2;
    config2.set_build_type(GPUTestConfig::kBuildTypeRelease);
    EXPECT_TRUE(config.Matches(config2));
    config2.set_build_type(GPUTestConfig::kBuildTypeRelease |
                           GPUTestConfig::kBuildTypeDebug);
    EXPECT_TRUE(config.Matches(config2));
    config2.set_build_type(GPUTestConfig::kBuildTypeDebug);
    EXPECT_FALSE(config.Matches(config2));
  }

  {  // exact matching
    GPUTestConfig config2;
    config2.set_os(GPUTestConfig::kOsWin10);
    config2.set_build_type(GPUTestConfig::kBuildTypeRelease);
    config2.AddGPUVendor(0x10de);
    config2.set_gpu_device_id(0x0640);
    EXPECT_TRUE(config.Matches(config2));
    config2.set_gpu_device_id(0x0641);
    EXPECT_FALSE(config.Matches(config2));
  }

  {  // api matching
    {
      GPUTestConfig config2;
      config2.set_api(GPUTestConfig::kAPID3D11);
      EXPECT_TRUE(config.Matches(config2));
      config2.set_api(config2.api() | GPUTestConfig::kAPID3D9);
      EXPECT_TRUE(config.Matches(config2));
    }
    {
      GPUTestConfig config2;
      config2.set_api(GPUTestConfig::kAPID3D9);
      EXPECT_FALSE(config.Matches(config2));
    }
  }
  {  // command decoder matching
    {
      GPUTestConfig config2;
      config2.set_command_decoder(GPUTestConfig::kCommandDecoderPassthrough);
      EXPECT_TRUE(config.Matches(config2));
    }
    {
      GPUTestConfig config2;
      config2.set_command_decoder(GPUTestConfig::kCommandDecoderValidating);
      EXPECT_FALSE(config.Matches(config2));
    }
  }
}

TEST_F(GPUTestConfigTest, StringMatches) {
  GPUTestBotConfig config;
  config.set_os(GPUTestConfig::kOsWin10);
  config.set_build_type(GPUTestConfig::kBuildTypeRelease);
  config.AddGPUVendor(0x10de);
  config.set_gpu_device_id(0x0640);
  config.set_api(GPUTestConfig::kAPID3D11);
  config.set_command_decoder(GPUTestConfig::kCommandDecoderPassthrough);
  EXPECT_TRUE(config.IsValid());

  EXPECT_TRUE(config.Matches(std::string()));

  // os matching
  EXPECT_TRUE(config.Matches("WIN"));
  EXPECT_TRUE(config.Matches("WIN10"));
  EXPECT_FALSE(config.Matches("MAC"));
  EXPECT_TRUE(config.Matches("WIN10 LINUX"));

  // gpu vendor matching
  EXPECT_TRUE(config.Matches("NVIDIA"));
  EXPECT_TRUE(config.Matches("NVIDIA AMD"));
  EXPECT_FALSE(config.Matches("INTEL"));

  // build type matching
  EXPECT_TRUE(config.Matches("RELEASE"));
  EXPECT_TRUE(config.Matches("RELEASE DEBUG"));
  EXPECT_FALSE(config.Matches("DEBUG"));

  // exact matching
  EXPECT_TRUE(config.Matches("WIN10 RELEASE NVIDIA 0X0640"));
  EXPECT_FALSE(config.Matches("WIN10 RELEASE NVIDIA 0X0641"));

  // api matching
  EXPECT_TRUE(config.Matches("D3D11"));
  EXPECT_FALSE(config.Matches("D3D9 OPENGL GLES"));

  // command decoder matching
  EXPECT_TRUE(config.Matches("PASSTHROUGH"));
  EXPECT_FALSE(config.Matches("VALIDATING"));
}

TEST_F(GPUTestConfigTest, OverlapsWith) {
  {  // os
      // win vs win10
      GPUTestConfig config;
      config.set_os(GPUTestConfig::kOsWin);
      GPUTestConfig config2;
      config2.set_os(GPUTestConfig::kOsWin10);
      EXPECT_TRUE(config.OverlapsWith(config2));
      EXPECT_TRUE(config2.OverlapsWith(config));
      // win vs win10+linux
      config2.set_os(GPUTestConfig::kOsWin10 | GPUTestConfig::kOsLinux);
      EXPECT_TRUE(config.OverlapsWith(config2));
      EXPECT_TRUE(config2.OverlapsWith(config));
      // win vs mac
      config2.set_os(GPUTestConfig::kOsMac);
      EXPECT_FALSE(config.OverlapsWith(config2));
      EXPECT_FALSE(config2.OverlapsWith(config));
      // win vs unknown
      config2.set_os(GPUTestConfig::kOsUnknown);
      EXPECT_TRUE(config.OverlapsWith(config2));
      EXPECT_TRUE(config2.OverlapsWith(config));
  }

  {  // gpu vendor
    GPUTestConfig config;
    config.AddGPUVendor(0x10de);
    // nvidia vs unknown
    GPUTestConfig config2;
    EXPECT_TRUE(config.OverlapsWith(config2));
    EXPECT_TRUE(config2.OverlapsWith(config));
    // nvidia vs intel
    config2.AddGPUVendor(0x1086);
    EXPECT_FALSE(config.OverlapsWith(config2));
    EXPECT_FALSE(config2.OverlapsWith(config));
    // nvidia vs nvidia+intel
    config2.AddGPUVendor(0x10de);
    EXPECT_TRUE(config.OverlapsWith(config2));
    EXPECT_TRUE(config2.OverlapsWith(config));
  }

  {  // build type
    // release vs debug
    GPUTestConfig config;
    config.set_build_type(GPUTestConfig::kBuildTypeRelease);
    GPUTestConfig config2;
    config2.set_build_type(GPUTestConfig::kBuildTypeDebug);
    EXPECT_FALSE(config.OverlapsWith(config2));
    EXPECT_FALSE(config2.OverlapsWith(config));
    // release vs release+debug
    config2.set_build_type(GPUTestConfig::kBuildTypeRelease |
                           GPUTestConfig::kBuildTypeDebug);
    EXPECT_TRUE(config.OverlapsWith(config2));
    EXPECT_TRUE(config2.OverlapsWith(config));
    // release vs unknown
    config2.set_build_type(GPUTestConfig::kBuildTypeUnknown);
    EXPECT_TRUE(config.OverlapsWith(config2));
    EXPECT_TRUE(config2.OverlapsWith(config));
  }

  {  // win10 vs nvidia
    GPUTestConfig config;
    config.set_os(GPUTestConfig::kOsWin10);
    GPUTestConfig config2;
    config2.AddGPUVendor(0x10de);
    EXPECT_TRUE(config.OverlapsWith(config2));
    EXPECT_TRUE(config2.OverlapsWith(config));
  }
}

TEST_F(GPUTestConfigTest, LoadCurrentConfig) {
  GPUTestBotConfig config;
  GPUInfo gpu_info;
  gpu_info.gpu.vendor_id = 0x10de;
  gpu_info.gpu.device_id = 0x0640;
  EXPECT_TRUE(config.LoadCurrentConfig(&gpu_info));
  EXPECT_TRUE(config.IsValid());
}

}  // namespace gpu