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