Home | History | Annotate | Download | only in tests
      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 <GLES2/gl2.h>
      6 #include <GLES2/gl2ext.h>
      7 #include <GLES2/gl2extchromium.h>
      8 
      9 #include "base/threading/platform_thread.h"
     10 #include "gpu/command_buffer/tests/gl_manager.h"
     11 #include "gpu/command_buffer/tests/gl_test_utils.h"
     12 #include "testing/gmock/include/gmock/gmock.h"
     13 #include "testing/gtest/include/gtest/gtest.h"
     14 
     15 namespace gpu {
     16 
     17 class QueryTest : public testing::Test {
     18  protected:
     19   virtual void SetUp() {
     20     gl_.Initialize(GLManager::Options());
     21   }
     22 
     23   virtual void TearDown() {
     24     gl_.Destroy();
     25   }
     26 
     27   GLManager gl_;
     28 };
     29 
     30 TEST_F(QueryTest, GetErrorBasic) {
     31   EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query"));
     32 
     33   GLuint query = 0;
     34   glGenQueriesEXT(1, &query);
     35 
     36   GLuint query_status = 0;
     37   GLuint result = 0;
     38 
     39   glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, query);
     40   glEnable(GL_TEXTURE_2D);  // Generates an INVALID_ENUM error
     41   glEndQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM);
     42 
     43   glFinish();
     44 
     45   query_status = 0;
     46   result = 0;
     47   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &result);
     48   EXPECT_TRUE(result);
     49   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_status);
     50   EXPECT_EQ(static_cast<uint32>(GL_INVALID_ENUM), query_status);
     51 }
     52 
     53 TEST_F(QueryTest, DISABLED_LatencyQueryBasic) {
     54   EXPECT_TRUE(GLTestHelper::HasExtension(
     55                   "GL_CHROMIUM_command_buffer_latency_query"));
     56 
     57   GLuint query = 0;
     58   glGenQueriesEXT(1, &query);
     59 
     60   GLuint query_result = 0;
     61   GLuint available = 0;
     62 
     63   // First test a query with a ~1ms "latency".
     64   const unsigned int kExpectedLatencyMicroseconds = 2000;
     65   const unsigned int kTimePrecisionMicroseconds = 1000;
     66 
     67   glBeginQueryEXT(GL_LATENCY_QUERY_CHROMIUM, query);
     68   // Usually, we want to measure gpu-side latency, but we fake it by
     69   // adding client side latency for our test because it's easier.
     70   base::PlatformThread::Sleep(
     71       base::TimeDelta::FromMicroseconds(kExpectedLatencyMicroseconds));
     72   glEndQueryEXT(GL_LATENCY_QUERY_CHROMIUM);
     73 
     74   glFinish();
     75 
     76   query_result = 0;
     77   available = 0;
     78   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &available);
     79   EXPECT_TRUE(available);
     80   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_result);
     81   EXPECT_GE(query_result, kExpectedLatencyMicroseconds
     82                           - kTimePrecisionMicroseconds);
     83   EXPECT_LE(query_result, kExpectedLatencyMicroseconds
     84                           + kTimePrecisionMicroseconds);
     85 
     86   // Then test a query with the lowest latency possible.
     87   glBeginQueryEXT(GL_LATENCY_QUERY_CHROMIUM, query);
     88   glEndQueryEXT(GL_LATENCY_QUERY_CHROMIUM);
     89 
     90   glFinish();
     91 
     92   query_result = 0;
     93   available = 0;
     94   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &available);
     95   EXPECT_TRUE(available);
     96   glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_result);
     97 
     98   EXPECT_LE(query_result, kTimePrecisionMicroseconds);
     99 }
    100 
    101 }  // namespace gpu
    102 
    103 
    104