[Piglit] [PATCH] egl-khr-debug: Start adding tests for EGL_KHR_debug

Eric Anholt eric at anholt.net
Tue Sep 13 06:21:19 UTC 2016


Adam Jackson <ajax at redhat.com> writes:

> First test does some basic API error checking, then provokes an error
> against the (implicit) thread object. There is clearly much more to
> cover here, but this at least touches all of the new entrypoints and
> verifies that it errors reasonably when misused.
>
> Signed-off-by: Adam Jackson <ajax at redhat.com>
> ---
>  tests/all.py                                       |   6 +
>  tests/egl/spec/CMakeLists.txt                      |   1 +
>  tests/egl/spec/egl_khr_debug/CMakeLists.no_api.txt |  14 ++
>  tests/egl/spec/egl_khr_debug/CMakeLists.txt        |   1 +
>  tests/egl/spec/egl_khr_debug/common.c              |  44 ++++++
>  tests/egl/spec/egl_khr_debug/egl-khr-debug.h       |  36 +++++
>  tests/egl/spec/egl_khr_debug/thread.c              | 153 +++++++++++++++++++++
>  7 files changed, 255 insertions(+)
>  create mode 100644 tests/egl/spec/egl_khr_debug/CMakeLists.no_api.txt
>  create mode 100644 tests/egl/spec/egl_khr_debug/CMakeLists.txt
>  create mode 100644 tests/egl/spec/egl_khr_debug/common.c
>  create mode 100644 tests/egl/spec/egl_khr_debug/egl-khr-debug.h
>  create mode 100644 tests/egl/spec/egl_khr_debug/thread.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 3961656..5de994f 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -4433,6 +4433,12 @@ with profile.group_manager(
>  
>  with profile.group_manager(
>          PiglitGLTest,
> +        grouptools.join('spec', 'egl_khr_debug'),
> +        exclude_platforms=['glx']) as g:
> +    g(['egl-khr-debug-thread'], 'thread object', run_concurrent=True)
> +
> +with profile.group_manager(
> +        PiglitGLTest,
>          grouptools.join('spec', 'egl_khr_create_context'),
>          exclude_platforms=['glx']) as g:
>      g(['egl-create-context-default-major-version-gles'],
> diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
> index 7206556..9949483 100644
> --- a/tests/egl/spec/CMakeLists.txt
> +++ b/tests/egl/spec/CMakeLists.txt
> @@ -3,6 +3,7 @@ add_subdirectory (egl_ext_client_extensions)
>  add_subdirectory (egl_ext_device_query)
>  add_subdirectory (egl_ext_device_enumeration)
>  add_subdirectory (egl_khr_create_context)
> +add_subdirectory (egl_khr_debug)
>  add_subdirectory (egl_khr_get_all_proc_addresses)
>  add_subdirectory (egl_khr_fence_sync)
>  if (PIGLIT_HAS_X11)
> diff --git a/tests/egl/spec/egl_khr_debug/CMakeLists.no_api.txt b/tests/egl/spec/egl_khr_debug/CMakeLists.no_api.txt
> new file mode 100644
> index 0000000..9a0d710
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_debug/CMakeLists.no_api.txt
> @@ -0,0 +1,14 @@
> +
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +	${GLPROTO_INCLUDE_DIRS}
> +)
> +
> +link_libraries (
> +	piglitutil
> +)
> +
> +piglit_add_executable (egl-khr-debug-thread thread.c common.c)
> +
> +# vim: ft=cmake:
> diff --git a/tests/egl/spec/egl_khr_debug/CMakeLists.txt b/tests/egl/spec/egl_khr_debug/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_debug/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/egl/spec/egl_khr_debug/common.c b/tests/egl/spec/egl_khr_debug/common.c
> new file mode 100644
> index 0000000..a99804a
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_debug/common.c
> @@ -0,0 +1,44 @@
> +/*
> + * Copyright © 2016 Red Hat, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *	Adam Jackson <ajax at redhat.com>
> + */
> +
> +#include "egl-khr-debug.h"
> +
> +PFNEGLDEBUGMESSAGECONTROLKHRPROC debugMessageControl = NULL;
> +PFNEGLQUERYDEBUGKHRPROC queryDebug = NULL;
> +PFNEGLLABELOBJECTKHRPROC labelObject = NULL;
> +
> +void
> +EGL_KHR_debug_init(void)
> +{
> +	piglit_require_egl_extension(EGL_NO_DISPLAY, "EGL_KHR_debug");
> +
> +	debugMessageControl =
> +	    (void *)eglGetProcAddress("eglDebugMessageControlKHR");
> +	queryDebug =
> +	    (void *)eglGetProcAddress("eglQueryDebugKHR");
> +	labelObject =
> +	    (void *)eglGetProcAddress("eglLabelObjectKHR");
> +}
> diff --git a/tests/egl/spec/egl_khr_debug/egl-khr-debug.h b/tests/egl/spec/egl_khr_debug/egl-khr-debug.h
> new file mode 100644
> index 0000000..1d734c9
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_debug/egl-khr-debug.h
> @@ -0,0 +1,36 @@
> +/*
> + * Copyright © 2016 Red Hat, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *	Adam Jackson <ajax at redhat.com>
> + */
> +
> +#include "piglit-util.h"
> +#include "piglit-util-egl.h"
> +
> +#define EGL_BAD_TOKEN 0xdeadc0de
> +
> +extern PFNEGLDEBUGMESSAGECONTROLKHRPROC debugMessageControl;
> +extern PFNEGLQUERYDEBUGKHRPROC queryDebug;
> +extern PFNEGLLABELOBJECTKHRPROC labelObject;
> +
> +extern void EGL_KHR_debug_init(void);
> diff --git a/tests/egl/spec/egl_khr_debug/thread.c b/tests/egl/spec/egl_khr_debug/thread.c
> new file mode 100644
> index 0000000..de76fe7
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_debug/thread.c
> @@ -0,0 +1,153 @@
> +/*
> + * Copyright © 2016 Red Hat, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *	Adam Jackson <ajax at redhat.com>
> + */
> +
> +/*
> + * Basic exercise of EGL error generation, since the thread object is
> + * always present.
> + */
> +
> +#include "egl-khr-debug.h"
> +
> +static int one, two;
> +
> +static void
> +check_egl_error(EGLint expected)
> +{
> +	if (!piglit_check_egl_error(expected))
> +		piglit_report_result(PIGLIT_FAIL);
> +}
> +
> +static void
> +callback(EGLenum error,	const char *cmd, EGLint type, EGLLabelKHR thread,
> +	 EGLLabelKHR object, const char *msg)
> +{
> +	two = 2; /* see if we made it here */
> +
> +	if (error != EGL_BAD_PARAMETER ||
> +	    strcmp(cmd, "eglBindAPI") ||
> +	    type != EGL_DEBUG_MSG_ERROR_KHR ||
> +	    thread != object)
> +		piglit_report_result(PIGLIT_FAIL);
> +}
> +
> +int main(void)
> +{
> +	EGLint i, major, minor;
> +	EGLAttrib value = 0;
> +	const EGLAttrib debug_attrs[] = {
> +	    EGL_DEBUG_MSG_CRITICAL_KHR, EGL_FALSE,
> +	    EGL_DEBUG_MSG_ERROR_KHR, EGL_FALSE,
> +	    EGL_DEBUG_MSG_WARN_KHR, EGL_TRUE,
> +	    EGL_DEBUG_MSG_INFO_KHR, EGL_TRUE,
> +	    EGL_NONE,
> +	};
> +	EGLDisplay dpy;
> +
> +	EGL_KHR_debug_init();
> +
> +	/* Some basic sanity checks */
> +
> +	labelObject(EGL_NO_DISPLAY, EGL_OBJECT_THREAD_KHR, NULL, &one);
> +	check_egl_error(EGL_SUCCESS);

Is one supposed to be used somewhere else?  Is it supposed to have the
value "1" at some point?

> +
> +	queryDebug(EGL_BAD_TOKEN, &value);
> +	check_egl_error(EGL_BAD_ATTRIBUTE);
> +
> +	dpy = piglit_egl_get_default_display(EGL_NONE);
> +	if (dpy == EGL_NO_DISPLAY) {
> +		printf("Failed to get default display\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	eglInitialize(dpy, &major, &minor);
> +	check_egl_error(EGL_SUCCESS);
> +
> +	labelObject(dpy, EGL_BAD_TOKEN, NULL, &one);
> +	check_egl_error(EGL_BAD_PARAMETER);
> +
> +	labelObject(dpy, EGL_OBJECT_THREAD_KHR, NULL, &two);
> +	check_egl_error(EGL_SUCCESS);
> +
> +	queryDebug(EGL_DEBUG_CALLBACK_KHR, &value);
> +	check_egl_error(EGL_SUCCESS);
> +	if ((void *)value != NULL) {
> +		printf("Already have a debug callback?\n");
> +		piglit_report_result(PIGLIT_WARN);
> +	}
> +
> +	debugMessageControl(callback, debug_attrs);
> +	check_egl_error(EGL_SUCCESS);
> +
> +	queryDebug(EGL_DEBUG_CALLBACK_KHR, &value);
> +	check_egl_error(EGL_SUCCESS);
> +	if ((void *)value != &callback) {
> +		printf("Failed to query set callback\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	for (i = 0; i < sizeof(debug_attrs) / sizeof(EGLAttrib); i += 2) {

ARRAY_SIZE would be nicer here.

> +		if (debug_attrs[i] == EGL_NONE)
> +			break;
> +		queryDebug(debug_attrs[i], &value);
> +		check_egl_error(EGL_SUCCESS);
> +		if (value != debug_attrs[i+1]) {
> +			printf("Got bogus value %ld for attribute %lx\n",
> +			       value, debug_attrs[i]);
> +			piglit_report_result(PIGLIT_FAIL);
> +		}
> +	}
> +
> +	/* reset the callback attributes so we get errors */
> +	debugMessageControl(NULL, NULL);
> +	debugMessageControl(callback, NULL);
> +	check_egl_error(EGL_SUCCESS);
> +
> +	/* and try to provoke the callback */
> +	eglBindAPI(EGL_BAD_TOKEN);
> +	check_egl_error(EGL_BAD_PARAMETER);
> +
> +	if (two != 2) {
> +		printf("Callback not called!\n");
> +		piglit_report_result(PIGLIT_WARN);
> +	}
> +
> +	/*
> +	 * TODO: More tests where the thread is the primary object:
> +	 *
> +	 * eglGetDisplay
> +	 * eglGetError
> +	 * eglGetPlatformDisplay
> +	 * eglReleaseThread
> +	 * eglWaitNative
> +	 *
> +	 * It is difficult to reliably provoke an error for some of these.
> +	 * For example, a ReleaseThread implementation could quite
> +	 * plausibly never fail.
> +	 */
> +
> +	piglit_report_result(PIGLIT_PASS);
> +	return 0;
> +}

I think this test would be a lot nicer split into two: One for the basic
API error checks like labelObject(dpy, EGL_BAD_TOKEN, NULL, ptr) and
default message contro state that don't seem to be related to the thread
object, and another for the thread error callback testing.

I'm mostly wondering what "one" is about, though.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20160912/290f29ec/attachment.sig>


More information about the Piglit mailing list