[Piglit] [PATCH 4/5] egl: Test behavior of eglQuerySurface()
Ian Romanick
idr at freedesktop.org
Thu Oct 27 10:56:40 PDT 2011
On 10/19/2011 06:37 PM, Chad Versace wrote:
> Add the following tests:
>
> * egl-query-surface --bad-surface
> Call eglQuerySurface(surf=0) and expect that error EGL_BAD_SURFACE
> is generated.
>
> * egl-query-surface --bad-attr
> Call eglQuerySurface(attr=EGL_DONT_CARE) and expect that error
> EGL_BAD_ATTRIBUTE is generated.
>
> * egl-query-surface --attr=EGL_WIDTH
> * egl-query-surface --attr=EGL_HEIGHT
> Call eglQueryDrawable() with the given attribute.
>
> All tests pass on Fedora 15, which has
> Mesa 7.11
> Xserver 1.10.4
> xcb 0.3.6
>
> (Strangely, no EGL test is added to all.tests. That should be fixed.)
We have the same issue with ES1 and ES2 tests. The problem is that
people expect running all.tests to "just work." However, many
implementations may not have EGL, ES1, or ES2. If you run tests that
link with non-existent (or unsupported) libraries, they will show up as
fail instead of skip in the results.
For the ES1 tests, Chia-I and I have started adding them to
all_es1.tests. This is not ideal (or scaleable), but it works for now.
We need to find a better solution.
> Signed-off-by: Chad Versace<chad at chad-versace.us>
> ---
> tests/egl/CMakeLists.gl.txt | 2 +
> tests/egl/egl-query-surface.c | 193 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 195 insertions(+), 0 deletions(-)
> create mode 100644 tests/egl/egl-query-surface.c
>
> diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt
> index d59e4ae..1ab0dd5 100644
> --- a/tests/egl/CMakeLists.gl.txt
> +++ b/tests/egl/CMakeLists.gl.txt
> @@ -21,6 +21,8 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
> target_link_libraries(egl-nok-texture-from-pixmap pthread X11)
> add_executable (egl-create-surface egl-util.c egl-create-surface.c)
> target_link_libraries(egl-create-surface pthread X11)
> + add_executable (egl-query-surface egl-util.c egl-query-surface.c)
> + target_link_libraries(egl-query-surface pthread X11)
> ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>
> # vim: ft=cmake:
> diff --git a/tests/egl/egl-query-surface.c b/tests/egl/egl-query-surface.c
> new file mode 100644
> index 0000000..104f21f
> --- /dev/null
> +++ b/tests/egl/egl-query-surface.c
> @@ -0,0 +1,193 @@
> +/*
> + * Copyright © 2011 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.
> + */
> +
> +/** @file egl-query-drawable.c
> + *
> + * Test behavior of eglQuerySurface(). See EGL 1.4 spec, Section 3.5.6
> + * Surface Attributes.
> + *
> + * For usage information, see usage_error().
> + */
> +
> +#include<EGL/egl.h>
> +#include "piglit-util-egl.h"
> +#include "egl-util.h"
> +
> +static EGLint window_width = 119;
> +static EGLint window_height= 137;
> +
> +static void
> +usage_error()
> +{
> + const char *message =
> + "usage:\n"
> + " egl-query-surface [-auto] --bad-surface\n"
> + " Call eglQuerySurface(surf=0) and expect that error\n"
> + " EGL_BAD_SURFACE is generated.\n"
> + "\n"
> + " egl-query-surface [-auto] --bad-attr\n"
> + " Call eglQuerySurface(attr=EGL_DONT_CARE) and expect that\n"
> + " error EGL_BAD_ATTRIBUTE is generated.\n"
> + "\n"
> + " egl-query-surface [-auto] --attr=EGL_WIDTH\n"
> + " egl-query-surface [-auto] --attr=EGL_HEIGHT\n"
> + " Call eglQueryDrawable() with the given attribute.\n";
> + printf(message);
> + piglit_report_result(PIGLIT_FAIL);
> +}
> +
> +static enum piglit_result
> +query_width(struct egl_state *state)
> +{
> + EGLint width;
> + EGLBoolean ok;
> +
> + assert(state->width == window_width);
> + ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_WIDTH,&width);
> + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
> + if (!ok) {
> + fprintf(stderr, "error: eglQuerySurface() failed\n");
> + return PIGLIT_FAIL;
> + }
> + if (width != state->width) {
> + fprintf(stderr,
> + "error: width=%d but eglQuerySurface(EGL_WIDTH) "
> + "returned %d\n", state->height, width);
> + return PIGLIT_FAIL;
> + }
> + return PIGLIT_PASS;
> +}
> +
> +static enum piglit_result
> +query_height(struct egl_state *state)
> +{
> + EGLint height;
> + EGLBoolean ok;
> +
> + assert(state->height == window_height);
> + ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_HEIGHT,&height);
> + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
> + if (!ok) {
> + fprintf(stderr, "error: eglQuerySurface() failed\n");
> + return PIGLIT_FAIL;
> + }
> + if (height != state->height) {
> + fprintf(stderr,
> + "error: height=%d but eglQuerySurface(EGL_HEIGHT) "
> + "returned %d\n", state->height, height);
> + return PIGLIT_FAIL;
> + }
> + return PIGLIT_PASS;
> +}
> +
> +static enum piglit_result
> +query_bad_surface(struct egl_state *state)
> +{
> + EGLint width;
> + EGLBoolean ok;
> +
> + ok = eglQuerySurface(state->egl_dpy, 0, EGL_WIDTH,&width);
> + if (ok) {
> + fprintf(stderr,
> + "error: eglQuerySurface(surface=0) succeeded\n");
> + return PIGLIT_FAIL;
> + }
> + piglit_expect_egl_error(EGL_BAD_SURFACE, PIGLIT_FAIL);
> + return PIGLIT_PASS;
> +}
> +
> +static enum piglit_result
> +query_bad_parameter(struct egl_state *state)
> +{
> + EGLint junk;
> + EGLBoolean ok;
> +
> + ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_DONT_CARE,
> + &junk);
> + if (ok) {
> + fprintf(stderr,
> + "error: eglQuerySurface(attribute=EGL_DONT_CARE) "
> + "succeeded\n");
> + return PIGLIT_FAIL;
> + }
> + piglit_expect_egl_error(EGL_BAD_ATTRIBUTE, PIGLIT_FAIL);
> + return PIGLIT_PASS;
> +}
> +
> +static void
> +parse_args(int argc, char **argv,
> + enum piglit_result (**test_func)(struct egl_state*))
> +{
> + int i;
> +
> + /* Count of parsed args, exlcluding -auto. */
> + int num_parsed_args = 0;
> +
> + for (i = 1; i< argc; ++i) {
> + const char *arg = argv[i];
> + if (!strncmp(arg, "-auto", 5)) {
> + /* Skip. -auto is parsed by egl_util_run().
> + *
> + * More importantly, referencing piglit_automatic here
> + * will mysteriously cause linking to fail with the
> + * message:
> + * piglit-framework.c: multiple definition of `main'
> + */
> + } else if (!strncmp(arg, "--bad-surface", 13)) {
> + ++num_parsed_args;
> + *test_func = query_bad_surface;
> + } else if (!strncmp(arg, "--bad-attr", 10)) {
> + ++num_parsed_args;
> + *test_func = query_bad_parameter;
> + } else if (!strncmp(arg, "--attr=EGL_WIDTH", 16)) {
> + ++num_parsed_args;
> + *test_func = query_width;
> + } else if (!strncmp(arg, "--attr=EGL_HEIGHT", 17)) {
> + ++num_parsed_args;
> + *test_func = query_height;
> + } else {
> + /* Unrecognized argument. */
> + usage_error();
> + }
> + }
> +
> + if (num_parsed_args != 1) {
> + usage_error();
> + }
> +}
> +
> +int
> +main(int argc, char *argv[])
> +{
> + struct egl_test test;
> + enum piglit_result (*test_func)(struct egl_state *state) = NULL;
> +
> + parse_args(argc, argv,&test_func);
> +
> + egl_init_test(&test);
> + test.draw = test_func;
> + test.window_width = window_width;
> + test.window_height = window_height;
> +
> + return egl_util_run(&test, argc, argv);
> +}
More information about the Piglit
mailing list