tests: Add tests for the multithreaded path in libGLdispatch

This is important for testing the TSD stubs, which have a separate fast path
for single-threaded programs.

The TSD stubs start with a simple global variable to hold the dispatch table
so that a single-threaded program doesn't have to deal with the overhead of
calling pthread_getspecific. When a second thread comes along, it sets that
variable to NULL, which makes the stubs call pthread_getspecific instead.

This change adds a flag to the testgldispatch test program that tells it to
call into libGLdispatch from two threads to force it into its multi-threaded
mode.

It also adds three new test scripts, which are the same testgldispatch tests
but for the multithreaded path.
This commit is contained in:
Kyle Brenneman 2018-09-19 15:40:59 -06:00
parent ff9246a97f
commit bed48a107c
5 changed files with 41 additions and 2 deletions

View File

@ -57,18 +57,23 @@ AM_CFLAGS = \
TESTS += testgldispatch_static.sh
TESTS += testgldispatch_static_thr.sh
TESTS += testgldispatch_generated.sh
TESTS += testgldispatch_generated_thr.sh
TESTS += testgldispatch_patched.sh
TESTS += testgldispatch_patched_thr.sh
check_PROGRAMS += testgldispatch
testgldispatch_SOURCES = \
testgldispatch.c
testgldispatch_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/GLdispatch
-I$(top_srcdir)/src/GLdispatch \
$(PTHREAD_CFLAGS)
testgldispatch_LDADD = $(top_builddir)/src/GLdispatch/libGLdispatch.la
testgldispatch_LDADD += $(top_builddir)/src/OpenGL/libOpenGL.la
testgldispatch_LDADD += dummy/libpatchentrypoints.la
testgldispatch_LDADD += $(top_builddir)/src/util/libutils_misc.la
testgldispatch_LDADD += $(PTHREAD_LIBS)
# Start of GLX-specific tests.
# Notes that the TESTS_GLX variable must be defined outside the conditional, so

View File

@ -31,6 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <pthread.h>
#include <GL/gl.h>
#include <GLdispatch.h>
@ -68,6 +69,8 @@ typedef struct DummyVendorLibRec {
static void InitDummyVendors(void);
static void CleanupDummyVendors(void);
static void *ForceMultiThreadedProc(void *param);
static GLboolean TestDispatch(int vendorIndex,
GLboolean testStatic, GLboolean testGenerated);
@ -103,13 +106,14 @@ static pfn_glVertex3fv ptr_glDummyTestProc;
static GLboolean enableStaticTest = GL_FALSE;
static GLboolean enableGeneratedTest = GL_FALSE;
static GLboolean enablePatching = GL_FALSE;
static GLboolean forceMultiThreaded = GL_FALSE;
int main(int argc, char **argv)
{
int i;
while (1) {
int opt = getopt(argc, argv, "sgp");
int opt = getopt(argc, argv, "sgpt");
if (opt == -1) {
break;
}
@ -123,6 +127,9 @@ int main(int argc, char **argv)
case 'p':
enablePatching = GL_TRUE;
break;
case 't':
forceMultiThreaded = GL_TRUE;
break;
default:
return 1;
}
@ -131,6 +138,15 @@ int main(int argc, char **argv)
__glDispatchInit();
InitDummyVendors();
if (forceMultiThreaded) {
pthread_t thr;
printf("Forcing libGLdispatch into multi-threaded mode.\n");
__glDispatchCheckMultithreaded();
pthread_create(&thr, NULL, ForceMultiThreadedProc, NULL);
pthread_join(thr, NULL);
}
ptr_glVertex3fv = (pfn_glVertex3fv) __glDispatchGetProcAddress("glVertex3fv");
if (ptr_glVertex3fv == NULL) {
printf("Can't find dispatch function for glVertex3fv\n");
@ -154,6 +170,12 @@ int main(int argc, char **argv)
return 0;
}
static void *ForceMultiThreadedProc(void *param)
{
__glDispatchCheckMultithreaded();
return NULL;
}
static void InitDummyVendors(void)
{
int i;

View File

@ -0,0 +1,4 @@
#!/bin/sh
./testgldispatch -g -t

View File

@ -0,0 +1,4 @@
#!/bin/sh
./testgldispatch -s -g -p

View File

@ -0,0 +1,4 @@
#!/bin/sh
./testgldispatch -s -t