]> git.cworth.org Git - fips/commitdiff
test: Add support for EGL-based test, (and one EGL-based test)
authorCarl Worth <cworth@cworth.org>
Tue, 2 Jul 2013 00:44:14 +0000 (17:44 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 2 Jul 2013 21:19:39 +0000 (14:19 -0700)
For this, common.c now supports a new macro COMMON_USE_EGL which can
optionally be defined by the test before including common.c.

Some aspects of the common.c interface have changed slightly, (the
create_context call is now either create_glx_context or
create_egl_context, and the caller must explicitly call the new
common_make_current call).

This commit adds a single egl-based test, (egl-opengl-link-call),
which is similar to the existing gl-link-call test. This is basically
to ensure that the new code in common.c is functional.

We plan to follow up with egl-opengl variants for the remaining 5
existing gl tests, (and then egl-glesv2 variants for all 6 as well).

test/.gitignore
test/Makefile.local
test/common.c
test/egl-opengl-link-call.c [new file with mode: 0644]
test/fips-test
test/glx-dlopen-dlsym.c
test/glx-dlopen-gpa.c
test/glx-dlopen-gpaa.c
test/glx-link-call.c
test/glx-link-gpa.c
test/glx-link-gpaa.c

index c326b9f093178114ef051f32e6100231a8e811c1..55577409925bd9c18a818b5dd7bc7c270fa1a0db 100644 (file)
@@ -4,3 +4,5 @@ glx-link-gpaa
 glx-dlopen-dlsym
 glx-dlopen-gpa
 glx-dlopen-gpaa
+egl-opengl-link-call
+
index dfcbe8237b50c0bd24be3a59385883bb8cbedfeb..69e524aa16a0a5bc3960fded1ac769e4b2feca24 100644 (file)
@@ -13,6 +13,7 @@ test_programs += $(dir)/glx-link-gpaa
 test_programs += $(dir)/glx-dlopen-dlsym
 test_programs += $(dir)/glx-dlopen-gpa
 test_programs += $(dir)/glx-dlopen-gpaa
+test_programs += $(dir)/egl-opengl-link-call
 endif
 
 glx_link_call_srcs = \
@@ -69,6 +70,15 @@ glx_dlopen_gpaa_modules = $(glx_dlopen_gpaa_srcs:.c=.o)
 $(dir)/glx-dlopen-gpaa: $(glx_dlopen_gpaa_modules)
        $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ -ldl $(X11_LDFLAGS) -o $@
 
+egl_opengl_link_call_srcs = \
+       $(dir)/egl-opengl-link-call.c \
+       $(dir)/util-x11.c
+
+egl_opengl_link_call_modules = $(egl_opengl_link_call_srcs:.c=.o)
+
+$(dir)/egl-opengl-link-call: $(egl_opengl_link_call_modules)
+       $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ $(EGL_LDFLAGS) $(GL_LDFLAGS) $(X11_LDFLAGS) -o $@
+
 test: all $(test_programs)
        @${dir}/fips-test
 
@@ -79,11 +89,13 @@ SRCS := $(SRCS) \
        $(glx_link_gpa_srcs) \
        $(glx_link_gpaa_srcs) \
        $(glx_dlopen_dlsym_srcs) \
-       $(glx_dlopen_gpa_srcs)
+       $(glx_dlopen_gpa_srcs) \
+       $(egl_opengl_link_call_srcs)
 
 CLEAN += $(test_programs) \
        $(glx_link_call_modules) \
        $(glx_link_gpa_modules) \
        $(glx_link_gpaa_modules) \
        $(glx_dlopen_dlsym_modules) \
-       $(glx_dlopen_gpa_modules)
+       $(glx_dlopen_gpa_modules) \
+       $(egl_opengl_link_call_modules)
index 01ce383ce41c51db3b4c4445b47114a2395434a9..e4d81f81ba5afc6599d6502159bf458ff955337f 100644 (file)
 /* This is C code intended to be included (yes, included) by test
  * programs in the fips test suite.
  *
- * It defines two functions for use by the test:
- *
- *     static void
- *     common_create_context (Display *dpy, GLXContext *ctx, XVisualInfo **vi);
- * and:
- *     static void
- *     common_handle_events (Display *dpy, Window window);
- *
  * Before including this file, the test program must define a macro
  * COMMON_GL_PREFIX to some prefix. This macro can be empty (to
  * directly call functions in an OpenGL-library directly linked) or
  * can be some custom prefix to call through symbols defined in the
  * test program.
+ *
+ * Optionally, the test program may define the macro COMMON_USE_EGL to
+ * instruct the common code to use EGL (rather than GLX which it will
+ * use by default if COMMON_USE_EGL is not defined).
+ *
+ * If COMMON_USE_EGL is not defined, this file provides three
+ * functions for use by the test program:
+ *
+ *     static void
+ *     common_create_glx_context (Display *dpy,
+ *                                GLXContext *ctx, XVisualInfo **vi);
+ *
+ *     static void
+ *     common_make_current (Display *dpy, GLXContext ctx, Window window)
+ *
+ *     static void
+ *     common_handle_events (Display *dpy, GLXContext ctx, Window window);
+ *
+ * If COMMON_USE_EGL is defined, this file instead provides three
+ * similar functions:
+ *
+ *     static void
+ *     common_create_egl_context (Display *dpy, EGLenum api,
+ *                                EGLDisplay *egl_dpy, EGLContext *ctx,
+ *                                EGLConfig *config, XVisualInfo **vi);
+ *
+ *     static void
+ *     common_make_current (EGLDisplay egl_dpy, EGLContext ctx,
+ *                          EGLSurface surface)
+ *
+ *     static void
+ *     common_handle_event (Display *dpy, EGLDisplay egl_dpy,
+ *                          EGLSurface surface);
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifndef COMMON_GL_PREFIX
 #error Code including common.c must define COMMON_GL_PREFIX
 #endif
 
+#ifdef COMMON_USE_EGL
+#define COMMON_CONTEXT EGLContext
+#define COMMON_SWAP_DISPLAY EGLDisplay
+#define COMMON_SWAP_WINDOW EGLSurface
+#define COMMON_SWAP_FUNCTION eglSwapBuffers
+#else
+#define COMMON_CONTEXT GLXContext
+#define COMMON_SWAP_DISPLAY Display*
+#define COMMON_SWAP_WINDOW Window
+#define COMMON_SWAP_FUNCTION glXSwapBuffers
+#endif
+
 #define concat_(a,b) a ## b
 #define concat(a,b) concat_(a,b)
 #define _(func) concat(COMMON_GL_PREFIX, func)
@@ -61,9 +101,78 @@ paint_rgb_using_clear (double r, double g, double b)
         _(glClear) (GL_COLOR_BUFFER_BIT);
 }
 
+#ifdef COMMON_USE_EGL
+static void
+common_create_egl_context (Display *dpy, EGLenum api, EGLDisplay *egl_dpy_ret,
+                          EGLContext *ctx_ret, EGLConfig *config_ret,
+                          XVisualInfo **visual_info_ret)
+{
+       EGLDisplay egl_dpy;
+       int config_attr[] = {
+                EGL_RED_SIZE,          8,
+                EGL_GREEN_SIZE,        8,
+                EGL_BLUE_SIZE,         8,
+                EGL_ALPHA_SIZE,        8,
+               EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
+               EGL_RENDERABLE_TYPE,    EGL_OPENGL_BIT,
+                EGL_NONE
+        };
+       EGLConfig config;
+       int num_configs;
+       EGLint major, minor;
+       EGLBoolean success;
+       int context_attr[] = {
+               EGL_NONE
+       };
+       EGLContext ctx;
+       XVisualInfo *visual_info, visual_attr;
+       int visualid, num_visuals;
+
+       egl_dpy = eglGetDisplay (dpy);
+
+       success = eglInitialize (egl_dpy, &major, &minor);
+       if (!success) {
+               fprintf (stderr, "Error: Failed to initialized EGL\n");
+               exit (1);
+       }
+
+       success = eglChooseConfig (egl_dpy, config_attr, &config, 1, &num_configs);
+       if (!success || num_configs == 0) {
+               fprintf (stderr, "Error: Failed to find EGL config\n");
+               exit (1);
+       }
+
+       success = eglGetConfigAttrib (egl_dpy, config, EGL_NATIVE_VISUAL_ID, &visualid);
+       if (!success) {
+               fprintf (stderr, "Error: Failed to find native Visual ID\n");
+               exit (1);
+       }
+
+       visual_attr.visualid = visualid;
+       visual_info = XGetVisualInfo (dpy, VisualIDMask, &visual_attr, &num_visuals);
+       if (!visual_info) {
+               fprintf (stderr, "Error: Failed to get XVisualInfo\n");
+               exit (1);
+       }
+
+       eglBindAPI (api);
+
+       ctx = eglCreateContext (egl_dpy, config, NULL, context_attr);
+       if (!ctx) {
+               fprintf (stderr, "Error: Failed to create EGL context\n");
+               exit (1);
+       }
+
+       *egl_dpy_ret = egl_dpy;
+       *ctx_ret = ctx;
+       *config_ret = config;
+       *visual_info_ret = visual_info;
+       
+}
+#else
 static void
-common_create_context (Display *dpy,
-                      GLXContext *ctx_ret, XVisualInfo **visual_info_ret)
+common_create_glx_context (Display *dpy,
+                          GLXContext *ctx_ret, XVisualInfo **visual_info_ret)
 {
         int visual_attr[] = {
                 GLX_RGBA,
@@ -78,17 +187,29 @@ common_create_context (Display *dpy,
                 None
         };
 
-       /* Window and context setup. */
         *visual_info_ret = _(glXChooseVisual) (dpy, 0, visual_attr);
         *ctx_ret = _(glXCreateContext) (dpy, *visual_info_ret, NULL, True);
 }
