xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fInfoLogQueryShared.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.1 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 Info log query shared utilities
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es31fInfoLogQueryShared.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "tcuTestLog.hpp"
27 #include "glwEnums.hpp"
28 #include "gluStrUtil.hpp"
29 
30 #include <string>
31 
32 namespace deqp
33 {
34 namespace gles31
35 {
36 namespace Functional
37 {
38 
verifyInfoLogQuery(tcu::ResultCollector & result,glu::CallLogWrapper & gl,int logLen,glw::GLuint object,void (glu::CallLogWrapper::* getInfoLog)(glw::GLuint,glw::GLsizei,glw::GLsizei *,glw::GLchar *),const char * getterName)39 void verifyInfoLogQuery(tcu::ResultCollector &result, glu::CallLogWrapper &gl, int logLen, glw::GLuint object,
40                         void (glu::CallLogWrapper::*getInfoLog)(glw::GLuint, glw::GLsizei, glw::GLsizei *,
41                                                                 glw::GLchar *),
42                         const char *getterName)
43 {
44     {
45         const tcu::ScopedLogSection section(gl.getLog(), "QueryAll", "Query all");
46         std::string buf(logLen + 2, 'X');
47 
48         buf[logLen + 1] = '\0';
49         (gl.*getInfoLog)(object, logLen, DE_NULL, &buf[0]);
50         GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
51 
52         if (logLen > 0 && buf[logLen - 1] != '\0')
53             result.fail("Return buffer was not INFO_LOG_LENGTH sized and null-terminated");
54         else if (buf[logLen] != 'X' && buf[logLen + 1] != '\0')
55             result.fail("Buffer end guard modified, query wrote over the end of the buffer.");
56     }
57 
58     {
59         const tcu::ScopedLogSection section(gl.getLog(), "QueryMore", "Query more");
60         std::string buf(logLen + 4, 'X');
61         int written = -1;
62 
63         buf[logLen + 3] = '\0';
64         (gl.*getInfoLog)(object, logLen + 2, &written, &buf[0]);
65         GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
66 
67         if (written == -1)
68             result.fail("'length' was not written to");
69         else if (buf[written] != '\0')
70             result.fail("Either length was incorrect or result was not null-terminated");
71         else if (logLen != 0 && (written + 1) > logLen)
72             result.fail("'length' characters + null terminator is larger than INFO_LOG_LENGTH");
73         else if ((written + 1) < logLen)
74             result.fail("'length' is not consistent with INFO_LOG_LENGTH");
75         else if (buf[logLen + 2] != 'X' && buf[logLen + 3] != '\0')
76             result.fail("Buffer end guard modified, query wrote over the end of the buffer.");
77         else if (written != (int)strlen(&buf[0]))
78             result.fail("'length' and written string length do not match");
79     }
80 
81     if (logLen > 2)
82     {
83         const tcu::ScopedLogSection section(gl.getLog(), "QueryLess", "Query less");
84         std::string buf(logLen + 2, 'X');
85         int written = -1;
86 
87         (gl.*getInfoLog)(object, 2, &written, &buf[0]);
88         GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
89 
90         if (written == -1)
91             result.fail("'length' was not written to");
92         else if (written != 1)
93             result.fail("Expected 'length' = 1");
94         else if (buf[1] != '\0')
95             result.fail("Expected null terminator at index 1");
96     }
97 
98     if (logLen > 0)
99     {
100         const tcu::ScopedLogSection section(gl.getLog(), "QueryOne", "Query one character");
101         std::string buf(logLen + 2, 'X');
102         int written = -1;
103 
104         (gl.*getInfoLog)(object, 1, &written, &buf[0]);
105         GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
106 
107         if (written == -1)
108             result.fail("'length' was not written to");
109         else if (written != 0)
110             result.fail("Expected 'length' = 0");
111         else if (buf[0] != '\0')
112             result.fail("Expected null terminator at index 0");
113     }
114 
115     {
116         const tcu::ScopedLogSection section(gl.getLog(), "QueryNone", "Query to zero-sized buffer");
117         std::string buf(logLen + 2, 'X');
118         int written = -1;
119 
120         (gl.*getInfoLog)(object, 0, &written, &buf[0]);
121         GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
122 
123         if (written == -1)
124             result.fail("'length' was not written to");
125         else if (written != 0)
126             result.fail("Expected 'length' = 0");
127         else if (buf[0] != 'X')
128             result.fail("Unexpected buffer mutation at index 0");
129     }
130 }
131 
132 } // namespace Functional
133 } // namespace gles31
134 } // namespace deqp
135