[Piglit] [PATCH] Add test case to verify swapping buffers without active context.
Yi Sun
yi.sun at intel.com
Sun Jan 15 00:41:13 PST 2012
From: Sun Yi <yi.sun at intel.com>
Make current context null and then swap frame buffers. The swapping buffer could still happen as expected and no crash expected.
Signed-off-by: Yi Sun <yi.sun at intel.com>
v2: Incorporated suggestions from Anuj and Brian.
diff --git a/tests/bugs/CMakeLists.gl.txt b/tests/bugs/CMakeLists.gl.txt
index bce0532..64d2c77 100644
--- a/tests/bugs/CMakeLists.gl.txt
+++ b/tests/bugs/CMakeLists.gl.txt
@@ -33,5 +33,6 @@ add_executable (fdo28551 fdo28551.c)
add_executable (fdo31934 fdo31934.c)
add_executable (tri-tex-crash tri-tex-crash.c)
add_executable (vbo-buffer-unmap vbo-buffer-unmap.c)
+add_executable (swapbuffers-no-context swapbuffers-no-context.c)
# vim: ft=cmake:
diff --git a/tests/bugs/swapbuffers-no-context.c b/tests/bugs/swapbuffers-no-context.c
new file mode 100644
index 0000000..d3984b2
--- /dev/null
+++ b/tests/bugs/swapbuffers-no-context.c
@@ -0,0 +1,89 @@
+/* Copyright © 2012 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 swapbuffers-no-context.c
+ *
+ * Test swapping buffers on NULL context.
+ * Verify that swapping buffers without active context could still
+ * happen as expected.
+ *
+ * Test renders a rectangle then active context is deselected.
+ * Render another rectangle after making context null, which
+ * make sure that the second rectangle doesn't modified frame buffer.
+ * Afterwards buffers swapping is performed, and verify the color
+ * in front buffer correct.
+ *
+ * Test is expected no crash occurs during testcase execution.
+ * Test case also verifies the fix for Bug 44153:
+ * https://bugs.freedesktop.org/show_bug.cgi?id=44614
+ *
+ * Author Yi Sun <yi.sun at intel.com>
+ */
+
+#include "piglit-util.h"
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static const float green[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
+static const float red[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
+
+enum piglit_result
+piglit_display(void)
+{
+ int pass;
+ int x, y;
+ x = piglit_width - 10;
+ y = piglit_height - 5;
+
+ Display *dpy = glXGetCurrentDisplay();
+ GLXDrawable curDraw = glXGetCurrentDrawable();
+ GLXDrawable readDraw = glXGetCurrentReadDrawable();
+ GLXContext curContext = glXGetCurrentContext();
+
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glColor3f(0.0, 1.0, 0.0);
+ piglit_draw_rect(0, 0, piglit_width, piglit_height);
+
+ glXMakeContextCurrent(dpy, 0, 0, 0); //deselect the context
+
+ glColor3f(1.0, 0.0, 0.0);
+ piglit_draw_rect(0, 0, piglit_width, piglit_height);
+
+ glXSwapBuffers(dpy, curDraw); //swap buffer, no crashing expected
+ glXMakeContextCurrent(dpy, curDraw, readDraw, curContext); //re-select the context
+
+ glReadBuffer(GL_FRONT);
+ pass = piglit_probe_pixel_rgb( x, y, green);
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+
+}
--
1.7.6.4
More information about the Piglit
mailing list