xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fDebugMarkerTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 2.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2015 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 GL_EXT_debug_marker tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2fDebugMarkerTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluRenderContext.hpp"
27 #include "glwFunctions.hpp"
28 #include "glwEnums.hpp"
29 #include "tcuTestLog.hpp"
30 #include "deRandom.hpp"
31 #include "deUniquePtr.hpp"
32 
33 namespace deqp
34 {
35 namespace gles2
36 {
37 namespace Functional
38 {
39 
40 namespace
41 {
42 
43 using std::vector;
44 using tcu::TestLog;
45 
checkSupport(const glu::ContextInfo & ctxInfo)46 void checkSupport(const glu::ContextInfo &ctxInfo)
47 {
48     if (!ctxInfo.isExtensionSupported("GL_EXT_debug_marker"))
49     {
50 #if (DE_OS == DE_OS_ANDROID)
51         TCU_THROW(TestError, "Support for GL_EXT_debug_marker is mandatory on Android");
52 #else
53         TCU_THROW(NotSupportedError, "GL_EXT_debug_marker is not supported");
54 #endif
55     }
56     // else no exception thrown
57 }
58 
59 class IsSupportedCase : public TestCase
60 {
61 public:
IsSupportedCase(Context & context)62     IsSupportedCase(Context &context) : TestCase(context, "supported", "Is GL_EXT_debug_marker supported")
63     {
64     }
65 
iterate(void)66     IterateResult iterate(void)
67     {
68         checkSupport(m_context.getContextInfo());
69         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "GL_EXT_debug_marker is supported");
70         return STOP;
71     }
72 };
73 
getSimpleRndString(vector<char> & dst,de::Random & rnd,int maxLen)74 void getSimpleRndString(vector<char> &dst, de::Random &rnd, int maxLen)
75 {
76     const char s_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -_";
77 
78     dst.resize(rnd.getInt(0, (int)maxLen));
79 
80     for (size_t ndx = 0; ndx < dst.size(); ndx++)
81         dst[ndx] = rnd.choose<char>(DE_ARRAY_BEGIN(s_chars), DE_ARRAY_END(s_chars));
82 }
83 
getComplexRndString(vector<char> & dst,de::Random & rnd,int maxLen)84 void getComplexRndString(vector<char> &dst, de::Random &rnd, int maxLen)
85 {
86     dst.resize(rnd.getInt(0, (int)maxLen));
87 
88     for (size_t ndx = 0; ndx < dst.size(); ndx++)
89         dst[ndx] = (char)rnd.getUint8();
90 }
91 
92 enum CallType
93 {
94     CALL_TYPE_PUSH_GROUP = 0,
95     CALL_TYPE_POP_GROUP,
96     CALL_TYPE_INSERT_MARKER,
97 
98     CALL_TYPE_LAST
99 };
100 
101 class RandomCase : public TestCase
102 {
103 public:
RandomCase(Context & context)104     RandomCase(Context &context) : TestCase(context, "random", "Random GL_EXT_debug_marker usage")
105     {
106     }
107 
init(void)108     void init(void)
109     {
110         checkSupport(m_context.getContextInfo());
111     }
112 
iterate(void)113     IterateResult iterate(void)
114     {
115         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
116         const int numIters       = 1000;
117         const int maxMsgLen      = 4096;
118         de::Random rnd(0xaf829c0);
119 
120         for (int iterNdx = 0; iterNdx < numIters; iterNdx++)
121         {
122             const CallType callType = CallType(rnd.getInt(0, CALL_TYPE_LAST - 1));
123 
124             if (callType == CALL_TYPE_PUSH_GROUP || callType == CALL_TYPE_INSERT_MARKER)
125             {
126                 const bool nullTerminate = rnd.getBool();
127                 const bool passLength    = rnd.getBool();
128                 const bool complexMsg    = rnd.getBool();
129                 vector<char> message;
130 
131                 if (complexMsg)
132                     getComplexRndString(message, rnd, maxMsgLen);
133                 else
134                     getSimpleRndString(message, rnd, maxMsgLen);
135 
136                 if (nullTerminate)
137                     message.push_back(char(0));
138 
139                 {
140                     const glw::GLsizei length =
141                         passLength ? glw::GLsizei(nullTerminate ? message.size() - 1 : message.size()) : 0;
142 
143                     if (callType == CALL_TYPE_PUSH_GROUP)
144                         gl.pushGroupMarkerEXT(length, &message[0]);
145                     else
146                         gl.insertEventMarkerEXT(length, &message[0]);
147                 }
148             }
149             else
150                 gl.popGroupMarkerEXT();
151         }
152 
153         GLU_EXPECT_NO_ERROR(gl.getError(), "Debug marker calls must not set error state");
154 
155         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "All calls passed");
156         return STOP;
157     }
158 };
159 
160 class InvalidCase : public TestCase
161 {
162 public:
InvalidCase(Context & context)163     InvalidCase(Context &context) : TestCase(context, "invalid", "Invalid GL_EXT_debug_marker usage")
164     {
165     }
166 
init(void)167     void init(void)
168     {
169         checkSupport(m_context.getContextInfo());
170     }
171 
iterate(void)172     IterateResult iterate(void)
173     {
174         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
175 
176         m_testCtx.getLog()
177             << TestLog::Message
178             << "Note: GL_EXT_debug_marker calls must not report an error even if invalid arguments are supplied."
179             << TestLog::EndMessage;
180 
181         gl.pushGroupMarkerEXT(-1, "foo");
182         gl.insertEventMarkerEXT(-1, "foo");
183         gl.pushGroupMarkerEXT(0, DE_NULL);
184         gl.insertEventMarkerEXT(0, DE_NULL);
185         gl.pushGroupMarkerEXT(-1, DE_NULL);
186         gl.insertEventMarkerEXT(-1, DE_NULL);
187 
188         GLU_EXPECT_NO_ERROR(gl.getError(), "Debug marker calls must not set error state");
189 
190         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "All calls passed");
191         return STOP;
192     }
193 };
194 
195 } // namespace
196 
createDebugMarkerTests(Context & context)197 tcu::TestCaseGroup *createDebugMarkerTests(Context &context)
198 {
199     de::MovePtr<tcu::TestCaseGroup> debugMarkerGroup(
200         new tcu::TestCaseGroup(context.getTestContext(), "debug_marker", "GL_EXT_debug_marker tests"));
201 
202     debugMarkerGroup->addChild(new IsSupportedCase(context));
203     debugMarkerGroup->addChild(new RandomCase(context));
204     debugMarkerGroup->addChild(new InvalidCase(context));
205 
206     return debugMarkerGroup.release();
207 }
208 
209 } // namespace Functional
210 } // namespace gles2
211 } // namespace deqp
212