+#endif
 
+#ifdef COMMON_USE_EGL
 static void
-draw (Display *dpy, GLXContext ctx, Window window, int width, int height)
+common_make_current (EGLDisplay egl_dpy, EGLContext ctx, EGLSurface surface)
 {
-       int i;
-        _(glXMakeCurrent) (dpy, window, ctx);
+       _(eglMakeCurrent) (egl_dpy, surface, surface, ctx);
+}
+#else
+static void
+common_make_current (Display *dpy, GLXContext ctx, Window window)
+{
+       _(glXMakeCurrent) (dpy, window, ctx);
+}
+#endif
 
+static void
+draw (COMMON_SWAP_DISPLAY dpy, COMMON_SWAP_WINDOW window, int width, int height)
+{
+       int i;
         _(glViewport) (0, 0, width, height);
 
        set_2d_projection (width, height);
@@ -100,26 +221,23 @@ draw (Display *dpy, GLXContext ctx, Window window, int width, int height)
        for (i = 0; i < 2; i++) {
                /* Frame: Draw a solid (magenta) frame */
                paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
+               _(COMMON_SWAP_FUNCTION) (dpy, window);
                frame++;
 
                /* Frame: Draw a solid (yellow) frame */
                paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
+               _(COMMON_SWAP_FUNCTION) (dpy, window);
                frame++;
 
                /* Frame: Draw a solid (cyan) frame */
                paint_rgb_using_clear (RGB(frame));
-               _(glXSwapBuffers) (dpy, window);
+               _(COMMON_SWAP_FUNCTION) (dpy, window);
                frame++;
        }
-
-       /* Cleanup */
-        _(glXDestroyContext) (dpy, ctx);
 }
 
 static void
