tests: Update EGL test helpers to match the new EGL dummy vendor functions.

Updated egl_test_utils.c/h to include the new eglTestReturnDevice function.

Added functions to egl_test_utils.c/h to load each vendor's DummySetDeviceCount
function using dlopen+dlsym.
This commit is contained in:
Kyle Brenneman 2021-02-11 11:48:49 -07:00
parent 6d43e9bac5
commit 01316ea91d
4 changed files with 80 additions and 7 deletions

View File

@ -185,32 +185,32 @@ check_PROGRAMS += testegldisplay
testegldisplay_SOURCES = \
testegldisplay.c \
egl_test_utils.c
testegldisplay_LDADD = $(top_builddir)/src/EGL/libEGL.la
testegldisplay_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
check_PROGRAMS += testegldevice
testegldevice_SOURCES = \
testegldevice.c \
egl_test_utils.c
testegldevice_LDADD = $(top_builddir)/src/EGL/libEGL.la
testegldevice_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
check_PROGRAMS += testeglgetprocaddress
testeglgetprocaddress_SOURCES = \
testeglgetprocaddress.c \
egl_test_utils.c
testeglgetprocaddress_LDADD = $(top_builddir)/src/EGL/libEGL.la
testeglgetprocaddress_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
check_PROGRAMS += testeglmakecurrent
testeglmakecurrent_SOURCES = \
testeglmakecurrent.c \
egl_test_utils.c
testeglmakecurrent_LDADD = $(top_builddir)/src/EGL/libEGL.la
testeglmakecurrent_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
testeglmakecurrent_LDADD += $(top_builddir)/src/OpenGL/libOpenGL.la
check_PROGRAMS += testeglerror
testeglerror_SOURCES = \
testeglerror.c \
egl_test_utils.c
testeglerror_LDADD = $(top_builddir)/src/EGL/libEGL.la
testeglerror_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
testeglerror_LDADD += $(top_builddir)/src/OpenGL/libOpenGL.la
@ -218,7 +218,7 @@ check_PROGRAMS += testegldebug
testegldebug_SOURCES = \
testegldebug.c \
egl_test_utils.c
testegldebug_LDADD = $(top_builddir)/src/EGL/libEGL.la
testegldebug_LDADD = $(top_builddir)/src/EGL/libEGL.la @LIB_DL@
endif # ENABLE_EGL

View File

@ -2,6 +2,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
const char *DUMMY_VENDOR_NAMES[DUMMY_VENDOR_COUNT] = {
DUMMY_VENDOR_NAME_0,
@ -16,6 +18,10 @@ PFNEGLLABELOBJECTKHRPROC ptr_eglLabelObjectKHR;
pfn_eglTestDispatchDisplay ptr_eglTestDispatchDisplay;
pfn_eglTestDispatchDevice ptr_eglTestDispatchDevice;
pfn_eglTestDispatchCurrent ptr_eglTestDispatchCurrent;
pfn_eglTestReturnDevice ptr_eglTestReturnDevice;
static void *dummyVendorHandles[DUMMY_VENDOR_COUNT] = {};
DummyVendorFunctions dummyFuncs[DUMMY_VENDOR_COUNT] = {};
__eglMustCastToProperFunctionPointerType loadEGLFunction(const char *name)
{
@ -44,5 +50,50 @@ void loadEGLExtensions(void)
loadEGLFunction("eglTestDispatchDevice");
ptr_eglTestDispatchCurrent = (pfn_eglTestDispatchCurrent)
loadEGLFunction("eglTestDispatchCurrent");
ptr_eglTestReturnDevice = (pfn_eglTestReturnDevice)
loadEGLFunction("eglTestReturnDevice");
}
void loadDummyVendorExtensions(void)
{
int i;
for (i=0; i<DUMMY_VENDOR_COUNT; i++)
{
if (dummyVendorHandles[i] == NULL)
{
char filename[128];
snprintf(filename, sizeof(filename), "libEGL_%s.so.0", DUMMY_VENDOR_NAMES[i]);
dummyVendorHandles[i] = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
if (dummyVendorHandles[i] == NULL)
{
printf("Failed to load %s: %s\n", filename, dlerror());
abort();
}
dummyFuncs[i].SetDeviceCount = dlsym(dummyVendorHandles[i], "DummySetDeviceCount");
if (dummyFuncs[i].SetDeviceCount == NULL)
{
printf("Can't load DummySetDeviceCount from %s\n", filename);
abort();
}
}
}
}
void cleanupDummyVendorExtensions(void)
{
int i;
for (i=0; i<DUMMY_VENDOR_COUNT; i++)
{
if (dummyVendorHandles[i] != NULL)
{
dlclose(dummyVendorHandles[i]);
dummyVendorHandles[i] = NULL;
}
}
memset(&dummyFuncs, 0, sizeof(dummyFuncs));
}

View File

@ -41,6 +41,15 @@
*/
#define DUMMY_TOTAL_DEVICE_COUNT (DUMMY_VENDOR_COUNT * DUMMY_EGL_DEVICE_COUNT)
/**
* Functions that are exported directly from a vendor library, rather than
* being accessed through eglGetProcAddress.
*/
typedef struct
{
pfn_DummySetDeviceCount SetDeviceCount;
} DummyVendorFunctions;
extern const char *DUMMY_VENDOR_NAMES[DUMMY_VENDOR_COUNT];
extern PFNEGLQUERYDEVICESEXTPROC ptr_eglQueryDevicesEXT;
@ -51,6 +60,9 @@ extern PFNEGLLABELOBJECTKHRPROC ptr_eglLabelObjectKHR;
extern pfn_eglTestDispatchDisplay ptr_eglTestDispatchDisplay;
extern pfn_eglTestDispatchDevice ptr_eglTestDispatchDevice;
extern pfn_eglTestDispatchCurrent ptr_eglTestDispatchCurrent;
extern pfn_eglTestReturnDevice ptr_eglTestReturnDevice;
extern DummyVendorFunctions dummyFuncs[DUMMY_VENDOR_COUNT];
/**
* Loads an EGL extension function with eglGetProcAddress. If it fails, then it
@ -64,4 +76,14 @@ __eglMustCastToProperFunctionPointerType loadEGLFunction(const char *name);
*/
void loadEGLExtensions(void);
/**
* Loads the additional functions exported by the dummy vendor libraries.
*/
void loadDummyVendorExtensions(void);
/**
* Frees up any memory allocated by loadDummyVendorExtensions.
*/
void cleanupDummyVendorExtensions(void);
#endif // EGL_TEST_UTILS_H

View File

@ -208,7 +208,7 @@ if get_option('egl')
['test@0@.c'.format(t[0]), 'egl_test_utils.c'],
include_directories : [inc_include],
link_with : [libEGL, t[1]],
dependencies : [t[2]],
dependencies : [dep_dl, t[2]],
),
env : env_egl,
suite : ['egl'],