For future EGL tests, I want to be able to use Chad's new piglit EGL
subtest infrastructure, and use the EGL utilities convenience functions
to set up a window, surface, and context.

Currently, egl_util_run calls piglit_report_result() after calling
test.draw.  This means no other subtests get run.  Add a new field in
egl_test to specify whether piglit_report_result() should be called, and
another field to store the result returned from test.draw.

Make sure that egl_util_run() tears down the window, surface, and
context.  Previously it was relying on cleanup being done when the
process died, which won't work if we want to run a second subtest in the
same thread.

TODO:

There's still some work that could be done here to ensure the
initialization steps in egl_util_run aren't done twice (e.g. calling
XOpenDisplay, eglInitialize, etc.)  However, the tests pass in their
current state, so there's no reason they shouldn't be merged.

Thanks a bunch to Chad Versace and Rob Bradford, who helped me debug
this code!

Signed-off-by: Sarah Sharp <[email protected]>
Cc: Chad Versace <[email protected]>
Cc: Rob Bradford <[email protected]>
---

v2:
 - Remove glFinish in egl_util_run.  Tests still pass without it.
 - Fix memory leak of vinfo in create_window.
 - Make error handling code in egl_util_run more readable/verifiable.
 - Make sure test is const in egl_util_run.
v3:
 - squash changes to other EGL tests into the right commit (this
   commit).  My git rebase skills were rusty. :)

 tests/egl/egl-create-surface.c          |  4 ++-
 tests/egl/egl-nok-swap-region.c         |  4 ++-
 tests/egl/egl-nok-texture-from-pixmap.c |  4 ++-
 tests/egl/egl-query-surface.c           |  4 ++-
 tests/egl/egl-util.c                    | 56 ++++++++++++++++++++++-----------
 tests/egl/egl-util.h                    |  3 +-
 6 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/tests/egl/egl-create-surface.c b/tests/egl/egl-create-surface.c
index 2c7224e..1fd819a 100644
--- a/tests/egl/egl-create-surface.c
+++ b/tests/egl/egl-create-surface.c
@@ -75,5 +75,7 @@ main(int argc, char *argv[])
        egl_init_test(&test);
        test.draw = draw;
 
-       return egl_util_run(&test, argc, argv);
+       if (egl_util_run(&test, argc, argv) != PIGLIT_PASS)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
 }
diff --git a/tests/egl/egl-nok-swap-region.c b/tests/egl/egl-nok-swap-region.c
index b32bec9..e7b8ceb 100644
--- a/tests/egl/egl-nok-swap-region.c
+++ b/tests/egl/egl-nok-swap-region.c
@@ -106,7 +106,9 @@ main(int argc, char *argv[])
        test.extensions = extensions;
        test.draw = draw;
 
-       return egl_util_run(&test, argc, argv);
+       if (egl_util_run(&test, argc, argv) != PIGLIT_PASS)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
 }
 
 #else
diff --git a/tests/egl/egl-nok-texture-from-pixmap.c 
b/tests/egl/egl-nok-texture-from-pixmap.c
index 026e17b..2e96a4a 100644
--- a/tests/egl/egl-nok-texture-from-pixmap.c
+++ b/tests/egl/egl-nok-texture-from-pixmap.c
@@ -109,7 +109,9 @@ main(int argc, char *argv[])
        test.extensions = extensions;
        test.draw = draw;
 
-       return egl_util_run(&test, argc, argv);
+       if (egl_util_run(&test, argc, argv) != PIGLIT_PASS)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
 }
 
 #else
diff --git a/tests/egl/egl-query-surface.c b/tests/egl/egl-query-surface.c
index d6424e4..cf71c3d 100644
--- a/tests/egl/egl-query-surface.c
+++ b/tests/egl/egl-query-surface.c
@@ -204,5 +204,7 @@ main(int argc, char *argv[])
        test.window_width = window_width;
        test.window_height = window_height;
 
-       return egl_util_run(&test, argc, argv);
+       if (egl_util_run(&test, argc, argv) != PIGLIT_PASS)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
 }
diff --git a/tests/egl/egl-util.c b/tests/egl/egl-util.c
index 226ba0e..85d3dd9 100644
--- a/tests/egl/egl-util.c
+++ b/tests/egl/egl-util.c
@@ -79,6 +79,7 @@ egl_init_test(struct egl_test *test)
        test->extensions = no_extensions;
        test->window_width = egl_default_window_width;
        test->window_height = egl_default_window_height;
+       test->stop_on_failure = true;
 }
 
 EGLSurface
@@ -97,7 +98,7 @@ egl_util_create_pixmap(struct egl_state *state,
        return surf;
 }
 
