From 596d4628e65be5d7a62c3434b8e69b9e6dbb71c7 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 24 Nov 2008 15:44:16 +0000 Subject: [PATCH] Add a wrapper library to help testing without NPOTs. * tests/tools/Makefile.am: Optionally build the libdisable-npots.la library depending on whether libdl was detected in the configure script. A helper script is also generated to setup the LD_PRELOAD. * tests/conform/Makefile.am: There are now two versions of the test-report and full-report rules. test-report-normal is the same as before and test-report-disable-npots runs the tests with the disable-npots wrapper script. The full-report rule runs both of them and displays two separate HTML files. The test-report rule just runs the normal version as before. * configure.ac: Add a test for libdl * tests/tools/disable-npots.sh.in: New file. Template for the helper script * tests/tools/disable-npots.c: New file --- .gitignore | 3 ++ ChangeLog | 23 +++++++++ configure.ac | 5 ++ tests/conform/Makefile.am | 55 ++++++++++++++++++--- tests/tools/Makefile.am | 22 ++++++++- tests/tools/disable-npots.c | 84 +++++++++++++++++++++++++++++++++ tests/tools/disable-npots.sh.in | 15 ++++++ 7 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 tests/tools/disable-npots.c create mode 100644 tests/tools/disable-npots.sh.in diff --git a/.gitignore b/.gitignore index e07d6bb6e..df7d68b4d 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,8 @@ stamp-h1 /tests/conform/test-conformance /tests/conform/test-conformance-results.xml /tests/conform/test-conformance-results.html +/tests/conform/test-conformance-results-dn.xml +/tests/conform/test-conformance-results-dn.html /tests/conform/test_entry_append_some /tests/conform/test_entry_cursor /tests/conform/test_entry_delete_chars @@ -147,6 +149,7 @@ stamp-h1 /tests/conform/test_paint_opacity /tests/conform/test_rectangle_opacity /tests/micro-bench/test-text +/tests/tools/disable-npots.sh /clutter/x11/clutter-x11-enum-types.[ch] /clutter/x11/stamp-clutter-x11-enum-types.h /po/Makefile.in.in diff --git a/ChangeLog b/ChangeLog index 04ca5662e..9b2e0897b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2008-11-24 Neil Roberts + + Add a wrapper library to help testing without NPOTs. + + * tests/tools/Makefile.am: Optionally build the + libdisable-npots.la library depending on whether libdl was + detected in the configure script. A helper script is also + generated to setup the LD_PRELOAD. + + * tests/conform/Makefile.am: There are now two versions of the + test-report and full-report rules. test-report-normal is the same + as before and test-report-disable-npots runs the tests with the + disable-npots wrapper script. The full-report rule runs both of + them and displays two separate HTML files. The test-report rule + just runs the normal version as before. + + * configure.ac: Add a test for libdl + + * tests/tools/disable-npots.sh.in: New file. Template for the + helper script + + * tests/tools/disable-npots.c: New file + 2008-11-24 Neil Roberts * clutter/cogl/gl/cogl-texture.c (cogl_texture_polygon): Fix the diff --git a/configure.ac b/configure.ac index 9ac8920ea..45c3db9e2 100644 --- a/configure.ac +++ b/configure.ac @@ -242,6 +242,11 @@ if test "x$xinput" = "xyes"; then X11_LIBS="$X11_LIBS -lXi" fi +dnl This is only used to decide whether to build +dnl tests/tools/disable-npots.la +AC_CHECK_LIB(dl, dlopen, HAVE_LIBDL=yes, HAVE_LIBDL=no) +AM_CONDITIONAL(HAVE_LIBDL, test "x$HAVE_LIBDL" != "xno") + clutter_gl_header="" use_gles2_wrapper="no" diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 2579b417e..c71242c71 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -39,19 +39,62 @@ test_conformance_CFLAGS = \ $(CLUTTER_CFLAGS) test_conformance_LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la -.PHONY: test test-report full-report +.PHONY: test +.PHONY: test-report test-report-normal test-report-disable-npots +.PHONY: full-report full-report-normal full-report-disable-npots +.PHONY: full-report-generate + test: gtester -o=test-conformance-results.xml ./test-conformance -test-report: +test-report-normal: gtester -o=test-conformance-results.xml -k ./test-conformance \ - && gtester-report test-conformance-results.xml > test-conformance-results.html \ + && ( gtester-report test-conformance-results.xml \ + | sed 's/>GTester Unit Test ReportGTester Unit Test Report (normal) test-conformance-results.html ) \ && gnome-open ./test-conformance-results.html -full-report: +test-report-disable-npots: + ../tools/disable-npots.sh \ + gtester -o=test-conformance-results-dn.xml -k ./test-conformance \ + && ( gtester-report test-conformance-results-dn.xml \ + | sed 's/>GTester Unit Test ReportGTester Unit Test Report (no NPOTs) test-conformance-results-dn.html ) \ + && gnome-open ./test-conformance-results-dn.html + +test-report: test-report-normal + +full-report-normal: gtester -o=test-conformance-results.xml -k -m=slow ./test-conformance \ - && gtester-report test-conformance-results.xml > test-conformance-results.html \ - && gnome-open ./test-conformance-results.html + && ( gtester-report test-conformance-results.xml \ + | sed 's/>GTester Unit Test ReportGTester Unit Test Report (normal) test-conformance-results.html ) + +full-report-disable-npots: + ../tools/disable-npots.sh \ + gtester -o=test-conformance-results-dn.xml -k -m=slow ./test-conformance \ + && ( gtester-report test-conformance-results-dn.xml \ + | sed 's/>GTester Unit Test ReportGTester Unit Test Report (no NPOTs) test-conformance-results-dn.html ) + +REPORTS = test-conformance-results.html + +if HAVE_LIBDL + +REPORTS += test-conformance-results-dn.html + +full-report-generate: full-report-normal full-report-disable-npots + +else + +full-report-generate: full-report-normal + +endif + +full-report: full-report-generate + for x in $(REPORTS); do \ + gnome-open "$$x"; \ + done EXTRA_DIST = ADDING_NEW_TESTS diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index 93d6c488e..af5efce4d 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -1,2 +1,22 @@ +lib_LTLIBRARIES = -EXTRA_DIST = README +if HAVE_LIBDL + +lib_LTLIBRARIES += libdisable-npots.la + +endif + +libdisable_npots_la_SOURCES = disable-npots.c + +libdisable_npots_la_LIBADD = -ldl + +all-local : disable-npots.sh + +clean-local : + rm -f disable-npots.sh + +disable-npots.sh : $(top_builddir)/tests/tools/disable-npots.sh.in + sed 's|--builddir--|'`cd '$(top_builddir)' && pwd`'|' < $< > $@ && \ + chmod 755 disable-npots.sh + +EXTRA_DIST = README disable-npots.sh.in diff --git a/tests/tools/disable-npots.c b/tests/tools/disable-npots.c new file mode 100644 index 000000000..baa1f5778 --- /dev/null +++ b/tests/tools/disable-npots.c @@ -0,0 +1,84 @@ +/* + * This file can be build as a shared library and then used as an + * LD_PRELOAD to fake a system where NPOTs is not supported. It simply + * overrides glGetString and removes the extension strings. + */ + +#include +#include +#include +#include +#include +#include + +typedef const GLubyte * (* GetStringFunc) (GLenum name); + +static const char * const bad_strings[] += { "GL_ARB_texture_non_power_of_two", + "GL_ARB_texture_rectangle", + "GL_EXT_texture_rectangle", + NULL }; + +const GLubyte * +glGetString (GLenum name) +{ + const GLubyte *ret = NULL; + static void *gl_lib = NULL; + static GetStringFunc func = NULL; + static GLubyte *extensions = NULL; + + if (gl_lib == NULL + && (gl_lib = dlopen ("libGL.so", RTLD_LAZY)) == NULL) + fprintf (stderr, "dlopen: %s\n", dlerror ()); + else if (func == NULL + && (func = (GetStringFunc) dlsym (gl_lib, "glGetString")) == NULL) + fprintf (stderr, "dlsym: %s\n", dlerror ()); + else + { + ret = (* func) (name); + + if (name == GL_EXTENSIONS) + { + if (extensions == NULL) + { + if ((extensions = (GLubyte *) strdup ((char *) ret)) == NULL) + fprintf (stderr, "strdup: %s\n", strerror (errno)); + else + { + GLubyte *dst = extensions, *src = extensions; + + while (1) + { + const char * const *str = bad_strings; + GLubyte *end; + + while (isspace (*src)) + *(dst++) = *(src++); + + if (*src == 0) + break; + + for (end = src + 1; *end && !isspace (*end); end++); + + while (*str && strncmp ((char *) src, *str, end - src)) + str++; + + if (*str == NULL) + { + memcpy (dst, src, end - src); + dst += end - src; + } + + src = end; + } + + *dst = '\0'; + } + } + + ret = extensions; + } + } + + return ret; +} diff --git a/tests/tools/disable-npots.sh.in b/tests/tools/disable-npots.sh.in new file mode 100644 index 000000000..cde4912f0 --- /dev/null +++ b/tests/tools/disable-npots.sh.in @@ -0,0 +1,15 @@ +#!/bin/sh + +# This script sets up the LD_PRELOAD environment to use +# libdisable-npots.la + +# Read the .la file so we can get the library name +. "--builddir--/tests/tools/libdisable-npots.la" + +if test -n "$LD_PRELOAD"; then + LD_PRELOAD="${LD_PRELOAD}:"; +fi + +export LD_PRELOAD="${LD_PRELOAD}--builddir--/tests/tools/.libs/${dlname}" + +exec "$@"