2 * Copyright (c) 2013 Timothy Arceri <t_arceri@yahoo.com.au>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include "piglit-util-gl.h"
27 static const char *TestMessage1
= "Piglit Message 1";
28 static const char *TestMessage2
= "Piglit Message 2";
29 static const char *TestMessage3
= "Piglit Message 3";
30 static const char *TestMessage4
= "Piglit Message 4";
32 static const int MessageId1
= 101;
33 static const int MessageId2
= 202;
34 static const int MessageId3
= 303;
35 static const int MessageId4
= 404;
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 #ifdef PIGLIT_USE_OPENGL
40 config
.supports_gl_compat_version
= 11;
41 config
.require_debug_context
= true;
42 #else /* using GLES */
43 config
.supports_gl_es_version
= 20;
46 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
47 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
49 PIGLIT_GL_TEST_CONFIG_END
51 #ifdef PIGLIT_USE_OPENGL
53 #else /* using GLES */
54 #define GET_FUNC(x) x ## KHR
57 static PFNGLGETDEBUGMESSAGELOGPROC GetDebugMessageLog
;
58 static PFNGLDEBUGMESSAGEINSERTPROC DebugMessageInsert
;
59 static PFNGLDEBUGMESSAGECONTROLPROC DebugMessageControl
;
60 static PFNGLPUSHDEBUGGROUPPROC PushDebugGroup
;
61 static PFNGLPOPDEBUGGROUPPROC PopDebugGroup
;
63 static GLboolean
fetch_one_log_message()
67 !!GetDebugMessageLog(1, 4096, NULL
, NULL
, NULL
, NULL
, NULL
, log
);
70 printf("Log: %s\n", log
);
75 static bool check_inheritance_messages(int expectedCount
, GLuint
* expectedIds
)
78 #define MAX_MESSAGES 5
82 GLuint ids
[MAX_MESSAGES
];
83 GLchar messageLog
[BUF_SIZE
];
85 count
= GetDebugMessageLog(MAX_MESSAGES
,
94 if (count
!= expectedCount
) {
95 fprintf(stderr
, "Expected message count: %i Actual message count: %i\n",
96 expectedCount
, count
);
99 for (i
= 0; i
< expectedCount
; i
++) {
100 if (expectedIds
[i
] != ids
[i
]) {
101 fprintf(stderr
, "Expected id: %i Actual id: %i\n",
102 expectedIds
[i
], ids
[i
]);
111 static void insert_inheritance_messages()
113 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId1
,
114 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage1
);
116 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId2
,
117 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage2
);
119 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId3
,
120 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage3
);
122 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId4
,
123 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage4
);
127 * Test inheritance of group filtering (nesting)
129 static bool test_push_pop_group_inheritance()
132 GLuint allowedIds1
[] = {MessageId1
};
133 GLuint allowedIds2
[] = {MessageId2
};
134 GLuint allowedIds3
[] = {MessageId3
};
136 GLuint expectedIds1
[] = {MessageId1
};
137 GLuint expectedIds2
[] = {MessageId1
, MessageId2
};
138 GLuint expectedIds3
[] = {MessageId1
, MessageId2
, MessageId3
};
140 puts("Testing Push debug group inheritance");
142 /* Setup of the default active debug group: Filter everything out */
143 DebugMessageControl(GL_DONT_CARE
, GL_DONT_CARE
,
144 GL_DONT_CARE
, 0, NULL
, GL_FALSE
);
146 /* Push debug group 1 and allow messages with the id 101*/
147 PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION
, 1, -1, "Push_Pop 1");
148 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
,
149 GL_DONT_CARE
, 1, allowedIds1
, GL_TRUE
);
150 insert_inheritance_messages();
151 pass
= check_inheritance_messages(1, expectedIds1
);
153 /* Push debug group 1 and allow messages with the id 101 and 202*/
154 PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION
, 1, -1, "Push_Pop 2");
155 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
,
156 GL_DONT_CARE
, 1, allowedIds2
, GL_TRUE
);
157 insert_inheritance_messages();
158 pass
= check_inheritance_messages(2, expectedIds2
) && pass
;
160 /* Push debug group 1 and allow messages with the id 101, 202 and 303*/
161 PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION
, 1, -1, "Push_Pop 3");
162 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
,
163 GL_DONT_CARE
, 1, allowedIds3
, GL_TRUE
);
164 insert_inheritance_messages();
165 pass
= check_inheritance_messages(3, expectedIds3
) && pass
;
167 puts("Testing Pop debug group inheritance");
169 /* Pop debug group 3 */
171 insert_inheritance_messages();
172 pass
= check_inheritance_messages(2, expectedIds2
) && pass
;
174 /* Pop debug group 2 */
176 insert_inheritance_messages();
177 pass
= check_inheritance_messages(1, expectedIds1
) && pass
;
179 /* Pop group 1, restore the volume control of the default debug group. */
181 insert_inheritance_messages();
182 /* check message log is empty, all messages should have been filtered */
183 if (fetch_one_log_message()) {
184 fprintf(stderr
, "The message log should be empty\n");
192 * Test Push/Pop Debug Group
194 static bool test_push_pop_debug_group()
197 #define MAX_MESSAGES 5
198 #define BUF_SIZE 1280
199 int i
, nextMessage
= 0;
202 GLint maxMessageLength
;
203 GLint maxMessageLogLength
;
205 GLsizei lengths
[MAX_MESSAGES
];
206 GLchar messageLog
[BUF_SIZE
];
208 /* Make sure the implementation has max values big enough to run this test
209 * since the spec only mandates GL_MAX_DEBUG_MESSAGE_LENGTH and
210 * GL_MAX_DEBUG_LOGGED_MESSAGES to be 1 or larger.
212 glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH
, &maxMessageLength
);
213 glGetIntegerv(GL_MAX_DEBUG_LOGGED_MESSAGES
, &maxMessageLogLength
);
214 /* assume all test messages are of the same length */
215 messageLen
= strlen(TestMessage1
);
216 /* MAX_DEBUG_MESSAGE_LENGTH must be greater than messageLen as it includes the null terminator */
217 if (maxMessageLength
<= messageLen
) {
218 printf("push_pop_debug_group test skipped implementations MAX_DEBUG_MESSAGE_LENGTH=%i and max piglit test length=%i\n", maxMessageLength
, messageLen
);
221 if (maxMessageLogLength
< MAX_MESSAGES
) {
222 printf("push_pop_debug_group test skipped implementations MAX_DEBUG_LOGGED_MESSAGES=%i and max piglit test length=%i\n", maxMessageLogLength
, MAX_MESSAGES
);
226 puts("Testing Push Pop debug message group");
228 /* Setup of the default active debug group, only enabling
229 * the messages we will be interested in.
231 DebugMessageControl(GL_DONT_CARE
, GL_DONT_CARE
,
232 GL_DONT_CARE
, 0, NULL
, GL_FALSE
);
233 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_PUSH_GROUP
,
234 GL_DEBUG_SEVERITY_NOTIFICATION
, 0, NULL
, GL_TRUE
);
235 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_POP_GROUP
,
236 GL_DEBUG_SEVERITY_NOTIFICATION
, 0, NULL
, GL_TRUE
);
237 DebugMessageControl(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
,
238 GL_DEBUG_SEVERITY_NOTIFICATION
, 0, NULL
, GL_TRUE
);
240 /* Generate a debug marker debug output message */
241 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId1
,
242 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage1
);
244 /* Push debug group 1 */
245 PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION
, 1, -1, TestMessage2
);
247 /* Setup of the debug group 1: Filter everything out */
248 DebugMessageControl(GL_DONT_CARE
, GL_DONT_CARE
, GL_DONT_CARE
,
251 /* This message shouldn't appear in the debug output log */
252 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId1
,
253 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage3
);
255 /* Pop group 1, restore the volume control of the default debug group. */
258 /* Generate a debug marker debug output message */
259 DebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_MARKER
, MessageId1
,
260 GL_DEBUG_SEVERITY_NOTIFICATION
, -1, TestMessage4
);
262 /* Check that message log has done correct filtering */
263 count
= GetDebugMessageLog(MAX_MESSAGES
,
273 fprintf(stderr
, "The message log should contain 4 messages not %i messages\n", count
);
275 for (i
= 0; i
< count
; i
++) {
276 fprintf(stderr
, "%s\n", messageLog
+nextMessage
);
277 nextMessage
+= lengths
[i
];
283 /* the third message should contain TestMessage2 from PopDebugGroup() */
284 nextMessage
= lengths
[0] + lengths
[1];
285 if (strstr(messageLog
+nextMessage
, TestMessage2
) == NULL
) {
286 fprintf(stderr
, "Expected: %s Message: %s\n", TestMessage2
, messageLog
+nextMessage
);
290 /* double check that TestMessage3 didn't sneak into the log */
292 for (i
= 0; i
< count
; i
++) {
293 if (strstr(messageLog
+nextMessage
, TestMessage3
) != NULL
) {
294 fprintf(stderr
, "The log should not contain the message: %s",
295 messageLog
+nextMessage
);
298 nextMessage
+= lengths
[i
];
301 /* the forth message should contain TestMessage4 */
302 nextMessage
= lengths
[0] + lengths
[1] + lengths
[2];
303 if (strstr(messageLog
+nextMessage
, TestMessage4
) == NULL
) {
304 fprintf(stderr
, "Expected: %s Message: %s\n", TestMessage4
, messageLog
+nextMessage
);
312 void piglit_init(int argc
, char **argv
)
316 GetDebugMessageLog
= GET_FUNC(glGetDebugMessageLog
);
317 DebugMessageInsert
= GET_FUNC(glDebugMessageInsert
);
318 DebugMessageControl
= GET_FUNC(glDebugMessageControl
);
319 PushDebugGroup
= GET_FUNC(glPushDebugGroup
);
320 PopDebugGroup
= GET_FUNC(glPopDebugGroup
);
322 piglit_require_extension("GL_KHR_debug");
324 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS
);
325 glEnable(GL_DEBUG_OUTPUT
);
327 if (!piglit_check_gl_error(GL_NO_ERROR
))
328 piglit_report_result(PIGLIT_FAIL
);
330 /* clear_message_log */
331 while(fetch_one_log_message())
334 /* test message control and debug groups */
335 pass
= test_push_pop_debug_group();
336 pass
= test_push_pop_group_inheritance() && pass
;
338 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);