]> git.cworth.org Git - fips/commitdiff
test: Add two more tests, (now using glXGetProcAddress instead of dlsym)
authorCarl Worth <cworth@cworth.org>
Thu, 27 Jun 2013 21:34:21 +0000 (14:34 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 27 Jun 2013 21:34:21 +0000 (14:34 -0700)
One test calls glXGetProcAddress the other calls glXGetProcAddressARB.

And noticeably, the test with glXGetProcAddress fails, so the test
suite has found its first bug.

test/.gitignore
test/Makefile.local
test/fips-test
test/glx-dlopen-gpa.c [new file with mode: 0644]
test/glx-dlopen-gpaa.c [new file with mode: 0644]

index 9b4824f49068e28754bb457e263f334a5c3c37c6..02d9184379d55f41cb9fbe3260c01e4bff578cd4 100644 (file)
@@ -1,2 +1,4 @@
 glx-link-call
 glx-dlopen-dlsym
+glx-dlopen-gpa
+glx-dlopen-gpaa
index 09072e0169e89cd0c590fff9b66d062613cbf8a8..7291dd23854585d5135166cdbbbb46000c397992 100644 (file)
@@ -9,6 +9,8 @@ test_programs =
 ifeq ($(HAVE_X11),Yes)
 test_programs += $(dir)/glx-link-call
 test_programs += $(dir)/glx-dlopen-dlsym
+test_programs += $(dir)/glx-dlopen-gpa
+test_programs += $(dir)/glx-dlopen-gpaa
 endif
 
 glx_link_call_srcs = \
@@ -29,11 +31,29 @@ glx_dlopen_dlsym_modules = $(glx_dlopen_dlsym_srcs:.c=.o)
 $(dir)/glx-dlopen-dlsym: $(glx_dlopen_dlsym_modules)
        $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ -ldl $(X11_LDFLAGS) -o $@
 
+glx_dlopen_gpa_srcs = \
+       $(dir)/glx-dlopen-gpa.c \
+       $(dir)/util.c
+
+glx_dlopen_gpa_modules = $(glx_dlopen_gpa_srcs:.c=.o)
+
+$(dir)/glx-dlopen-gpa: $(glx_dlopen_gpa_modules)
+       $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ -ldl $(X11_LDFLAGS) -o $@
+
+glx_dlopen_gpaa_srcs = \
+       $(dir)/glx-dlopen-gpaa.c \
+       $(dir)/util.c
+
+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 $@
+
 test: all $(test_programs)
        @${dir}/fips-test
 
 check: test
 
-SRCS := $(SRCS) $(glx_link_call_srcs) $(glx_dlopen_dlsym_srcs)
+SRCS := $(SRCS) $(glx_link_call_srcs) $(glx_dlopen_dlsym_srcs) $(glx_dlopen_gpa_srcs)
 
-CLEAN += $(test_programs) $(glx_link_call_modules) $(glx_dlopen_dlsym_modules)
+CLEAN += $(test_programs) $(glx_link_call_modules) $(glx_dlopen_dlsym_modules) $(glx_dlopen_gpa_modules)
index 329fc54ef1aebce3f5282f114c54c8456e088c53..7f9435288269134c554bf6abd90712efee6eb630 100755 (executable)
@@ -24,14 +24,20 @@ echo "OpenGL, different linking mechanisms, and different symbol-lookup."
 echo ""
 
 printf "               Win-sys Link-mode       Lookup\n"
-printf "               ------- -------------   ------------\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     dlopen(libGL)   dlsym           ... "
+printf "Testing                GLX     dlopen(libGL)   dlsym                   ... "
 test glx-dlopen-dlsym
 
+printf "Testing                GLX     dlopen(libGL)   glXGetProcAddress       ... "
+test glx-dlopen-gpa
+
+printf "Testing                GLX     dlopen(libGL)   glXGetProcAddressARB    ... "
+test glx-dlopen-gpaa
+
 echo ""
 
 if [ $errors -gt 0 ]; then
diff --git a/test/glx-dlopen-gpa.c b/test/glx-dlopen-gpa.c
new file mode 100644 (file)
index 0000000..716d3e2
--- /dev/null
@@ -0,0 +1,249 @@
+/* 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 GLX to construct an OpenGL context
+ *     2. By using dlopen to dynamically load libGL.so
+ *     3. By using dlsym to lookup OpenGL functions
+ */
+
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+#include <GL/glx.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include "util.h"
+
+void* (*my_glXGetProcAddress) (char *);
+void (*my_glClear) (GLbitfield);
+void (*my_glClearColor) (GLclampf, GLclampf, GLclampf, GLclampf);
+void (*my_glLoadIdentity) (void);
+void (*my_glMatrixMode) (GLenum);
+void (*my_glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
+void (*my_glViewport) (GLint, GLint, GLsizei, GLsizei);
+XVisualInfo * (*my_glXChooseVisual) (Display *, int, int *);
+GLXContext (*my_glXCreateContext) (Display *, XVisualInfo *, GLXContext, Bool);
+void (*my_glXDestroyContext) (Display *, GLXContext);
+Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
+void (*my_glXSwapBuffers) (Display *, GLXDrawable);
+
+static void
+set_2d_projection (int width, int height)
+{
+       my_glMatrixMode (GL_PROJECTION);
+       my_glLoadIdentity ();
+       my_glOrtho (0, width, height, 0, 0, 1);
+       my_glMatrixMode (GL_MODELVIEW);
+}
+
+static void
+paint_rgb_using_clear (double r, double g, double b)
+{
+        my_glClearColor(r, g, b, 1.0);
+        my_glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void
+draw (Display *dpy, Window window, int width, int height)
+{
+       int i;
+        int visual_attr[] = {
+                GLX_RGBA,
+                GLX_RED_SIZE,          8,
+                GLX_GREEN_SIZE,        8,
+                GLX_BLUE_SIZE,         8,
+                GLX_ALPHA_SIZE,        8,
+                GLX_DOUBLEBUFFER,
+                GLX_DEPTH_SIZE,                24,
+                GLX_STENCIL_SIZE,      8,
+                GLX_X_VISUAL_TYPE,     GLX_DIRECT_COLOR,
+                None
+        };
+
+       /* Window and context setup. */
+        XVisualInfo *visual_info = my_glXChooseVisual(dpy, 0, visual_attr);
+        GLXContext ctx = my_glXCreateContext(dpy, visual_info, NULL, True);
+        my_glXMakeCurrent(dpy, window, ctx);
+
+        my_glViewport(0, 0, width, height);
+
+       set_2d_projection (width, height);
+
+/* Simply count through some colors, frame by frame. */
+#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
+
+       int frame = 0;
+       for (i = 0; i < 2; i++) {
+               /* Frame: Draw a solid (magenta) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (yellow) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (cyan) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+       }
+
+       /* Cleanup */
+        my_glXDestroyContext (dpy, ctx);
+}
+
+static void
+handle_events(Display *dpy, Window window)
+{
+        XEvent xev;
+       int width = 0;
+       int height = 0;
+
+        XNextEvent (dpy, &xev);
+
+        while (1) {
+                XNextEvent (dpy, &xev);
+                switch (xev.type) {
+                case ConfigureNotify:
+                        width = xev.xconfigure.width;
+                        height = xev.xconfigure.height;
+                        break;
+                case Expose:
+                        if (xev.xexpose.count == 0) {
+                                draw (dpy, window, width, height);
+                                return;
+                        }
+                        break;
+                }
+        }
+}
+
+static void
+resolve_symbols (void)
+{
+       void *gl_handle;
+       char *error;
+
+       gl_handle = dlopen ("libGL.so", RTLD_LAZY);
+       if (gl_handle == NULL) {
+               fprintf (stderr, "Error: Failed to open libGL.so\n");
+               exit (1);
+       }
+
+       /* Clear errors. */
+       dlerror();
+
+       my_glXGetProcAddress = dlsym (gl_handle, "glXGetProcAddress");
+       error = dlerror ();
+       if (error) {
+               fprintf (stderr, "Failed to dlsym glXGetProcAddress: %s\n", error);
+               exit (1);
+       }
+
+       my_glClear = my_glXGetProcAddress ("glClear");
+       if (my_glClear == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glClear\n");
+               exit (1);
+       }
+
+       my_glClearColor = my_glXGetProcAddress ("glClearColor");
+       if (my_glClearColor == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glClearColor\n");
+               exit (1);
+       }
+
+       my_glLoadIdentity = my_glXGetProcAddress ("glLoadIdentity");
+       if (my_glLoadIdentity == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glLoadIdentity\n");
+               exit (1);
+       }
+
+       my_glMatrixMode = my_glXGetProcAddress ("glMatrixMode");
+       if (my_glMatrixMode == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glMatrixMode\n");
+               exit (1);
+       }
+
+       my_glOrtho = my_glXGetProcAddress ("glOrtho");
+       if (my_glOrtho == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glOrtho\n");
+               exit (1);
+       }
+
+       my_glViewport = my_glXGetProcAddress ("glViewport");
+       if (my_glViewport == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glViewport\n");
+               exit (1);
+       }
+
+       my_glXChooseVisual = my_glXGetProcAddress ("glXChooseVisual");
+       if (my_glXChooseVisual == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glXChooseVisual\n");
+               exit (1);
+       }
+
+       my_glXCreateContext = my_glXGetProcAddress ("glXCreateContext");
+       if (my_glXCreateContext == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glXCreateContext\n");
+               exit (1);
+       }
+
+       my_glXDestroyContext = my_glXGetProcAddress ("glXDestroyContext");
+       if (my_glXDestroyContext == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glXDestroyContext\n");
+               exit (1);
+       }
+
+       my_glXMakeCurrent = my_glXGetProcAddress ("glXMakeCurrent");
+       if (my_glXMakeCurrent == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glXMakeCurrent\n");
+               exit (1);
+       }
+
+       my_glXSwapBuffers = my_glXGetProcAddress ("glXSwapBuffers");
+       if (my_glXSwapBuffers == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddress glXSwapBuffers\n");
+               exit (1);
+       }
+}
+
+int
+main (void)
+{
+        Display *dpy;
+        Window window;
+
+       util_init_display_window (&dpy, &window);
+
+       resolve_symbols ();
+
+        handle_events (dpy, window);
+
+       util_fini_display_window (dpy, window);
+
+        return 0;
+}
diff --git a/test/glx-dlopen-gpaa.c b/test/glx-dlopen-gpaa.c
new file mode 100644 (file)
index 0000000..b81a57b
--- /dev/null
@@ -0,0 +1,249 @@
+/* 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 GLX to construct an OpenGL context
+ *     2. By using dlopen to dynamically load libGL.so
+ *     3. By using dlsym to lookup OpenGL functions
+ */
+
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+#include <GL/glx.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include "util.h"
+
+void* (*my_glXGetProcAddressARB) (char *);
+void (*my_glClear) (GLbitfield);
+void (*my_glClearColor) (GLclampf, GLclampf, GLclampf, GLclampf);
+void (*my_glLoadIdentity) (void);
+void (*my_glMatrixMode) (GLenum);
+void (*my_glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
+void (*my_glViewport) (GLint, GLint, GLsizei, GLsizei);
+XVisualInfo * (*my_glXChooseVisual) (Display *, int, int *);
+GLXContext (*my_glXCreateContext) (Display *, XVisualInfo *, GLXContext, Bool);
+void (*my_glXDestroyContext) (Display *, GLXContext);
+Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
+void (*my_glXSwapBuffers) (Display *, GLXDrawable);
+
+static void
+set_2d_projection (int width, int height)
+{
+       my_glMatrixMode (GL_PROJECTION);
+       my_glLoadIdentity ();
+       my_glOrtho (0, width, height, 0, 0, 1);
+       my_glMatrixMode (GL_MODELVIEW);
+}
+
+static void
+paint_rgb_using_clear (double r, double g, double b)
+{
+        my_glClearColor(r, g, b, 1.0);
+        my_glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void
+draw (Display *dpy, Window window, int width, int height)
+{
+       int i;
+        int visual_attr[] = {
+                GLX_RGBA,
+                GLX_RED_SIZE,          8,
+                GLX_GREEN_SIZE,        8,
+                GLX_BLUE_SIZE,         8,
+                GLX_ALPHA_SIZE,        8,
+                GLX_DOUBLEBUFFER,
+                GLX_DEPTH_SIZE,                24,
+                GLX_STENCIL_SIZE,      8,
+                GLX_X_VISUAL_TYPE,     GLX_DIRECT_COLOR,
+                None
+        };
+
+       /* Window and context setup. */
+        XVisualInfo *visual_info = my_glXChooseVisual(dpy, 0, visual_attr);
+        GLXContext ctx = my_glXCreateContext(dpy, visual_info, NULL, True);
+        my_glXMakeCurrent(dpy, window, ctx);
+
+        my_glViewport(0, 0, width, height);
+
+       set_2d_projection (width, height);
+
+/* Simply count through some colors, frame by frame. */
+#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
+
+       int frame = 0;
+       for (i = 0; i < 2; i++) {
+               /* Frame: Draw a solid (magenta) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (yellow) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (cyan) frame */
+               paint_rgb_using_clear (RGB(frame));
+               my_glXSwapBuffers (dpy, window);
+               frame++;
+       }
+
+       /* Cleanup */
+        my_glXDestroyContext (dpy, ctx);
+}
+
+static void
+handle_events(Display *dpy, Window window)
+{
+        XEvent xev;
+       int width = 0;
+       int height = 0;
+
+        XNextEvent (dpy, &xev);
+
+        while (1) {
+                XNextEvent (dpy, &xev);
+                switch (xev.type) {
+                case ConfigureNotify:
+                        width = xev.xconfigure.width;
+                        height = xev.xconfigure.height;
+                        break;
+                case Expose:
+                        if (xev.xexpose.count == 0) {
+                                draw (dpy, window, width, height);
+                                return;
+                        }
+                        break;
+                }
+        }
+}
+
+static void
+resolve_symbols (void)
+{
+       void *gl_handle;
+       char *error;
+
+       gl_handle = dlopen ("libGL.so", RTLD_LAZY);
+       if (gl_handle == NULL) {
+               fprintf (stderr, "Error: Failed to open libGL.so\n");
+               exit (1);
+       }
+
+       /* Clear errors. */
+       dlerror();
+
+       my_glXGetProcAddressARB = dlsym (gl_handle, "glXGetProcAddressARB");
+       error = dlerror ();
+       if (error) {
+               fprintf (stderr, "Failed to dlsym glXGetProcAddressARB: %s\n", error);
+               exit (1);
+       }
+
+       my_glClear = my_glXGetProcAddressARB ("glClear");
+       if (my_glClear == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glClear\n");
+               exit (1);
+       }
+
+       my_glClearColor = my_glXGetProcAddressARB ("glClearColor");
+       if (my_glClearColor == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glClearColor\n");
+               exit (1);
+       }
+
+       my_glLoadIdentity = my_glXGetProcAddressARB ("glLoadIdentity");
+       if (my_glLoadIdentity == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glLoadIdentity\n");
+               exit (1);
+       }
+
+       my_glMatrixMode = my_glXGetProcAddressARB ("glMatrixMode");
+       if (my_glMatrixMode == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glMatrixMode\n");
+               exit (1);
+       }
+
+       my_glOrtho = my_glXGetProcAddressARB ("glOrtho");
+       if (my_glOrtho == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glOrtho\n");
+               exit (1);
+       }
+
+       my_glViewport = my_glXGetProcAddressARB ("glViewport");
+       if (my_glViewport == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glViewport\n");
+               exit (1);
+       }
+
+       my_glXChooseVisual = my_glXGetProcAddressARB ("glXChooseVisual");
+       if (my_glXChooseVisual == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glXChooseVisual\n");
+               exit (1);
+       }
+
+       my_glXCreateContext = my_glXGetProcAddressARB ("glXCreateContext");
+       if (my_glXCreateContext == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glXCreateContext\n");
+               exit (1);
+       }
+
+       my_glXDestroyContext = my_glXGetProcAddressARB ("glXDestroyContext");
+       if (my_glXDestroyContext == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glXDestroyContext\n");
+               exit (1);
+       }
+
+       my_glXMakeCurrent = my_glXGetProcAddressARB ("glXMakeCurrent");
+       if (my_glXMakeCurrent == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glXMakeCurrent\n");
+               exit (1);
+       }
+
+       my_glXSwapBuffers = my_glXGetProcAddressARB ("glXSwapBuffers");
+       if (my_glXSwapBuffers == NULL) {
+               fprintf (stderr, "Failed to glXGetProcAddressARB glXSwapBuffers\n");
+               exit (1);
+       }
+}
+
+int
+main (void)
+{
+        Display *dpy;
+        Window window;
+
+       util_init_display_window (&dpy, &window);
+
+       resolve_symbols ();
+
+        handle_events (dpy, window);
+
+       util_fini_display_window (dpy, window);
+
+        return 0;
+}