[Piglit] [PATCH] egl: API test for EGL_IMG_context_priority extension

Tapani Pälli tapani.palli at intel.com
Tue Apr 18 11:55:21 UTC 2017



On 04/18/2017 02:25 PM, Chris Wilson wrote:
> On Tue, Apr 18, 2017 at 02:11:57PM +0300, Tapani Pälli wrote:
>> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
>> ---
>>   tests/all.py                     |   1 +
>>   tests/egl/CMakeLists.gl.txt      |   2 +
>>   tests/egl/egl-context-priority.c | 127 +++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 130 insertions(+)
>>   create mode 100644 tests/egl/egl-context-priority.c
>>
>> diff --git a/tests/all.py b/tests/all.py
>> index 9a6c6f9..120d88d 100644
>> --- a/tests/all.py
>> +++ b/tests/all.py
>> @@ -4532,6 +4532,7 @@ with profile.test_list.group_manager(
>>         'largest possible eglCreatePbufferSurface and then glClear',
>>         run_concurrent=False)
>>       g(['egl-invalid-attr'])
>> +    g(['egl-context-priority'])
>>   
>>   with profile.test_list.group_manager(
>>           PiglitGLTest,
>> diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt
>> index 17e04b3..6ba8842 100644
>> --- a/tests/egl/CMakeLists.gl.txt
>> +++ b/tests/egl/CMakeLists.gl.txt
>> @@ -31,6 +31,8 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>>   	target_link_libraries(egl-gl-colorspace pthread ${X11_X11_LIB})
>>   	piglit_add_executable (egl-invalid-attr egl-invalid-attr.c)
>>   	target_link_libraries(egl-invalid-attr pthread)
>> +	piglit_add_executable (egl-context-priority egl-context-priority.c)
>> +	target_link_libraries(egl-context-priority pthread)
>>   ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>>   
>>   # vim: ft=cmake:
>> diff --git a/tests/egl/egl-context-priority.c b/tests/egl/egl-context-priority.c
>> new file mode 100644
>> index 0000000..e8b128a
>> --- /dev/null
>> +++ b/tests/egl/egl-context-priority.c
>> @@ -0,0 +1,127 @@
>> +/*
>> + * Copyright © 2017 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-egl.h"
>> +#include "piglit-util-gl.h"
>> +
>> +/**
>> + * @file egl-context-priority.c
>> + *
>> + * EGL API tests for IMG_context_priority extension
>> + */
>> +
>> +PIGLIT_GL_TEST_CONFIG_BEGIN
>> +
>> +	config.supports_gl_compat_version = 10;
>> +
>> +PIGLIT_GL_TEST_CONFIG_END
>> +
>> +/* dummy */
>> +enum piglit_result
>> +piglit_display(void)
>> +{
>> +	return PIGLIT_FAIL;
>> +}
>> +
>> +static EGLint
>> +check_priority(EGLDisplay dpy, EGLContext ctx, EGLint *expected)
>> +{
>> +	EGLint value;
>> +	EGLBoolean status =
>> +		eglQueryContext(dpy, ctx, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &value);
>> +
>> +	if (status == EGL_FALSE) {
>> +		fprintf(stderr, "eglQueryContext failed\n");
>> +		piglit_report_result(PIGLIT_FAIL);
>> +	}
>> +
>> +	if (expected && value != *expected) {
>> +		fprintf(stderr, "%s fail: value 0x%x, expected 0x%x\n", __func__, value, *expected);
>> +		piglit_report_result(PIGLIT_FAIL);
>> +	}
>> +	return value;
>> +}
>> +
>> +EGLContext
>> +create_context(EGLDisplay dpy, EGLint *attr)
>> +{
>> +	EGLContext ctx =
>> +		eglCreateContext(dpy, EGL_NO_CONFIG_MESA, EGL_NO_CONTEXT, attr);
>> +
>> +	if (ctx == EGL_NO_CONTEXT) {
>> +		fprintf(stderr, "could not create EGL context, attr 0x%x\n", attr[1]);
>> +		piglit_report_result(PIGLIT_FAIL);
>> +	}
>> +	return ctx;
>> +}
>> +
>> +void
>> +piglit_init(int argc, char **argv)
>> +{
>> +	EGLint major, minor;
>> +	EGLDisplay dpy = eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, EGL_DEFAULT_DISPLAY, NULL);
>> +	eglInitialize(dpy, &major, &minor);
>> +
>> +	piglit_require_egl_extension(dpy, "EGL_IMG_context_priority");
>> +	piglit_require_egl_extension(dpy, "EGL_KHR_surfaceless_context");
>> +	piglit_require_egl_extension(dpy, "EGL_MESA_configless_context");
>> +
>> +	EGLint attr[] = { EGL_NONE, EGL_NONE, EGL_NONE };
>> +	EGLContext ctx = create_context(dpy, attr);
>> +
>> +	/* Verify default priority level. */
>> +	EGLint expect = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
>> +	check_priority(dpy, ctx, &expect);
>> +	eglDestroyContext(dpy, ctx);
>> +
>> +	/* Verify that invalid priority level fails. */
>> +	attr[0] = EGL_CONTEXT_PRIORITY_LEVEL_IMG;
>> +	attr[1] = EGL_TRANSPARENT_RED_VALUE;
>> +
>> +	ctx = eglCreateContext(dpy, EGL_NO_CONFIG_MESA, EGL_NO_CONTEXT, attr);
>> +
>> +	if (ctx != EGL_NO_CONTEXT) {
>> +		fprintf(stderr, "should fail with invalid parameter\n");
>> +		piglit_report_result(PIGLIT_FAIL);
>> +	}
>> +
>> +	/* Verify that creating a context with each defined priority level
>> +	 * succeeds, also print what we asked and which priority level we got.
>> +	 */
>> +	EGLenum levels[] = {
>> +		EGL_CONTEXT_PRIORITY_HIGH_IMG,
>> +		EGL_CONTEXT_PRIORITY_MEDIUM_IMG,
>> +		EGL_CONTEXT_PRIORITY_LOW_IMG
>> +	};
>> +
>> +	for (unsigned i = 0; i < ARRAY_SIZE(levels); i++) {
>> +		attr[1] = levels[i];
>> +		ctx = create_context(dpy, attr);
>> +		fprintf(stderr, "passed 0x%x, context created has 0x%x priority\n",
>> +			levels[i], check_priority(dpy, ctx, NULL));
> 
> I'd add a note here and say "passed hint 0x%x", just so that anyone
> who notices the discrepancy in the logs can see that the mismatch is
> acceptable.
> -Chris
> 

Sure, will add that!

// Tapani


More information about the Piglit mailing list