15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_info.h"
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_info_collector.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gl/gl_implementation.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gl/gl_mock.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::gfx::MockGLInterface;
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::Return;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace gpu {
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GPUInfoCollectorTest : public testing::Test {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GPUInfoCollectorTest() {}
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~GPUInfoCollectorTest() { }
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUp() {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(kbr): make this setup robust in the case where
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // GLSurface::InitializeOneOff() has already been called by
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // another unit test. http://crbug.com/100285
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::InitializeGLBindings(gfx::kGLImplementationMockGL);
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ::gfx::GLInterface::SetGLInterface(gl_.get());
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 vendor_id = 0x10de;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 device_id = 0x0658;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_vendor = "";  // not implemented
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_version = "";
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* shader_version = "1.40";
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version = "3.1";
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_vendor = "NVIDIA Corporation";
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version_string = "3.1.0";
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_shading_language_version = "1.40 NVIDIA via Cg compiler";
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_extensions =
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_EXT_read_format_bgra";
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_MACOSX)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 vendor_id = 0x10de;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 device_id = 0x0640;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_vendor = "";  // not implemented
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_version = "1.6.18";
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* shader_version = "1.20";
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version = "2.1";
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_vendor = "NVIDIA Corporation";
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version_string = "2.1 NVIDIA-1.6.18";
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_shading_language_version = "1.20 ";
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_extensions =
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_EXT_read_format_bgra";
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else  // defined (OS_LINUX)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 vendor_id = 0x10de;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const uint32 device_id = 0x0658;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_vendor = "NVIDIA";
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* driver_version = "195.36.24";
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* shader_version = "1.50";
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version = "3.2";
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_vendor = "NVIDIA Corporation";
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_version_string = "3.2.0 NVIDIA 195.36.24";
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_shading_language_version = "1.50 NVIDIA via Cg compiler";
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* gl_extensions =
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        "GL_EXT_read_format_bgra";
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gpu.vendor_id = vendor_id;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gpu.device_id = device_id;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.driver_vendor = driver_vendor;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.driver_version =driver_version;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.pixel_shader_version = shader_version;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.vertex_shader_version = shader_version;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gl_version = gl_version;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gl_renderer = gl_renderer;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gl_vendor = gl_vendor;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gl_version_string = gl_version_string;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.gl_extensions = gl_extensions;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_values_.can_lose_context = false;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gl_extensions)));
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_CALL(*gl_, GetString(GL_SHADING_LANGUAGE_VERSION))
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gl_shading_language_version)));
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_CALL(*gl_, GetString(GL_VERSION))
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gl_version_string)));
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_CALL(*gl_, GetString(GL_VENDOR))
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gl_vendor)));
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_CALL(*gl_, GetString(GL_RENDERER))
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gl_renderer)));
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void TearDown() {
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ::gfx::GLInterface::SetGLInterface(NULL);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gl_.reset();
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use StrictMock to make 100% sure we know how GL will be called.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo test_values_;
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(rlp): Test the vendor and device id collection if deemed necessary as
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//            it involves several complicated mocks for each platform.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(kbr): re-enable these tests; see http://crbug.com/100285 .
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_DriverVendorGL) {
12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.driver_vendor,
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.driver_vendor);
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Skip Windows because the driver version is obtained from bot registry.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_WIN)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_DriverVersionGL) {
12990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.driver_version,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.driver_version);
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_PixelShaderVersionGL) {
13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.pixel_shader_version,
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.pixel_shader_version);
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_VertexShaderVersionGL) {
14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.vertex_shader_version,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.vertex_shader_version);
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionGL) {
15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.gl_version,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.gl_version);
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionStringGL) {
15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.gl_version_string,
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.gl_version_string);
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_GLRendererGL) {
16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.gl_renderer,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.gl_renderer);
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_GLVendorGL) {
17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.gl_vendor,
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.gl_vendor);
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(GPUInfoCollectorTest, DISABLED_GLExtensionsGL) {
17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GPUInfo gpu_info;
18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CollectGraphicsInfoGL(&gpu_info);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(test_values_.gl_extensions,
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            gpu_info.gl_extensions);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace gpu
18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
187