Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: gpu/command_buffer/service/gpu_tracer_unittest.cc

Issue 509723002: Added support for GPU Tracing on mobile devices which support it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another gpu tracer unittest issue Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gpu_tracer_unittest.cc
diff --git a/gpu/command_buffer/service/gpu_tracer_unittest.cc b/gpu/command_buffer/service/gpu_tracer_unittest.cc
index 75d66e595475a3ec0ebad26a6a7477b49813628d..065800004b06602ec40bec4fbf758aed6b55a15e 100644
--- a/gpu/command_buffer/service/gpu_tracer_unittest.cc
+++ b/gpu/command_buffer/service/gpu_tracer_unittest.cc
@@ -51,14 +51,14 @@ class GlFakeQueries {
void SetCurrentGLTime(GLint64 current_time) { current_time_ = current_time; }
- void GenQueries(GLsizei n, GLuint* ids) {
+ void GenQueriesARB(GLsizei n, GLuint* ids) {
for (GLsizei i = 0; i < n; i++) {
ids[i] = next_query_id_++;
alloced_queries_.insert(ids[i]);
}
}
- void DeleteQueries(GLsizei n, const GLuint* ids) {
+ void DeleteQueriesARB(GLsizei n, const GLuint* ids) {
for (GLsizei i = 0; i < n; i++) {
alloced_queries_.erase(ids[i]);
query_timestamp_.erase(ids[i]);
@@ -80,6 +80,21 @@ class GlFakeQueries {
}
}
+ void GetQueryObjectivARB(GLuint id, GLenum pname, GLint* params) {
+ switch (pname) {
+ case GL_QUERY_RESULT_AVAILABLE_EXT: {
+ std::map<GLuint, GLint64>::iterator it = query_timestamp_.find(id);
+ if (it != query_timestamp_.end() && it->second <= current_time_)
+ *params = 1;
+ else
+ *params = 0;
+ break;
+ }
+ default:
+ ASSERT_TRUE(false);
+ }
+ }
+
void QueryCounter(GLuint id, GLenum target) {
switch (target) {
case GL_TIMESTAMP:
@@ -102,6 +117,17 @@ class GlFakeQueries {
}
}
+ void GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64* params) {
+ switch (pname) {
+ case GL_QUERY_RESULT_EXT:
+ ASSERT_TRUE(query_timestamp_.find(id) != query_timestamp_.end());
+ *params = query_timestamp_.find(id)->second;
+ break;
+ default:
+ ASSERT_TRUE(false);
+ }
+ }
+
protected:
GLint64 current_time_;
GLuint next_query_id_;
@@ -109,56 +135,13 @@ class GlFakeQueries {
std::map<GLuint, GLint64> query_timestamp_;
};
-class GpuTracerTest : public GpuServiceTest {
+class BaseGpuTracerTest : public GpuServiceTest {
public:
- GpuTracerTest() {}
+ BaseGpuTracerTest() {}
///////////////////////////////////////////////////////////////////////////
- protected:
- virtual void SetUp() {
- GpuServiceTest::SetUp();
- gl_fake_queries_.Reset();
- }
-
- virtual void TearDown() {
- gl_.reset();
- gl_fake_queries_.Reset();
- GpuServiceTest::TearDown();
- }
-
- void SetupTimerQueryMocks() {
- // Delegate query APIs used by GPUTrace to a GlFakeQueries
- EXPECT_CALL(*gl_, GenQueries(_, NotNull())).Times(AtLeast(1)).WillOnce(
- Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries));
-
- EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull()))
- .Times(AtLeast(2))
- .WillRepeatedly(
- Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv));
-
- EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP))
- .Times(AtLeast(2))
- .WillRepeatedly(
- Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter));
-
- EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull()))
- .Times(AtLeast(2))
- .WillRepeatedly(
- Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v));
-
- EXPECT_CALL(*gl_, DeleteQueries(2, NotNull()))
- .Times(AtLeast(1))
- .WillRepeatedly(
- Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries));
- }
-
- GlFakeQueries gl_fake_queries_;
-};
-
-TEST_F(GpuTracerTest, GPUTrace) {
- // Test basic timer query functionality
- {
+ void DoTraceTest() {
MockOutputter* outputter = new MockOutputter();
scoped_refptr<Outputter> outputter_ref = outputter;
@@ -180,7 +163,8 @@ TEST_F(GpuTracerTest, GPUTrace) {
Trace(trace_name, expect_start_time, expect_end_time));
scoped_refptr<GPUTrace> trace =
- new GPUTrace(outputter_ref, trace_name, offset_time);
+ new GPUTrace(outputter_ref, trace_name, offset_time,
+ GetTracerType());
gl_fake_queries_.SetCurrentGLTime(start_timestamp);
trace->Start();
@@ -203,6 +187,105 @@ TEST_F(GpuTracerTest, GPUTrace) {
// Proces should output expected Trace results to MockOutputter
trace->Process();
}
+
+ protected:
+ virtual void SetUp() {
+ GpuServiceTest::SetUp();
+ gl_fake_queries_.Reset();
+ }
+
+ virtual void TearDown() {
+ gl_.reset();
+ gl_fake_queries_.Reset();
+ GpuServiceTest::TearDown();
+ }
+
+ virtual void SetupTimerQueryMocks() = 0;
+
+ virtual GpuTracerType GetTracerType() = 0;
+
+ GlFakeQueries gl_fake_queries_;
+};
+
+class GpuARBTimerTracerTest : public BaseGpuTracerTest {
+ protected:
+ virtual void SetupTimerQueryMocks() OVERRIDE {
+ // Delegate query APIs used by GPUTrace to a GlFakeQueries
+ EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(AtLeast(1)).WillOnce(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB));
+
+ EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull()))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv));
+
+ EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter));
+
+ EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull()))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v));
+
+ EXPECT_CALL(*gl_, DeleteQueriesARB(2, NotNull()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueriesARB));
+ }
+
+ virtual GpuTracerType GetTracerType() OVERRIDE {
+ return kTracerTypeARBTimer;
+ }
+};
+
+class GpuDisjointTimerTracerTest : public BaseGpuTracerTest {
+ protected:
+ virtual void SetupTimerQueryMocks() OVERRIDE {
+ // Delegate query APIs used by GPUTrace to a GlFakeQueries
+ EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(AtLeast(1)).WillOnce(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB));
+
+ EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE_EXT,
+ NotNull()))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB));
+
+ EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP_EXT))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter));
+
+ EXPECT_CALL(*gl_, GetQueryObjectui64vEXT(_, GL_QUERY_RESULT_EXT, NotNull()))
+ .Times(AtLeast(2))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64vEXT));
+
+ EXPECT_CALL(*gl_, DeleteQueriesARB(2, NotNull()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(
+ Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueriesARB));
+ }
+
+ virtual GpuTracerType GetTracerType() OVERRIDE {
+ return kTracerTypeDisjointTimer;
+ }
+};
+
+TEST_F(GpuARBTimerTracerTest, GPUTrace) {
+ // Test basic timer query functionality
+ {
+ DoTraceTest();
+ }
+}
+
+TEST_F(GpuDisjointTimerTracerTest, GPUTrace) {
+ // Test basic timer query functionality
+ {
+ DoTraceTest();
+ }
}
} // namespace gles2

Powered by Google App Engine
This is Rietveld 408576698