summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Nguyen <brnguyen@nvidia.com>2014-01-23 20:11:40 -0800
committerbrnguyen <brnguyen@nvidia.com>2014-01-23 20:28:50 -0800
commit171fa7481f2966f0e5e03563cd96f26c6e151c1b (patch)
tree4a70189ea25d33df08f23bc590740da32e459820
parenta0221d1ad6b9d62b0e5d6a95e60e475fd61f4e22 (diff)
Add testpatchentrypoints unit test
This unit test verifies that entrypoint patching works as expected, by loading libGLX_patchentry.so, looking up the address of __glXSawVertex3fv defined in libGLX_patchentry.so, and verifying that the value at this symbol matches the number of calls to glVertex3fv() (which is hacked to increment __glXSawVertex3fv via entrypoint rewriting).
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/testpatchentrypoints.c100
-rwxr-xr-xtests/testpatchentrypoints.sh7
3 files changed, 118 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 190a1a9..63dc369 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ TESTS = \
testglxqueryversion.sh \
testglxnscreens.sh \
testglxnscrthreads.sh \
+ testpatchentrypoints.sh \
fini_test_env.sh
EXTRA_DIST = $(TESTS)
@@ -59,6 +60,7 @@ check_PROGRAMS = \
testx11glvndproto \
testglxgetclientstr \
testglxqueryversion \
+ testpatchentrypoints \
testglxnscreens
testglxnscreens_SOURCES = \
@@ -123,3 +125,12 @@ testglxqueryversion_LDADD = -lX11
testglxqueryversion_LDADD += $(top_builddir)/src/GLX/libGLX.la
testglxqueryversion_LDADD += $(top_builddir)/src/OpenGL/libOpenGL.la
testglxqueryversion_LDADD += $(top_builddir)/src/util/trace/libtrace.la
+
+testpatchentrypoints_SOURCES = \
+ testpatchentrypoints.c \
+ test_utils.c
+
+testpatchentrypoints_LDADD = -lX11 -ldl
+testpatchentrypoints_LDADD += $(top_builddir)/src/GLX/libGLX.la
+testpatchentrypoints_LDADD += $(top_builddir)/src/OpenGL/libOpenGL.la
+testpatchentrypoints_LDADD += $(top_builddir)/src/util/trace/libtrace.la
diff --git a/tests/testpatchentrypoints.c b/tests/testpatchentrypoints.c
new file mode 100644
index 0000000..59ba045
--- /dev/null
+++ b/tests/testpatchentrypoints.c
@@ -0,0 +1,100 @@
+#define _GNU_SOURCE 1
+
+#include <string.h>
+#include <X11/X.h>
+#include <GL/gl.h>
+#include <dlfcn.h>
+#include "test_utils.h"
+
+#define NUM_VERTEX3FV_CALLS 100
+
+int main(int argc, char **argv)
+{
+ struct window_info wi;
+ Display *dpy = XOpenDisplay(NULL);
+ int sawVertex3fv1, sawVertex3fv2, *pSawVertex3fv;
+ int i;
+ int ret = 1;
+ GLXContext ctx = None;
+ void *vendorHandle;
+
+ if (!dpy) {
+ printError("No display!\n");
+ goto fail;
+ }
+
+ memset(&wi, 0, sizeof(wi));
+
+ if (!testUtilsCreateWindow(dpy, &wi, 0)) {
+ printError("Failed to create window!\n");
+ goto fail;
+ }
+
+ ctx = glXCreateContext(dpy, wi.visinfo, NULL, GL_TRUE);
+ if (!ctx) {
+ printError("Failed to create a context!\n");
+ goto fail;
+ }
+
+ if (!glXMakeContextCurrent(dpy, wi.win, wi.win, ctx)) {
+ printError("Failed to make current\n");
+ goto fail;
+ }
+
+ vendorHandle = dlopen("libGLX_patchentry.so", RTLD_LAZY);
+ if (!vendorHandle) {
+ printError("No valid vendor library handle\n");
+ goto fail;
+ }
+
+ pSawVertex3fv = (int *)dlsym(vendorHandle, "__glXSawVertex3fv");
+ if (!pSawVertex3fv) {
+ printError("Could not find __glXSawVertex3fv\n");
+ goto fail;
+ }
+
+ for (i = 0; i < NUM_VERTEX3FV_CALLS; i++) {
+ glVertex3fv(NULL);
+ }
+
+ // Read the resulting value
+ sawVertex3fv1 = *pSawVertex3fv;
+
+ if (!glXMakeContextCurrent(dpy, None, None, NULL)) {
+ printError("Could not lose current\n");
+ goto fail;
+ }
+
+ // Read again. The NOP stubs should be restored by libglvnd
+ for (i = 0; i < NUM_VERTEX3FV_CALLS; i++) {
+ glVertex3fv(NULL);
+ }
+
+ sawVertex3fv2 = *pSawVertex3fv;
+
+ dlclose(vendorHandle);
+ pSawVertex3fv = NULL;
+
+ if (sawVertex3fv1 != NUM_VERTEX3FV_CALLS) {
+ printError("sawVertex3fv1 mismatch: expected %d, got %d\n",
+ NUM_VERTEX3FV_CALLS, sawVertex3fv1);
+ goto fail;
+ }
+
+ if (sawVertex3fv2 != sawVertex3fv1) {
+ printError("sawVertex3fv2 mismatch: expected %d, got %d\n",
+ NUM_VERTEX3FV_CALLS, sawVertex3fv2);
+ goto fail;
+ }
+
+ ret = 0;
+
+fail:
+ if (ctx) {
+ glXDestroyContext(dpy, ctx);
+ }
+
+ testUtilsDestroyWindow(dpy, &wi);
+
+ return ret;
+}
diff --git a/tests/testpatchentrypoints.sh b/tests/testpatchentrypoints.sh
new file mode 100755
index 0000000..fcd2b81
--- /dev/null
+++ b/tests/testpatchentrypoints.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+export __GLX_VENDOR_LIBRARY_NAME=patchentry
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TOP_BUILDDIR/tests/GLX_dummy/.libs
+
+# Run the patch entrypoint test.
+./testpatchentrypoints