[Piglit] [PATCH 03/11] egl_khr_create_context: Add common test infrastructure

Ian Romanick idr at freedesktop.org
Wed Aug 1 10:15:22 PDT 2012


On 07/31/2012 06:38 PM, Matt Turner wrote:
> ---
>   tests/all_egl.tests                                |    3 +
>   tests/egl/CMakeLists.gl.txt                        |    2 +
>   tests/egl/spec/CMakeLists.txt                      |    1 +
>   .../spec/egl_khr_create_context/CMakeLists.gl.txt  |   14 ++
>   .../egl/spec/egl_khr_create_context/CMakeLists.txt |    1 +
>   tests/egl/spec/egl_khr_create_context/common.c     |  149 ++++++++++++++++++++
>   tests/egl/spec/egl_khr_create_context/common.h     |   34 +++++
>   7 files changed, 204 insertions(+), 0 deletions(-)
>   create mode 100644 tests/egl/spec/CMakeLists.txt
>   create mode 100644 tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
>   create mode 100644 tests/egl/spec/egl_khr_create_context/CMakeLists.txt
>   create mode 100644 tests/egl/spec/egl_khr_create_context/common.c
>   create mode 100644 tests/egl/spec/egl_khr_create_context/common.h
>
> diff --git a/tests/all_egl.tests b/tests/all_egl.tests
> index c2d097a..93faef6 100644
> --- a/tests/all_egl.tests
> +++ b/tests/all_egl.tests
> @@ -17,3 +17,6 @@ egl['egl-query-surface-EGL_BAD_ATTRIBUTE'] = plain_test('egl-query-surface --bad
>   egl['egl-query-surface-EGL_BAD_SURFACE'] = plain_test('egl-query-surface --bad-surface')
>   egl['egl-query-surface-EGL_HEIGHT'] = plain_test('egl-query-surface --attr=EGL_HEIGHT')
>   egl['egl-query-surface-EGL_WIDTH'] = plain_test('egl-query-surface --attr=EGL_WIDTH')
> +
> +create_context = Group();
> +egl['EGL_KHR_create_context'] = create_context
> diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt
> index fb73248..03b2ae0 100644
> --- a/tests/egl/CMakeLists.gl.txt
> +++ b/tests/egl/CMakeLists.gl.txt
> @@ -20,6 +20,8 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>   	target_link_libraries(egl-create-surface pthread ${X11_X11_LIB})
>   	piglit_add_executable (egl-query-surface egl-util.c egl-query-surface.c)
>   	target_link_libraries(egl-query-surface pthread ${X11_X11_LIB})
> +
> +	add_subdirectory(spec)
>   ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>
>   # vim: ft=cmake:
> diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
> new file mode 100644
> index 0000000..de4de3f
> --- /dev/null
> +++ b/tests/egl/spec/CMakeLists.txt
> @@ -0,0 +1 @@
> +add_subdirectory (egl_khr_create_context)
> diff --git a/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt b/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..a25f747
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_create_context/CMakeLists.gl.txt
> @@ -0,0 +1,14 @@
> +
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +	${GLPROTO_INCLUDE_DIRS}
> +)
> +
> +link_libraries (
> +	${OPENGL_gl_LIBRARY}
> +	${OPENGL_glu_LIBRARY}
> +	${X11_X11_LIB}
> +)
> +
> +# vim: ft=cmake:
> diff --git a/tests/egl/spec/egl_khr_create_context/CMakeLists.txt b/tests/egl/spec/egl_khr_create_context/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_create_context/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/egl/spec/egl_khr_create_context/common.c b/tests/egl/spec/egl_khr_create_context/common.c
> new file mode 100644
> index 0000000..a4022d3
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_create_context/common.c
> @@ -0,0 +1,149 @@
> +/* Copyright © 2012 Intel Corporation
> + *
> + * 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.
> + */
> +
> +#include <ctype.h>
> +#include <errno.h>
> +#include "common.h"
> +
> +static Display *dpy = NULL;
> +EGLDisplay egl_dpy;
> +EGLConfig cfg;
> +EGLContext ctx;
> +
> +bool
> +parse_version_string(const char *string, int *major, int *minor)
> +{
> +	char *next;
> +	int ma;
> +	int mi;
> +
> +	if (string == NULL)
> +		return false;
> +
> +	next = (char *)string;
> +	while (!isdigit(*next) && *next != '\0')
> +		next++;
> +
> +	if (next[0] == '\0')
> +		return false;
> +
> +	errno = 0;
> +	ma = strtol(next, &next, 10);
> +	if (next == NULL || errno != 0)
> +		return false;
> +
> +	while (!isdigit(*next) && *next != '\0')
> +		next++;
> +
> +	if (next[0] == '\0')
> +		return false;
> +
> +	mi = strtol(next, &next, 10);
> +	if (errno != 0)
> +		return false;
> +
> +	*major = ma;
> +	*minor = mi;
> +	return true;
> +}
> +
> +static void
> +check_extensions(void)
> +{
> +	static const char *extensions[] = {
> +		"EGL_KHR_create_context",
> +#ifdef USE_OPENGL
> +		"EGL_KHR_surfaceless_opengl",
> +#endif
> +#ifdef USE_OPENGL_ES1
> +		"EGL_KHR_surfaceless_gles1",
> +#endif
> +#ifdef USE_OPENGL_ES2
> +		"EGL_KHR_surfaceless_gles2",
> +#endif

Even though Mesa advertises these extensions, they *DO NOT* exist. 
We've been scolded by Khronos for this.  They're going to disappear from 
Mesa very soon, so do not use these.

Ugly as it is, make a 1x1 pixmap instead. :(

> +	};
> +	int i;
> +
> +	const char *extension_string = eglQueryString(egl_dpy, EGL_EXTENSIONS);
> +	for (i = 0; ARRAY_SIZE(extensions); i++) {
> +		if (!strstr(extension_string, extensions[i])) {
> +			fprintf(stderr, "missing extension %s\n",
> +				extensions[i]);
> +			piglit_report_result(PIGLIT_SKIP);
> +		}
> +	}
> +}
> +
> +void
> +EGL_KHR_create_context_setup(void)
> +{
> +	static const EGLint config_attribs[] = {
> +		EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT,
> +		EGL_RED_SIZE, 1,
> +		EGL_GREEN_SIZE, 1,
> +		EGL_BLUE_SIZE, 1,
> +		EGL_DEPTH_SIZE, 1,
> +#ifdef USE_OPENGL
> +		EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
> +#endif
> +#ifdef USE_OPENGL_ES1
> +		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
> +#endif
> +#ifdef USE_OPENGL_ES2
> +		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
> +#endif

It seems like this should be a parameter of the function.

> +		EGL_NONE
> +	};
> +	EGLint count;
> +	EGLint major, minor;
> +
> +	dpy = XOpenDisplay(NULL);
> +	if (dpy == NULL) {
> +		fprintf(stderr, "couldn't open display\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	egl_dpy = eglGetDisplay(dpy);
> +	if (egl_dpy == EGL_NO_DISPLAY) {
> +		fprintf(stderr, "eglGetDisplay() failed\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	if (!eglInitialize(egl_dpy, &major, &minor)) {
> +		fprintf(stderr, "eglInitialize() failed\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	if (!eglChooseConfig(egl_dpy, config_attribs, &cfg, 1, &count) ||
> +	    count == 0) {
> +		fprintf(stderr, "eglChooseConfig() failed\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	check_extensions();
> +}
> +
> +void
> +EGL_KHR_create_context_teardown(void)
> +{
> +	eglTerminate(egl_dpy);
> +}
> diff --git a/tests/egl/spec/egl_khr_create_context/common.h b/tests/egl/spec/egl_khr_create_context/common.h
> new file mode 100644
> index 0000000..7455a75
> --- /dev/null
> +++ b/tests/egl/spec/egl_khr_create_context/common.h
> @@ -0,0 +1,34 @@
> +/* Copyright © 2012 Intel Corporation
> + *
> + * 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.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +#include <X11/Xlib.h>
> +#include <EGL/egl.h>
> +#include <EGL/eglext.h>
> +
> +extern EGLDisplay egl_dpy;
> +extern EGLConfig cfg;
> +extern EGLContext ctx;
> +
> +extern bool parse_version_string(const char *string, int *major, int *minor);
> +extern void EGL_KHR_create_context_setup(void);
> +extern void EGL_KHR_create_context_teardown(void);
>


More information about the Piglit mailing list