-static void
+static enum piglit_result
 create_window(struct egl_state *state)
 {
        XSetWindowAttributes window_attr;
@@ -111,14 +112,16 @@ create_window(struct egl_state *state)
        if (!eglGetConfigAttrib(state->egl_dpy,
                                state->cfg, EGL_NATIVE_VISUAL_ID, &id)) {
                fprintf(stderr, "eglGetConfigAttrib() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               return PIGLIT_FAIL;
        }
 
        template.visualid = id;
        vinfo = XGetVisualInfo(state->dpy, VisualIDMask, &template, &count);
        if (count != 1) {
                fprintf(stderr, "XGetVisualInfo() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               if (vinfo)
+                       XFree(vinfo);
+               return PIGLIT_FAIL;
        }
 
        state->depth = vinfo->depth;
@@ -137,6 +140,7 @@ create_window(struct egl_state *state)
        XMapWindow(state->dpy, state->win);
 
        XFree(vinfo);
+       return PIGLIT_PASS;
 }
 
 static enum piglit_result
@@ -183,12 +187,12 @@ check_extensions(struct egl_state *state, const struct 
egl_test *test)
        }
 }
 
-int
+enum piglit_result
 egl_util_run(const struct egl_test *test, int argc, char *argv[])
 {
        struct egl_state state;
        EGLint count;
-       enum piglit_result result;
+       enum piglit_result result = PIGLIT_PASS;
        int i, dispatch_api, api_bit = EGL_OPENGL_BIT;
 
        EGLint ctxAttribsES[] = {
@@ -207,7 +211,8 @@ egl_util_run(const struct egl_test *test, int argc, char 
*argv[])
        state.dpy = XOpenDisplay(NULL);
        if (state.dpy == NULL) {
                fprintf(stderr, "couldn't open display\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        /* read api_bit if EGL_RENDERABLE_TYPE set in the attribs */
@@ -243,12 +248,14 @@ egl_util_run(const struct egl_test *test, int argc, char 
*argv[])
        state.egl_dpy = eglGetDisplay(state.dpy);
        if (state.egl_dpy == EGL_NO_DISPLAY) {
                fprintf(stderr, "eglGetDisplay() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        if (!eglInitialize(state.egl_dpy, &state.major, &state.minor)) {
                fprintf(stderr, "eglInitialize() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        check_extensions(&state, test);
@@ -256,40 +263,53 @@ egl_util_run(const struct egl_test *test, int argc, char 
*argv[])
        if (!eglChooseConfig(state.egl_dpy, test->config_attribs, &state.cfg, 
1, &count) ||
            count == 0) {
                fprintf(stderr, "eglChooseConfig() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        state.ctx = eglCreateContext(state.egl_dpy, state.cfg,
                                     EGL_NO_CONTEXT, ctxAttribs);
        if (state.ctx == EGL_NO_CONTEXT) {
                fprintf(stderr, "eglCreateContext() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        state.width = test->window_width;
        state.height = test->window_height;
-       create_window(&state);
+       result = create_window(&state);
+       if (result != PIGLIT_PASS)
+               goto fail;
 
        state.surf = eglCreateWindowSurface(state.egl_dpy,
                                            state.cfg, state.win, NULL);
        if (state.surf == EGL_NO_SURFACE) {
                fprintf(stderr, "eglCreateWindowSurface() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        if (!eglMakeCurrent(state.egl_dpy,
                            state.surf, state.surf, state.ctx)) {
                fprintf(stderr, "eglMakeCurrent() failed\n");
-               piglit_report_result(PIGLIT_FAIL);
+               result = PIGLIT_FAIL;
+               goto fail;
        }
 
        piglit_dispatch_default_init(dispatch_api);
 
        result = event_loop(&state, test);
 
-       eglTerminate(state.egl_dpy);
-
-       piglit_report_result(result);
-
-       return EXIT_SUCCESS;
+fail:
+       if (state.egl_dpy) {
+               eglMakeCurrent(state.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, 
EGL_NO_CONTEXT);
+               eglDestroyContext(state.egl_dpy, state.ctx);
+       }
+       if (state.win)
+               XDestroyWindow(state.dpy, state.win);
+       if (state.egl_dpy)
+               eglTerminate(state.egl_dpy);
+       if (test->stop_on_failure)
+               piglit_report_result(result);
+       return result;
 }
diff --git a/tests/egl/egl-util.h b/tests/egl/egl-util.h
index e1caa94..f5c74fd 100644
--- a/tests/egl/egl-util.h
+++ b/tests/egl/egl-util.h
@@ -35,6 +35,7 @@ struct egl_test {
        enum piglit_result (*draw)(struct egl_state *state);
        EGLint window_width;
        EGLint window_height;
+       bool stop_on_failure;
 };
 
 static const EGLint egl_default_attribs[] = {
@@ -60,7 +61,7 @@ EGLSurface
 egl_util_create_pixmap(struct egl_state *state,
                       int width, int height, const EGLint *attribs);
 
-int egl_util_run(const struct egl_test *test, int argc, char *argv[]);
+enum piglit_result egl_util_run(const struct egl_test *test, int argc, char 
*argv[]);
 
 int
 egl_probe_front_pixel_rgb(struct egl_state *state,
-- 
1.8.3.2

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to