From bb94003b78d9bf533d89ead5f630e364261ca5a6 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 8 Apr 2014 23:47:25 -0700 Subject: [PATCH] Add a test for a failure I found with the X Server after my last fixes. --- test/.gitignore | 1 + test/Makefile.am | 4 ++ test/egl_gl.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 test/egl_gl.c diff --git a/test/.gitignore b/test/.gitignore index 4a0d22f..78919f3 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -2,6 +2,7 @@ egl_and_glx_different_pointers_egl egl_and_glx_different_pointers_egl_glx egl_and_glx_different_pointers_glx egl_has_extension_nocontext +egl_gl egl_gles1_without_glx egl_gles2_without_glx glx_alias_prefer_same_name diff --git a/test/Makefile.am b/test/Makefile.am index 7e43dd7..a647b8e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -63,6 +63,7 @@ TESTS = \ check_BINARIES = $(EGL_AND_GLX_BIN) XFAIL_TESTS = \ + egl_gl \ egl_and_glx_different_pointers_egl_glx \ $() @@ -71,6 +72,7 @@ check_PROGRAMS = $(TESTS) if BUILD_EGL EGL_TESTS = \ egl_has_extension_nocontext \ + egl_gl \ egl_gles1_without_glx \ egl_gles2_without_glx \ $() @@ -129,6 +131,8 @@ endif egl_has_extension_nocontext_LDADD = $(EPOXY) libegl_common.la $(X11_LIBS) +egl_gl_LDADD = $(EPOXY) $(DLOPEN_LIBS) libegl_common.la $(X11_LIBS) + egl_gles1_without_glx_CPPFLAGS = $(AM_CPPFLAGS) -DGLES_VERSION=1 egl_gles1_without_glx_SOURCES = egl_without_glx.c egl_gles1_without_glx_LDADD = $(EPOXY) $(DLOPEN_LIBS) libegl_common.la $(X11_LIBS) diff --git a/test/egl_gl.c b/test/egl_gl.c new file mode 100644 index 0000000..c3fb3c2 --- /dev/null +++ b/test/egl_gl.c @@ -0,0 +1,130 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * @file egl_gl.c + * + * Tests that epoxy works with EGL using desktop OpenGL. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include "epoxy/gl.h" +#include "epoxy/egl.h" +#include "epoxy/glx.h" + +#include "egl_common.h" +#include "glx_common.h" +#include "dlwrap.h" + +static bool +make_egl_current_and_test(EGLDisplay *dpy, EGLContext ctx) +{ + const char *string; + GLuint shader; + bool pass = true; + + eglMakeCurrent(dpy, NULL, NULL, ctx); + + if (!epoxy_is_desktop_gl()) { + fprintf(stderr, "Claimed to be desktop\n"); + pass = false; + } + + if (epoxy_gl_version() < 20) { + fprintf(stderr, "Claimed to be GL version %d\n", + epoxy_gl_version()); + pass = false; + } + + string = (const char *)glGetString(GL_VERSION); + printf("GL version: %s\n", string); + + shader = glCreateShader(GL_FRAGMENT_SHADER); + pass = glIsShader(shader); + + return pass; +} + +static void +init_egl(EGLDisplay **out_dpy, EGLContext *out_ctx) +{ + EGLDisplay *dpy = get_egl_display_or_skip(); + static const EGLint config_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE + }; + static const EGLint context_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLContext ctx; + EGLConfig cfg; + EGLint count; + + if (!epoxy_has_egl_extension(dpy, "EGL_KHR_surfaceless_context")) + errx(77, "Test requires EGL_KHR_surfaceless_context"); + + if (!eglBindAPI(EGL_OPENGL_API)) + errx(77, "Couldn't initialize EGL with desktop GL\n"); + + if (!eglChooseConfig(dpy, config_attribs, &cfg, 1, &count)) + errx(77, "Couldn't get an EGLConfig\n"); + + ctx = eglCreateContext(dpy, cfg, NULL, context_attribs); + if (!ctx) + errx(77, "Couldn't create a GL context\n"); + + *out_dpy = dpy; + *out_ctx = ctx; +} + +int +main(int argc, char **argv) +{ + bool pass = true; + EGLDisplay *egl_dpy; + EGLContext egl_ctx; + + /* Force epoxy to have loaded both EGL and GLX libs already -- we + * can't assume anything about symbol resolution based on having + * EGL or GLX loaded. + */ + (void)glXGetCurrentContext(); + (void)eglGetCurrentContext(); + + init_egl(&egl_dpy, &egl_ctx); + pass = make_egl_current_and_test(egl_dpy, egl_ctx) && pass; + + return pass != true; +}