1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Buffer Object Query tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "es2fBufferObjectQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es2fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 #include "deRandom.hpp"
31 #include "deMath.h"
32
33 #include <limits>
34
35 using namespace glw; // GLint and other GL types
36 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
37
38 namespace deqp
39 {
40 namespace gles2
41 {
42 namespace Functional
43 {
44 namespace BufferParamVerifiers
45 {
46
checkIntEquals(tcu::TestContext & testCtx,GLint got,GLint expected)47 void checkIntEquals(tcu::TestContext &testCtx, GLint got, GLint expected)
48 {
49 using tcu::TestLog;
50
51 if (got != expected)
52 {
53 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got
54 << TestLog::EndMessage;
55 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
56 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
57 }
58 }
59
checkPointerEquals(tcu::TestContext & testCtx,const void * got,const void * expected)60 void checkPointerEquals(tcu::TestContext &testCtx, const void *got, const void *expected)
61 {
62 using tcu::TestLog;
63
64 if (got != expected)
65 {
66 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got
67 << TestLog::EndMessage;
68 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
69 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
70 }
71 }
72
73 class BufferParamVerifier : protected glu::CallLogWrapper
74 {
75 public:
76 BufferParamVerifier(const glw::Functions &gl, tcu::TestLog &log, const char *testNamePostfix);
77 virtual ~BufferParamVerifier(); // make GCC happy
78
79 const char *getTestNamePostfix(void) const;
80
81 virtual void verifyInteger(tcu::TestContext &testCtx, GLenum target, GLenum name, GLint reference) = DE_NULL;
82
83 private:
84 const char *const m_testNamePostfix;
85 };
86
BufferParamVerifier(const glw::Functions & gl,tcu::TestLog & log,const char * testNamePostfix)87 BufferParamVerifier::BufferParamVerifier(const glw::Functions &gl, tcu::TestLog &log, const char *testNamePostfix)
88 : glu::CallLogWrapper(gl, log)
89 , m_testNamePostfix(testNamePostfix)
90 {
91 enableLogging(true);
92 }
93
~BufferParamVerifier()94 BufferParamVerifier::~BufferParamVerifier()
95 {
96 }
97
getTestNamePostfix(void) const98 const char *BufferParamVerifier::getTestNamePostfix(void) const
99 {
100 return m_testNamePostfix;
101 }
102
103 class GetBufferParameterIVerifier : public BufferParamVerifier
104 {
105 public:
106 GetBufferParameterIVerifier(const glw::Functions &gl, tcu::TestLog &log);
107
108 void verifyInteger(tcu::TestContext &testCtx, GLenum target, GLenum name, GLint reference);
109 };
110
GetBufferParameterIVerifier(const glw::Functions & gl,tcu::TestLog & log)111 GetBufferParameterIVerifier::GetBufferParameterIVerifier(const glw::Functions &gl, tcu::TestLog &log)
112 : BufferParamVerifier(gl, log, "_getbufferparameteri")
113 {
114 }
115
verifyInteger(tcu::TestContext & testCtx,GLenum target,GLenum name,GLint reference)116 void GetBufferParameterIVerifier::verifyInteger(tcu::TestContext &testCtx, GLenum target, GLenum name, GLint reference)
117 {
118 using tcu::TestLog;
119
120 StateQueryMemoryWriteGuard<GLint> state;
121 glGetBufferParameteriv(target, name, &state);
122
123 if (!state.verifyValidity(testCtx))
124 return;
125
126 if (state != reference)
127 {
128 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state
129 << TestLog::EndMessage;
130
131 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
132 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
133 }
134 }
135
136 } // namespace BufferParamVerifiers
137
138 namespace
139 {
140
141 using namespace BufferParamVerifiers;
142
143 // Tests
144
145 class BufferCase : public ApiCase
146 {
147 public:
BufferCase(Context & context,BufferParamVerifier * verifier,const char * name,const char * description)148 BufferCase(Context &context, BufferParamVerifier *verifier, const char *name, const char *description)
149 : ApiCase(context, name, description)
150 , m_bufferTarget(0)
151 , m_verifier(verifier)
152 {
153 }
154
155 virtual void testBuffer(void) = DE_NULL;
156
test(void)157 void test(void)
158 {
159 const GLenum bufferTargets[] = {GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER};
160 const int targets = DE_LENGTH_OF_ARRAY(bufferTargets);
161
162 for (int ndx = 0; ndx < targets; ++ndx)
163 {
164 m_bufferTarget = bufferTargets[ndx];
165
166 GLuint bufferId = 0;
167 glGenBuffers(1, &bufferId);
168 glBindBuffer(m_bufferTarget, bufferId);
169 expectError(GL_NO_ERROR);
170
171 testBuffer();
172
173 glDeleteBuffers(1, &bufferId);
174 expectError(GL_NO_ERROR);
175 }
176 }
177
178 protected:
179 GLenum m_bufferTarget;
180 BufferParamVerifier *m_verifier;
181 };
182
183 class BufferSizeCase : public BufferCase
184 {
185 public:
BufferSizeCase(Context & context,BufferParamVerifier * verifier,const char * name,const char * description)186 BufferSizeCase(Context &context, BufferParamVerifier *verifier, const char *name, const char *description)
187 : BufferCase(context, verifier, name, description)
188 {
189 }
190
testBuffer(void)191 void testBuffer(void)
192 {
193 const int numIteration = 16;
194 de::Random rnd(0xabcdef);
195
196 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, 0);
197
198 for (int i = 0; i < numIteration; ++i)
199 {
200 const GLint len = rnd.getInt(0, 1024);
201 glBufferData(m_bufferTarget, len, DE_NULL, GL_STREAM_DRAW);
202 expectError(GL_NO_ERROR);
203
204 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, len);
205 expectError(GL_NO_ERROR);
206 }
207 }
208 };
209
210 class BufferUsageCase : public BufferCase
211 {
212 public:
BufferUsageCase(Context & context,BufferParamVerifier * verifier,const char * name,const char * description)213 BufferUsageCase(Context &context, BufferParamVerifier *verifier, const char *name, const char *description)
214 : BufferCase(context, verifier, name, description)
215 {
216 }
217
testBuffer(void)218 void testBuffer(void)
219 {
220 const GLenum usages[] = {GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW};
221
222 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, GL_STATIC_DRAW);
223
224 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(usages); ++ndx)
225 {
226 glBufferData(m_bufferTarget, 16, DE_NULL, usages[ndx]);
227 expectError(GL_NO_ERROR);
228
229 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, usages[ndx]);
230 expectError(GL_NO_ERROR);
231 }
232 }
233 };
234
235 } // namespace
236
237 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \
238 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
239 { \
240 BufferParamVerifier *verifier = (VERIFIERS)[_verifierNdx]; \
241 CODE_BLOCK; \
242 }
243
BufferObjectQueryTests(Context & context)244 BufferObjectQueryTests::BufferObjectQueryTests(Context &context)
245 : TestCaseGroup(context, "buffer_object", "Buffer Object Query tests")
246 , m_verifierInt(DE_NULL)
247 {
248 }
249
~BufferObjectQueryTests(void)250 BufferObjectQueryTests::~BufferObjectQueryTests(void)
251 {
252 deinit();
253 }
254
init(void)255 void BufferObjectQueryTests::init(void)
256 {
257 using namespace BufferParamVerifiers;
258
259 DE_ASSERT(m_verifierInt == DE_NULL);
260
261 m_verifierInt = new GetBufferParameterIVerifier(m_context.getRenderContext().getFunctions(),
262 m_context.getTestContext().getLog());
263 BufferParamVerifier *verifiers[] = {m_verifierInt};
264
265 FOR_EACH_VERIFIER(verifiers,
266 addChild(new BufferSizeCase(m_context, verifier,
267 (std::string("buffer_size") + verifier->getTestNamePostfix()).c_str(),
268 "BUFFER_SIZE")))
269 FOR_EACH_VERIFIER(
270 verifiers, addChild(new BufferUsageCase(m_context, verifier,
271 (std::string("buffer_usage") + verifier->getTestNamePostfix()).c_str(),
272 "BUFFER_USAGE")))
273 }
274
deinit(void)275 void BufferObjectQueryTests::deinit(void)
276 {
277 if (m_verifierInt)
278 {
279 delete m_verifierInt;
280 m_verifierInt = NULL;
281 }
282
283 this->TestCaseGroup::deinit();
284 }
285
286 } // namespace Functional
287 } // namespace gles2
288 } // namespace deqp
289