Blame tests/testpatchentrypoints.c

Packit 5af8b3
#define _GNU_SOURCE 1
Packit 5af8b3
Packit 5af8b3
#include <string.h>
Packit 5af8b3
#include <X11/X.h>
Packit 5af8b3
#include <GL/gl.h>
Packit 5af8b3
#include <dlfcn.h>
Packit 5af8b3
#include "test_utils.h"
Packit 5af8b3
Packit 5af8b3
#define NUM_VERTEX3FV_CALLS 100
Packit 5af8b3
Packit 5af8b3
int main(int argc, char **argv)
Packit 5af8b3
{
Packit 5af8b3
    struct window_info wi;
Packit 5af8b3
    Display *dpy = XOpenDisplay(NULL);
Packit 5af8b3
    int sawVertex3fv1, *pSawVertex3fv;
Packit 5af8b3
    int i;
Packit 5af8b3
    int ret = 1;
Packit 5af8b3
    GLXContext ctx = None;
Packit 5af8b3
    void *vendorHandle;
Packit 5af8b3
Packit 5af8b3
    if (!dpy) {
Packit 5af8b3
        printError("No display!\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    memset(&wi, 0, sizeof(wi));
Packit 5af8b3
Packit 5af8b3
    if (!testUtilsCreateWindow(dpy, &wi, 0)) {
Packit 5af8b3
        printError("Failed to create window!\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    ctx = glXCreateContext(dpy, wi.visinfo, NULL, GL_TRUE);
Packit 5af8b3
    if (!ctx) {
Packit 5af8b3
        printError("Failed to create a context!\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    if (!glXMakeContextCurrent(dpy, wi.win, wi.win, ctx)) {
Packit 5af8b3
        printError("Failed to make current\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    vendorHandle = dlopen("libGLX_dummy.so", RTLD_LAZY);
Packit 5af8b3
    if (!vendorHandle) {
Packit 5af8b3
        printError("No valid vendor library handle\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    pSawVertex3fv = (int *)dlsym(vendorHandle, "__glXSawVertex3fv");
Packit 5af8b3
    if (!pSawVertex3fv) {
Packit 5af8b3
        printError("Could not find __glXSawVertex3fv\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    for (i = 0; i < NUM_VERTEX3FV_CALLS; i++) {
Packit 5af8b3
        glVertex3fv(NULL);
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    // Read the resulting value
Packit 5af8b3
    sawVertex3fv1 = *pSawVertex3fv;
Packit 5af8b3
Packit 5af8b3
    if (!glXMakeContextCurrent(dpy, None, None, NULL)) {
Packit 5af8b3
        printError("Could not lose current\n");
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    dlclose(vendorHandle);
Packit 5af8b3
    pSawVertex3fv = NULL;
Packit 5af8b3
Packit 5af8b3
    if (sawVertex3fv1 != NUM_VERTEX3FV_CALLS) {
Packit 5af8b3
        printError("sawVertex3fv1 mismatch: expected %d, got %d\n",
Packit 5af8b3
                   NUM_VERTEX3FV_CALLS, sawVertex3fv1);
Packit 5af8b3
        goto fail;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    ret = 0;
Packit 5af8b3
Packit 5af8b3
fail:
Packit 5af8b3
    if (ctx) {
Packit 5af8b3
        glXDestroyContext(dpy, ctx);
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    testUtilsDestroyWindow(dpy, &wi;;
Packit 5af8b3
Packit 5af8b3
    return ret;
Packit 5af8b3
}