<div dir="ltr">On 20 September 2013 12:38, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@linux.intel.com" target="_blank">chad.versace@linux.intel.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This test makes current a context, terminates the context's display, then<br>
unbinds the context. According to the EGL 1.4 spec (2011.04.06), Section<br>
3.2 Initialization, no errors should occur.<br>
<br>
Exposes a use-after-free crash on mesa-9.2 with i965. This is the<br>
underlying reason that `./$gles1_test -fbo` crashes on Intel for each<br>
GLES1 test.<br>
<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=69622" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=69622</a><br>
CC: Ian Romanick <<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>><br>
CC: Paul Berry <<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>><br>
Signed-off-by: Chad Versace <<a href="mailto:chad.versace@linux.intel.com" target="_blank">chad.versace@linux.intel.com</a>><br>
---<br>
 tests/all.tests                                    |   1 +<br>
 tests/egl/spec/CMakeLists.txt                      |   1 +<br>
 tests/egl/spec/egl-1.4/CMakeLists.gles2.txt        |   8 ++<br>
 tests/egl/spec/egl-1.4/CMakeLists.txt              |   1 +<br>
 .../egl-1.4/egl-terminate-then-unbind-context.c    | 108 +++++++++++++++++++++<br>
 5 files changed, 119 insertions(+)<br>
 create mode 100644 tests/egl/spec/egl-1.4/CMakeLists.gles2.txt<br>
 create mode 100644 tests/egl/spec/egl-1.4/CMakeLists.txt<br>
 create mode 100644 tests/egl/spec/egl-1.4/egl-terminate-then-unbind-context.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index a7bf00c..6a89287 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -3020,6 +3020,7 @@ egl14['eglQuerySurface EGL_BAD_ATTRIBUTE'] = plain_test('egl-query-surface --bad<br>
 egl14['eglQuerySurface EGL_BAD_SURFACE'] = plain_test('egl-query-surface --bad-surface')<br>
 egl14['eglQuerySurface EGL_HEIGHT'] = plain_test('egl-query-surface --attr=EGL_HEIGHT')<br>
 egl14['eglQuerySurface EGL_WIDTH'] = plain_test('egl-query-surface --attr=EGL_WIDTH')<br>
+egl14['eglTerminate then unbind context'] = plain_test('egl-terminate-then-unbind-context')<br>
<br>
 egl_nok_swap_region = Group()<br>
 spec['EGL_NOK_swap_region'] = egl_nok_swap_region<br>
diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt<br>
index de4de3f..12bb419 100644<br>
--- a/tests/egl/spec/CMakeLists.txt<br>
+++ b/tests/egl/spec/CMakeLists.txt<br>
@@ -1 +1,2 @@<br>
+add_subdirectory (egl-1.4)<br>
 add_subdirectory (egl_khr_create_context)<br>
diff --git a/tests/egl/spec/egl-1.4/CMakeLists.gles2.txt b/tests/egl/spec/egl-1.4/CMakeLists.gles2.txt<br>
new file mode 100644<br>
index 0000000..b6bb1e8<br>
--- /dev/null<br>
+++ b/tests/egl/spec/egl-1.4/CMakeLists.gles2.txt<br>
@@ -0,0 +1,8 @@<br>
+link_libraries(<br>
+       piglitutil_${piglit_target_api}<br>
+        ${OPENGL_egl_LIBRARY}<br>
+        )<br>
+<br>
+piglit_add_executable(egl-terminate-then-unbind-context egl-terminate-then-unbind-context.c)<br>
+<br>
+# vim: ft=cmake:<br>
diff --git a/tests/egl/spec/egl-1.4/CMakeLists.txt b/tests/egl/spec/egl-1.4/CMakeLists.txt<br>
new file mode 100644<br>
index 0000000..144a306<br>
--- /dev/null<br>
+++ b/tests/egl/spec/egl-1.4/CMakeLists.txt<br>
@@ -0,0 +1 @@<br>
+piglit_include_target_api()<br>
diff --git a/tests/egl/spec/egl-1.4/egl-terminate-then-unbind-context.c b/tests/egl/spec/egl-1.4/egl-terminate-then-unbind-context.c<br>
new file mode 100644<br>
index 0000000..acf3dcb<br>
--- /dev/null<br>
+++ b/tests/egl/spec/egl-1.4/egl-terminate-then-unbind-context.c<br>
@@ -0,0 +1,108 @@<br>
+/* Copyright © 2013 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * \file<br>
+ *<br>
+ * This test makes current a context, terminates the context's display, then<br>
+ * unbinds the context. According to the EGL 1.4 spec (2011.04.06), Section<br>
+ * 3.2 Initialization, no error should occur.<br>
+ *<br>
+ *     EGLBoolean eglTerminate(EGLDisplay dpy);<br>
+ *<br>
+ *     Termination marks all EGL-specific resources, such as contexts and<br>
+ *     surfaces, associated with the specified display for deletion. Handles<br>
+ *     to all such resources are invalid as soon as eglTerminate returns, but<br>
+ *     the dpy handle itself remains valid. [...] Applications should not try<br>
+ *     to perform useful work with such resources following eglTerminate; only<br>
+ *     eglMakeCurrent or eglReleaseThread should be called, to complete<br>
+ *     deletion of these resources.<br>
+ *<br>
+ *     If contexts or surfaces created with respect to dpy are current (see<br>
+ *     section 3.7.3) to any thread, then they are not actually destroyed<br>
+ *     while they remain current. Such contexts and surfaces will be destroyed<br>
+ *     as soon as eglReleaseThread is called from the thread they are bound<br>
+ *     to, or eglMakeCurrent is called from that thread with the current<br>
+ *     rendering API (see section 3.7) set such that the current context is<br>
+ *     affected. [...]<br>
+ */<br>
+<br>
+#include <stdbool.h><br>
+#include <stdio.h><br>
+<br>
+#include "piglit-util-egl.h"<br>
+<br>
+#define fail(msg) \<br>
+       do { \<br>
+               fprintf(stderr, "error: %s:%d: %s failed\n", __func__, __LINE__, msg); \<br>
+               piglit_report_result(PIGLIT_FAIL); \<br>
+       } while (0)<br>
+<br>
+int<br>
+main(int argc, char **argv)<br>
+{<br>
+       EGLDisplay dpy;<br>
+       EGLint major_version;<br>
+       EGLint minor_version;<br>
+       EGLConfig config;<br>
+       EGLint num_configs = 0;<br>
+       EGLContext ctx;<br>
+       bool ok;<br>
+<br>
+       dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY );<br>
+       if (!dpy)<br>
+               fail("eglGetDisplay(EGL_DEFAULT_DISPLAY) failed");<br>
+<br>
+       ok = eglInitialize(dpy, &major_version, &minor_version);<br>
+       if (!ok)<br>
+               fail("eglInitialize() failed");<br>
+<br>
+       if (!piglit_is_egl_extension_supported(dpy, "EGL_KHR_surfaceless_context"))<br>
+               piglit_report_result(PIGLIT_SKIP);<br></blockquote><div><br></div><div>It's not obvious clear why EGL_KHR_surfaceless_context is necessary for this test.  Can we remove this check, or add a comment explaining why it's necessary?<br>
<br></div><div>With that addressed, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+       ok = eglChooseConfig(dpy, NULL, &config, 1, &num_configs);<br>
+       if (!ok)<br>
+               fail("eglChooseConfig() failed");<br>
+       if (num_configs == 0)<br>
+               fail("eglChooseConfig() returned no configs\n");<br>
+<br>
+       ctx = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL );<br>
+       if (!ctx)<br>
+               fail("eglCreateContext() failed");<br>
+<br>
+       ok = eglMakeCurrent(dpy, NULL, NULL, ctx);<br>
+       if (!ok)<br>
+               fail("eglMakeCurrent()");<br>
+<br>
+       ok = eglTerminate(dpy);<br>
+       if (!ok)<br>
+          fail("eglTerminate()");<br>
+<br>
+       /* Unbind the context. */<br>
+       ok = eglMakeCurrent(dpy, NULL, NULL, NULL);<br>
+       if (!ok)<br>
+               fail("eglMakeCurrent(ctx=NULL)");<br>
+<br>
+       piglit_report_result(PIGLIT_PASS);<br>
+       return 0;<br>
+<br>
+}<br>
<span><font color="#888888">--<br>
1.8.3.1<br>
<br>
</font></span></blockquote></div><br></div></div>