1 /*
2  * Copyright © 2019 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 /**
24  * \file glx-egl-switch-context.c
25  *
26  * Test aims to reproduce SIGSEGV on i965 appearing on certain
27  * sequences of switching glx and egl contexts. Particular sequence
28  * that leads to crash:
29  *
30  * 1. Make glx context current
31  * 2. Make egl context current
32  * 3. Drop glx context
33  * 4. Make egl context current
34  *
35  * In order to reproduce the crash you also need to export the loader:
36  * export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PATH_TO_MESA_BUILD/lib
37  *
38  * \author Yevhenii Kolesnikov <yevhenii.kolesnikov@globallogic.com>
39  */
40 
41 #include "piglit-util-gl.h"
42 #include "piglit-util-egl.h"
43 #include "piglit-glx-util.h"
44 
45 EGLint major_version, minor_version;
46 
47 int piglit_width = 160,
48     piglit_height = 160;
49 
main(int argc,char ** argv)50 int main(int argc, char **argv)
51 {
52     Display *dpy;
53     EGLDisplay dpy_egl;
54     XVisualInfo *visinfo;
55     GLXFBConfig fbconfig;
56     Window win;
57     GLXWindow glxWin;
58     GLXContext ctx_glx;
59     EGLContext ctx_egl;
60 
61     bool pass = true;
62 
63     dpy = piglit_get_glx_display();
64     visinfo = piglit_get_glx_visual(dpy);
65     fbconfig = piglit_glx_get_fbconfig_for_visinfo(dpy, visinfo);
66     win = piglit_get_glx_window(dpy, visinfo);
67     glxWin = glXCreateWindow(dpy, fbconfig, win, NULL);
68 
69     dpy_egl = eglGetDisplay(dpy);
70     if (!dpy_egl)
71         piglit_report_result(PIGLIT_SKIP);
72     if (!eglInitialize(dpy_egl, &major_version, &minor_version))
73         piglit_report_result(PIGLIT_SKIP);
74 
75     ctx_glx = glXCreateContext(dpy, visinfo, NULL, True);
76     ctx_egl = eglCreateContext(dpy_egl, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, NULL);
77 
78     glXMakeContextCurrent(dpy, glxWin, glxWin, ctx_glx);
79     eglMakeCurrent(dpy_egl, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_egl);
80     glXMakeContextCurrent(dpy, None, None, NULL);
81     eglMakeCurrent(dpy_egl, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_egl);
82     eglMakeCurrent(dpy_egl, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
83 
84     glXDestroyContext(dpy, ctx_glx);
85     eglDestroyContext(dpy_egl, ctx_egl);
86 
87     eglTerminate(dpy_egl);
88 
89     XFree(visinfo);
90 
91     piglit_report_result(PIGLIT_PASS);
92 
93     return pass;
94 }
95