-common_handle_events(Display *dpy, GLXContext ctx, Window window)
+common_handle_events(Display *dpy, COMMON_SWAP_DISPLAY swap_dpy, COMMON_SWAP_WINDOW window)
 {
         XEvent xev;
        int width = 0;
@@ -136,7 +254,7 @@ common_handle_events(Display *dpy, GLXContext ctx, Window window)
                         break;
                 case Expose:
                         if (xev.xexpose.count == 0) {
-                                draw (dpy, ctx, window, width, height);
+                                draw (swap_dpy, window, width, height);
                                 return;
                         }
                         break;
diff --git a/test/egl-opengl-link-call.c b/test/egl-opengl-link-call.c
new file mode 100644 (file)
index 0000000..11f8e17
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright © 2013, 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 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.
+ */
+
+/* Perform some simple drawing via OpenGL as follows:
+ *
+ *     1. Using EGL to construct an OpenGL context
+ *     2. By directly linking with libEGL.so
+ *     3. By directly calling OpenGL functions
+ */
+
+#include <EGL/egl.h>
+#include <GL/gl.h>
+
+#include "util-x11.h"
+
+#define COMMON_USE_EGL
+#define COMMON_GL_PREFIX
+#include "common.c"
+
+int
+main (void)
+{
+        Display *dpy;
+       Window window;
+       EGLDisplay egl_dpy;
+       EGLContext ctx;
+       EGLConfig config;
+        EGLSurface surface;
+       XVisualInfo *visual_info;
+
+       dpy = util_x11_init_display ();
+
+       common_create_egl_context (dpy, EGL_OPENGL_API, &egl_dpy,
+                                  &ctx, &config, &visual_info);
+
+       window = util_x11_init_window (dpy, visual_info);
+
+       surface = eglCreateWindowSurface (egl_dpy, config, window, NULL);
+
+       common_make_current (egl_dpy, ctx, surface);
+
+        common_handle_events (dpy, egl_dpy, surface);
+
+       util_x11_fini_window (dpy, window);
+
+       util_x11_fini_display (dpy);
+
+        return 0;
+}
index 85a218256fbb901d6659023577d10206392de960..2985994ac3f7f2393ad4060da7ddb311a23274f5 100755 (executable)
@@ -23,27 +23,30 @@ echo "Testing fips with programs using different window-system interfaces to"
 echo "OpenGL, different linking mechanisms, and different symbol-lookup."
 echo ""
 
-printf "               Win-sys Link-mode       Lookup\n"
-printf "               ------- -------------   -----------------\n"
+printf "       Window sys.     Link-mode       Lookup\n"
+printf "       -----------     -------------   -----------------\n"
 
-printf "Testing                GLX     link to libGL   direct calls            ... "
+printf "Testing        GLX             link to libGL   direct calls            ... "
 test glx-link-call
 
-printf "Testing                GLX     link to libGL   glXGetProcAddress       ... "
+printf "Testing        GLX             link to libGL   glXGetProcAddress       ... "
 test glx-link-gpa
 
-printf "Testing                GLX     link to libGL   glXGetProcAddressARB    ... "
+printf "Testing        GLX             link to libGL   glXGetProcAddressARB    ... "
 test glx-link-gpaa
 
-printf "Testing                GLX     dlopen(libGL)   dlsym                   ... "
+printf "Testing        GLX             dlopen(libGL)   dlsym                   ... "
 test glx-dlopen-dlsym
 
-printf "Testing                GLX     dlopen(libGL)   glXGetProcAddress       ... "
+printf "Testing        GLX             dlopen(libGL)   glXGetProcAddress       ... "
 test glx-dlopen-gpa
 
-printf "Testing                GLX     dlopen(libGL)   glXGetProcAddressARB    ... "
+printf "Testing        GLX             dlopen(libGL)   glXGetProcAddressARB    ... "
 test glx-dlopen-gpaa
 
+printf "Testing        EGL/OpenGL      link to libEGL  direct calls            ... "
+test egl-opengl-link-call
+
 echo ""
 
 if [ $errors -gt 0 ]; then
index 76749155d5755d4d3663bd56f57138dd9c07461a..6252c61d56403e88ea12f008b551d38cc43e094c 100644 (file)
@@ -156,11 +156,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       common_create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        common_handle_events (dpy, ctx, window);
+       common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);
 
