]> git.cworth.org Git - fips/commitdiff
fips: Add the beginning of a test suite
authorCarl Worth <cworth@cworth.org>
Thu, 27 Jun 2013 20:26:59 +0000 (13:26 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 27 Jun 2013 20:38:42 +0000 (13:38 -0700)
So far, there's just one test program. It links against libGL.so and
uses GLX to render a few solid frames. The test suite ensures that it
can be run and that "fips --verbose" actually prints a message.

Makefile
Makefile.local
test/.gitignore [new file with mode: 0644]
test/Makefile [new file with mode: 0644]
test/Makefile.local [new file with mode: 0644]
test/fips-test [new file with mode: 0755]
test/glx-link-call.c [new file with mode: 0644]
test/util.c [new file with mode: 0644]
test/util.h [new file with mode: 0644]

index 6938f22769ae86d4cf5daec151b1d7e13fc15f4f..f40cd5015c109a4b5505d095ffd944b2d6166dc3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 all:
 
 # List all subdirectores here. Each contains its own Makefile.local
-subdirs :=
+subdirs := test
 
 # We make all targets depend on the Makefiles themselves.
 global_deps = Makefile Makefile.config Makefile.local \
index cb73ab2ed231a34abe48696298949650105d13d4..7e17ff3753935b19921b956793b49b209427b6c7 100644 (file)
@@ -39,10 +39,6 @@ ifeq ($(shell cat .first-build-message 2>/dev/null),)
 endif
 endif
 
-.PHONY: test
-test:
-       @echo "FIXME: Should consider adding a test suite here."
-
 # The user has not set any verbosity, default to quiet mode and inform the
 # user how to enable verbose compiles.
 ifeq ($(V),)
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644 (file)
index 0000000..c1f0a2a
--- /dev/null
@@ -0,0 +1 @@
+glx-link-call
diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..6a07a4b
--- /dev/null
@@ -0,0 +1,11 @@
+# See Makefile.local for the actual compilation rules for this directory.
+
+# Prefer to build "test" target by default, (which depends on
+# top-level all), so that when running "make" from the test directory
+# the test programs will actually by compiled.
+
+all:
+       $(MAKE) -C .. all
+
+.DEFAULT:
+       $(MAKE) -C .. $@
\ No newline at end of file
diff --git a/test/Makefile.local b/test/Makefile.local
new file mode 100644 (file)
index 0000000..b40ee28
--- /dev/null
@@ -0,0 +1,29 @@
+# -*- makefile -*-
+
+dir := test
+
+extra_cflags += -I. $(GL_CFLAGS) $(X11_CFLAGS)
+
+test_programs =
+
+ifeq ($(HAVE_X11),Yes)
+test_programs += $(dir)/glx-link-call
+endif
+
+glx_link_call_srcs = \
+       $(dir)/glx-link-call.c \
+       $(dir)/util.c
+
+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 $@
+
+test: all $(test_programs)
+       @${dir}/fips-test
+
+check: test
+
+SRCS := $(SRCS) $(glx_link_call_srcs)
+
+CLEAN += $(test_programs) $(glx_link_call_modules)
diff --git a/test/fips-test b/test/fips-test
new file mode 100755 (executable)
index 0000000..cada79b
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+dir=$(dirname "$0")
+
+tests=0
+errors=0
+
+test ()
+{
+    script="$1"
+
+    tests=$((tests + 1))
+
+    if ./fips -v "${dir}/${script}" | grep -q "fips: terminating"; then
+       printf "PASS\n"
+    else
+       printf "FAIL\n"
+       errors=$((errors + 1))
+    fi
+}
+
+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 "Testing                GLX     link to libGL   direct calls ... "
+test glx-link-call
+
+echo ""
+
+if [ $errors -gt 0 ]; then
+    echo "Error: $errors/$tests tests failed."
+    exit 1
+else
+    echo "All $tests tests passed."
+    exit 0
+fi
+
diff --git a/test/glx-link-call.c b/test/glx-link-call.c
new file mode 100644 (file)
index 0000000..0c5047e
--- /dev/null
@@ -0,0 +1,141 @@
+/* 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 directly calling OpenGL functions
+ */
+
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+#include <GL/glx.h>
+
+#include "util.h"
+
+static void
+set_2d_projection (int width, int height)
+{
+       glMatrixMode (GL_PROJECTION);
+       glLoadIdentity ();
+       glOrtho (0, width, height, 0, 0, 1);
+       glMatrixMode (GL_MODELVIEW);
+}
+
+static void
+paint_rgb_using_clear (double r, double g, double b)
+{
+        glClearColor(r, g, b, 1.0);
+        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 = glXChooseVisual(dpy, 0, visual_attr);
+        GLXContext ctx = glXCreateContext(dpy, visual_info, NULL, True);
+        glXMakeCurrent(dpy, window, ctx);
+
+        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));
+               glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (yellow) frame */
+               paint_rgb_using_clear (RGB(frame));
+               glXSwapBuffers (dpy, window);
+               frame++;
+
+               /* Frame: Draw a solid (cyan) frame */
+               paint_rgb_using_clear (RGB(frame));
+               glXSwapBuffers (dpy, window);
+               frame++;
+       }
+
+       /* Cleanup */
+        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;
+                }
+        }
+}
+
+int
+main (void)
+{
+        Display *dpy;
+        Window window;
+
+       util_init_display_window (&dpy, &window);
+
+        handle_events (dpy, window);
+
+       util_fini_display_window (dpy, window);
+
+        return 0;
+}
diff --git a/test/util.c b/test/util.c
new file mode 100644 (file)
index 0000000..3bd13f6
--- /dev/null
@@ -0,0 +1,58 @@
+/* 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "util.h"
+
+void
+util_init_display_window (Display **dpy, Window *window)
+{
+       int width = 64;
+       int height = 64;
+
+        *dpy = XOpenDisplay (NULL);
+
+        if (*dpy == NULL) {
+                fprintf(stderr, "Failed to open display %s\n",
+                        XDisplayName(NULL));
+                exit (1);
+        }
+
+        *window = XCreateSimpleWindow(*dpy, DefaultRootWindow (*dpy),
+                                     0, 0, width, height, 0,
+                                     BlackPixel (*dpy, DefaultScreen (*dpy)),
+                                     BlackPixel (*dpy, DefaultScreen (*dpy)));
+
+        XSelectInput(*dpy, *window,
+                     KeyPressMask | StructureNotifyMask | ExposureMask);
+
+        XMapWindow (*dpy, *window);
+
+}
+
+void
+util_fini_display_window (Display *dpy, Window window)
+{
+        XDestroyWindow (dpy, window);
+        XCloseDisplay (dpy);
+}
diff --git a/test/util.h b/test/util.h
new file mode 100644 (file)
index 0000000..f795a00
--- /dev/null
@@ -0,0 +1,36 @@
+/* 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.
+ */
+
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <X11/Xlib.h>
+
+void
+util_init_display_window (Display **dpy, Window *window);
+
+void
+util_fini_display_window (Display *dpy, Window window);
+
+#endif /* UTIL_H */
+
+
+