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 "base/memory/scoped_ptr.h"
      6 #include "gpu/config/gpu_info.h"
      7 #include "gpu/config/gpu_info_collector.h"
      8 #include "testing/gmock/include/gmock/gmock.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 #include "ui/gl/gl_mock.h"
     11 
     12 using ::gfx::MockGLInterface;
     13 using ::testing::Return;
     14 
     15 namespace gpu {
     16 
     17 class GPUInfoCollectorTest : public testing::Test {
     18  public:
     19   GPUInfoCollectorTest() {}
     20   virtual ~GPUInfoCollectorTest() { }
     21 
     22   virtual void SetUp() {
     23     gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
     24     ::gfx::MockGLInterface::SetGLInterface(gl_.get());
     25 #if defined(OS_WIN)
     26     const uint32 vendor_id = 0x10de;
     27     const uint32 device_id = 0x0658;
     28     const char* driver_vendor = "";  // not implemented
     29     const char* driver_version = "";
     30     const char* shader_version = "1.40";
     31     const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
     32     const char* gl_vendor = "NVIDIA Corporation";
     33     const char* gl_version = "3.1.0";
     34     const char* gl_shading_language_version = "1.40 NVIDIA via Cg compiler";
     35     const char* gl_extensions =
     36         "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
     37         "GL_EXT_read_format_bgra";
     38 #elif defined(OS_MACOSX)
     39     const uint32 vendor_id = 0x10de;
     40     const uint32 device_id = 0x0640;
     41     const char* driver_vendor = "";  // not implemented
     42     const char* driver_version = "1.6.18";
     43     const char* shader_version = "1.20";
     44     const char* gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
     45     const char* gl_vendor = "NVIDIA Corporation";
     46     const char* gl_version = "2.1 NVIDIA-1.6.18";
     47     const char* gl_shading_language_version = "1.20 ";
     48     const char* gl_extensions =
     49         "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
     50         "GL_EXT_read_format_bgra";
     51 #else  // defined (OS_LINUX)
     52     const uint32 vendor_id = 0x10de;
     53     const uint32 device_id = 0x0658;
     54     const char* driver_vendor = "NVIDIA";
     55     const char* driver_version = "195.36.24";
     56     const char* shader_version = "1.50";
     57     const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
     58     const char* gl_vendor = "NVIDIA Corporation";
     59     const char* gl_version = "3.2.0 NVIDIA 195.36.24";
     60     const char* gl_shading_language_version = "1.50 NVIDIA via Cg compiler";
     61     const char* gl_extensions =
     62         "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
     63         "GL_EXT_read_format_bgra";
     64 #endif
     65     test_values_.gpu.vendor_id = vendor_id;
     66     test_values_.gpu.device_id = device_id;
     67     test_values_.driver_vendor = driver_vendor;
     68     test_values_.driver_version =driver_version;
     69     test_values_.pixel_shader_version = shader_version;
     70     test_values_.vertex_shader_version = shader_version;
     71     test_values_.gl_renderer = gl_renderer;
     72     test_values_.gl_vendor = gl_vendor;
     73     test_values_.gl_version = gl_version;
     74     test_values_.gl_extensions = gl_extensions;
     75     test_values_.can_lose_context = false;
     76 
     77     EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
     78         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
     79             gl_extensions)));
     80     EXPECT_CALL(*gl_, GetString(GL_SHADING_LANGUAGE_VERSION))
     81         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
     82             gl_shading_language_version)));
     83     EXPECT_CALL(*gl_, GetString(GL_VERSION))
     84         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
     85             gl_version)));
     86     EXPECT_CALL(*gl_, GetString(GL_VENDOR))
     87         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
     88             gl_vendor)));
     89     EXPECT_CALL(*gl_, GetString(GL_RENDERER))
     90         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
     91             gl_renderer)));
     92   }
     93 
     94   virtual void TearDown() {
     95     ::gfx::MockGLInterface::SetGLInterface(NULL);
     96     gl_.reset();
     97   }
     98 
     99  public:
    100   // Use StrictMock to make 100% sure we know how GL will be called.
    101   scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
    102   GPUInfo test_values_;
    103 };
    104 
    105 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
    106 //            it involves several complicated mocks for each platform.
    107 
    108 // TODO(kbr): re-enable these tests; see http://crbug.com/100285 .
    109 
    110 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVendorGL) {
    111   GPUInfo gpu_info;
    112   CollectGraphicsInfoGL(&gpu_info);
    113   EXPECT_EQ(test_values_.driver_vendor,
    114             gpu_info.driver_vendor);
    115 }
    116 
    117 // Skip Windows because the driver version is obtained from bot registry.
    118 #if !defined(OS_WIN)
    119 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVersionGL) {
    120   GPUInfo gpu_info;
    121   CollectGraphicsInfoGL(&gpu_info);
    122   EXPECT_EQ(test_values_.driver_version,
    123             gpu_info.driver_version);
    124 }
    125 #endif
    126 
    127 TEST_F(GPUInfoCollectorTest, DISABLED_PixelShaderVersionGL) {
    128   GPUInfo gpu_info;
    129   CollectGraphicsInfoGL(&gpu_info);
    130   EXPECT_EQ(test_values_.pixel_shader_version,
    131             gpu_info.pixel_shader_version);
    132 }
    133 
    134 TEST_F(GPUInfoCollectorTest, DISABLED_VertexShaderVersionGL) {
    135   GPUInfo gpu_info;
    136   CollectGraphicsInfoGL(&gpu_info);
    137   EXPECT_EQ(test_values_.vertex_shader_version,
    138             gpu_info.vertex_shader_version);
    139 }
    140 
    141 TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionGL) {
    142   GPUInfo gpu_info;
    143   CollectGraphicsInfoGL(&gpu_info);
    144   EXPECT_EQ(test_values_.gl_version, gpu_info.gl_version);
    145 }
    146 
    147 TEST_F(GPUInfoCollectorTest, DISABLED_GLRendererGL) {
    148   GPUInfo gpu_info;
    149   CollectGraphicsInfoGL(&gpu_info);
    150   EXPECT_EQ(test_values_.gl_renderer, gpu_info.gl_renderer);
    151 }
    152 
    153 TEST_F(GPUInfoCollectorTest, DISABLED_GLVendorGL) {
    154   GPUInfo gpu_info;
    155   CollectGraphicsInfoGL(&gpu_info);
    156   EXPECT_EQ(test_values_.gl_vendor, gpu_info.gl_vendor);
    157 }
    158 
    159 TEST_F(GPUInfoCollectorTest, DISABLED_GLExtensionsGL) {
    160   GPUInfo gpu_info;
    161   CollectGraphicsInfoGL(&gpu_info);
    162   EXPECT_EQ(test_values_.gl_extensions, gpu_info.gl_extensions);
    163 }
    164 
    165 }  // namespace gpu
    166 
    167