index b9d1b1af82125f2762e7799af48640fd0ba883a3..514f6714909607abf7a794b509755c9869044103 100644 (file)
@@ -153,11 +153,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       common_create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        common_handle_events (dpy, ctx, window);
+       common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);
 
index cd0734bea109a8ec35adf724789e8d125880ce74..61129a187968fcb0d4a9a41f8e5202d77ad9adb0 100644 (file)
@@ -49,8 +49,8 @@ void (*my_glXDestroyContext) (Display *, GLXContext);
 Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
 void (*my_glXSwapBuffers) (Display *, GLXDrawable);
 
-#define HANDLE_EVENTS_GL_PREFIX my_
-#include "handle-events.c"
+#define COMMON_GL_PREFIX my_
+#include "common.c"
 
 static void
 resolve_symbols (void)
@@ -153,11 +153,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        handle_events (dpy, ctx, window);
+       common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);
 
index 468411140d37537fc8fb3ba8bc0fada22dfd7cf2..8527739523ccc9f45ffd8fe8b1f0ef4d2984580c 100644 (file)
@@ -45,11 +45,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       common_create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        common_handle_events (dpy, ctx, window);
+        common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);
 
index 840a648695f058d772fb935fb5658060af8eef0c..83e00a394ca94af2ca2372a756911bbf6968c140 100644 (file)
@@ -157,11 +157,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       common_create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        common_handle_events (dpy, ctx, window);
+       common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);
 
index d25d295800443653ddf440ad36d884a362e553a8..91e5e872579482b31a2dc1fada47271ee09cc0af 100644 (file)
@@ -157,11 +157,13 @@ main (void)
 
        dpy = util_x11_init_display ();
 
-       common_create_context (dpy, &ctx, &visual_info);
+       common_create_glx_context (dpy, &ctx, &visual_info);
 
        window = util_x11_init_window (dpy, visual_info);
 
-        common_handle_events (dpy, ctx, window);
+       common_make_current (dpy, ctx, window);
+
+        common_handle_events (dpy, dpy, window);
 
        util_x11_fini_window (dpy, window);