From: Carl Worth Date: Fri, 28 Jun 2013 17:55:59 +0000 (-0700) Subject: test: Add two more tests to the test suite X-Git-Url: https://git.cworth.org/git?p=fips;a=commitdiff_plain;h=e90938cac9a539dc00c08b4439298cd05dada442 test: Add two more tests to the test suite These link directly against libGL, but then use glXGetProcAddress or glXGetProcAddressARB to locate OpenGL function symbols. --- diff --git a/test/.gitignore b/test/.gitignore index 02d9184..c326b9f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,6 @@ glx-link-call +glx-link-gpa +glx-link-gpaa glx-dlopen-dlsym glx-dlopen-gpa glx-dlopen-gpaa diff --git a/test/Makefile.local b/test/Makefile.local index 7291dd2..aae7fda 100644 --- a/test/Makefile.local +++ b/test/Makefile.local @@ -8,6 +8,8 @@ test_programs = ifeq ($(HAVE_X11),Yes) test_programs += $(dir)/glx-link-call +test_programs += $(dir)/glx-link-gpa +test_programs += $(dir)/glx-link-gpaa test_programs += $(dir)/glx-dlopen-dlsym test_programs += $(dir)/glx-dlopen-gpa test_programs += $(dir)/glx-dlopen-gpaa @@ -22,6 +24,24 @@ glx_link_call_modules = $(glx_link_call_srcs:.c=.o) $(dir)/glx-link-call: $(glx_link_call_modules) $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ $(GL_LDFLAGS) $(X11_LDFLAGS) -o $@ +glx_link_gpa_srcs = \ + $(dir)/glx-link-gpa.c \ + $(dir)/util.c + +glx_link_gpa_modules = $(glx_link_gpa_srcs:.c=.o) + +$(dir)/glx-link-gpa: $(glx_link_gpa_modules) + $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ $(GL_LDFLAGS) $(X11_LDFLAGS) -o $@ + +glx_link_gpaa_srcs = \ + $(dir)/glx-link-gpaa.c \ + $(dir)/util.c + +glx_link_gpaa_modules = $(glx_link_gpaa_srcs:.c=.o) + +$(dir)/glx-link-gpaa: $(glx_link_gpaa_modules) + $(call quiet,$(FIPS_LINKER) $(CFLAGS)) $^ $(GL_LDFLAGS) $(X11_LDFLAGS) -o $@ + glx_dlopen_dlsym_srcs = \ $(dir)/glx-dlopen-dlsym.c \ $(dir)/util.c @@ -54,6 +74,16 @@ test: all $(test_programs) check: test -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) $(glx_dlopen_gpa_modules) +SRCS := $(SRCS) \ + $(glx_link_call_srcs) \ + $(glx_link_gpa_srcs) \ + $(glx_link_gpaa_srcs) \ + $(glx_dlopen_dlsym_srcs) \ + $(glx_dlopen_gpa_srcs) + +CLEAN += $(test_programs) \ + $(glx_link_call_modules) \ + $(glx_link_gpa_modules) \ + $(glx_link_gpaa_modules) \ + $(glx_dlopen_dlsym_modules) \ + $(glx_dlopen_gpa_modules) diff --git a/test/fips-test b/test/fips-test index 7f94352..85a2182 100755 --- a/test/fips-test +++ b/test/fips-test @@ -29,6 +29,12 @@ printf " ------- ------------- -----------------\n" printf "Testing GLX link to libGL direct calls ... " test glx-link-call +printf "Testing GLX link to libGL glXGetProcAddress ... " +test glx-link-gpa + +printf "Testing GLX link to libGL glXGetProcAddressARB ... " +test glx-link-gpaa + printf "Testing GLX dlopen(libGL) dlsym ... " test glx-dlopen-dlsym diff --git a/test/glx-link-gpa.c b/test/glx-link-gpa.c new file mode 100644 index 0000000..04e5eb9 --- /dev/null +++ b/test/glx-link-gpa.c @@ -0,0 +1,163 @@ +/* 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 directly linking with libGL.so + * 3. By using glXGetProcAddress to lookup OpenGL functions + */ + +#define GL_GLEXT_PROTOTYPES +#include +#include + +#include +#include + +#include "util.h" + +/* The OpenGL header files give typedefs for the types of all + * functions provided by etensisons. Here, though, we're using + * glxGetProcAddress to lookup core functions, so we provide our own + * typedefs. */ +typedef void (*FIPS_GLCLEAR_FN)(GLbitfield); +FIPS_GLCLEAR_FN my_glClear; + +typedef void (*FIPS_GLCLEARCOLOR_FN)(GLclampf, GLclampf, GLclampf, GLclampf); +FIPS_GLCLEARCOLOR_FN my_glClearColor; + +typedef void (*FIPS_GLLOADIDENTITY_FN)(void); +FIPS_GLLOADIDENTITY_FN my_glLoadIdentity; + +typedef void (*FIPS_GLMATRIXMODE_FN)(GLenum); +FIPS_GLMATRIXMODE_FN my_glMatrixMode; + +typedef void (*FIPS_GLORTHO_FN)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); +FIPS_GLORTHO_FN my_glOrtho; + +typedef void (*FIPS_GLVIEWPORT_FN)(GLint, GLint, GLsizei, GLsizei); +FIPS_GLVIEWPORT_FN my_glViewport; + +typedef XVisualInfo* (*FIPS_GLXCHOOSEVISUAL_FN)(Display *, int, int *); +FIPS_GLXCHOOSEVISUAL_FN my_glXChooseVisual; + +typedef GLXContext (*FIPS_GLXCREATECONTEXT_FN)(Display *, XVisualInfo *, GLXContext, Bool); +FIPS_GLXCREATECONTEXT_FN my_glXCreateContext; + +typedef void (*FIPS_GLXDESTROYCONTEXT_FN)(Display *, GLXContext); +FIPS_GLXDESTROYCONTEXT_FN my_glXDestroyContext; + +typedef Bool (*FIPS_GLXMAKECURRENT_FN)(Display *, GLXDrawable, GLXContext); +FIPS_GLXMAKECURRENT_FN my_glXMakeCurrent; + +typedef void (*FIPS_GLXSWAPBUFFERS_FN)(Display *, GLXDrawable); +FIPS_GLXSWAPBUFFERS_FN my_glXSwapBuffers; + +#define HANDLE_EVENTS_GL_PREFIX my_ +#include "handle-events.c" + +static void +resolve_symbols (void) +{ + my_glClear = (FIPS_GLCLEAR_FN) glXGetProcAddress ((GLubyte*) "glClear"); + if (my_glClear == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glClear\n"); + exit (1); + } + + my_glClearColor = (FIPS_GLCLEARCOLOR_FN) glXGetProcAddress ((GLubyte*) "glClearColor"); + if (my_glClearColor == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glClearColor\n"); + exit (1); + } + + my_glLoadIdentity = (FIPS_GLLOADIDENTITY_FN) glXGetProcAddress ((GLubyte*) "glLoadIdentity"); + if (my_glLoadIdentity == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glLoadIdentity\n"); + exit (1); + } + + my_glMatrixMode = (FIPS_GLMATRIXMODE_FN) glXGetProcAddress ((GLubyte*) "glMatrixMode"); + if (my_glMatrixMode == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glMatrixMode\n"); + exit (1); + } + + my_glOrtho = (FIPS_GLORTHO_FN) glXGetProcAddress ((GLubyte*) "glOrtho"); + if (my_glOrtho == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glOrtho\n"); + exit (1); + } + + my_glViewport = (FIPS_GLVIEWPORT_FN) glXGetProcAddress ((GLubyte*) "glViewport"); + if (my_glViewport == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glViewport\n"); + exit (1); + } + + my_glXChooseVisual = (FIPS_GLXCHOOSEVISUAL_FN) glXGetProcAddress ((GLubyte*) "glXChooseVisual"); + if (my_glXChooseVisual == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glXChooseVisual\n"); + exit (1); + } + + my_glXCreateContext = (FIPS_GLXCREATECONTEXT_FN) glXGetProcAddress ((GLubyte*) "glXCreateContext"); + if (my_glXCreateContext == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glXCreateContext\n"); + exit (1); + } + + my_glXDestroyContext = (FIPS_GLXDESTROYCONTEXT_FN) glXGetProcAddress ((GLubyte*) "glXDestroyContext"); + if (my_glXDestroyContext == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glXDestroyContext\n"); + exit (1); + } + + my_glXMakeCurrent = (FIPS_GLXMAKECURRENT_FN) glXGetProcAddress ((GLubyte*) "glXMakeCurrent"); + if (my_glXMakeCurrent == NULL) { + fprintf (stderr, "Failed to glXGetProcAddress glXMakeCurrent\n"); + exit (1); + } + + my_glXSwapBuffers = (FIPS_GLXSWAPBUFFERS_FN) glXGetProcAddress ((GLubyte*) "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-link-gpaa.c b/test/glx-link-gpaa.c new file mode 100644 index 0000000..2bf73be --- /dev/null +++ b/test/glx-link-gpaa.c @@ -0,0 +1,163 @@ +/* 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 directly linking with libGL.so + * 3. By using glXGetProcAddressARB to lookup OpenGL functions + */ + +#define GL_GLEXT_PROTOTYPES +#include +#include + +#include +#include + +#include "util.h" + +/* The OpenGL header files give typedefs for the types of all + * functions provided by etensisons. Here, though, we're using + * glxGetProcAddressARB to lookup core functions, so we provide our + * own typedefs. */ +typedef void (*FIPS_GLCLEAR_FN)(GLbitfield); +FIPS_GLCLEAR_FN my_glClear; + +typedef void (*FIPS_GLCLEARCOLOR_FN)(GLclampf, GLclampf, GLclampf, GLclampf); +FIPS_GLCLEARCOLOR_FN my_glClearColor; + +typedef void (*FIPS_GLLOADIDENTITY_FN)(void); +FIPS_GLLOADIDENTITY_FN my_glLoadIdentity; + +typedef void (*FIPS_GLMATRIXMODE_FN)(GLenum); +FIPS_GLMATRIXMODE_FN my_glMatrixMode; + +typedef void (*FIPS_GLORTHO_FN)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); +FIPS_GLORTHO_FN my_glOrtho; + +typedef void (*FIPS_GLVIEWPORT_FN)(GLint, GLint, GLsizei, GLsizei); +FIPS_GLVIEWPORT_FN my_glViewport; + +typedef XVisualInfo* (*FIPS_GLXCHOOSEVISUAL_FN)(Display *, int, int *); +FIPS_GLXCHOOSEVISUAL_FN my_glXChooseVisual; + +typedef GLXContext (*FIPS_GLXCREATECONTEXT_FN)(Display *, XVisualInfo *, GLXContext, Bool); +FIPS_GLXCREATECONTEXT_FN my_glXCreateContext; + +typedef void (*FIPS_GLXDESTROYCONTEXT_FN)(Display *, GLXContext); +FIPS_GLXDESTROYCONTEXT_FN my_glXDestroyContext; + +typedef Bool (*FIPS_GLXMAKECURRENT_FN)(Display *, GLXDrawable, GLXContext); +FIPS_GLXMAKECURRENT_FN my_glXMakeCurrent; + +typedef void (*FIPS_GLXSWAPBUFFERS_FN)(Display *, GLXDrawable); +FIPS_GLXSWAPBUFFERS_FN my_glXSwapBuffers; + +#define HANDLE_EVENTS_GL_PREFIX my_ +#include "handle-events.c" + +static void +resolve_symbols (void) +{ + my_glClear = (FIPS_GLCLEAR_FN) glXGetProcAddressARB ((GLubyte*) "glClear"); + if (my_glClear == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glClear\n"); + exit (1); + } + + my_glClearColor = (FIPS_GLCLEARCOLOR_FN) glXGetProcAddressARB ((GLubyte*) "glClearColor"); + if (my_glClearColor == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glClearColor\n"); + exit (1); + } + + my_glLoadIdentity = (FIPS_GLLOADIDENTITY_FN) glXGetProcAddressARB ((GLubyte*) "glLoadIdentity"); + if (my_glLoadIdentity == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glLoadIdentity\n"); + exit (1); + } + + my_glMatrixMode = (FIPS_GLMATRIXMODE_FN) glXGetProcAddressARB ((GLubyte*) "glMatrixMode"); + if (my_glMatrixMode == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glMatrixMode\n"); + exit (1); + } + + my_glOrtho = (FIPS_GLORTHO_FN) glXGetProcAddressARB ((GLubyte*) "glOrtho"); + if (my_glOrtho == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glOrtho\n"); + exit (1); + } + + my_glViewport = (FIPS_GLVIEWPORT_FN) glXGetProcAddressARB ((GLubyte*) "glViewport"); + if (my_glViewport == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glViewport\n"); + exit (1); + } + + my_glXChooseVisual = (FIPS_GLXCHOOSEVISUAL_FN) glXGetProcAddressARB ((GLubyte*) "glXChooseVisual"); + if (my_glXChooseVisual == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glXChooseVisual\n"); + exit (1); + } + + my_glXCreateContext = (FIPS_GLXCREATECONTEXT_FN) glXGetProcAddressARB ((GLubyte*) "glXCreateContext"); + if (my_glXCreateContext == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glXCreateContext\n"); + exit (1); + } + + my_glXDestroyContext = (FIPS_GLXDESTROYCONTEXT_FN) glXGetProcAddressARB ((GLubyte*) "glXDestroyContext"); + if (my_glXDestroyContext == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glXDestroyContext\n"); + exit (1); + } + + my_glXMakeCurrent = (FIPS_GLXMAKECURRENT_FN) glXGetProcAddressARB ((GLubyte*) "glXMakeCurrent"); + if (my_glXMakeCurrent == NULL) { + fprintf (stderr, "Failed to glXGetProcAddressARB glXMakeCurrent\n"); + exit (1); + } + + my_glXSwapBuffers = (FIPS_GLXSWAPBUFFERS_FN) glXGetProcAddressARB ((GLubyte*) "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; +}