[Piglit] [PATCH 1/5] gles2: add sanity test
Tom Gall
tom.gall at linaro.org
Mon Dec 17 15:34:05 PST 2012
new tests/spec/gles-2.0 directory and infrastructure to build
initial testcase and add gles-2.0 as part of all.tests
new gles2 sanity test which very simply renders a triangle fan and
validates it was rendered correctly via
piglit_probe_rect_rgba
Signed-off-by: Tom Gall <tom.gall at linaro.org>
---
tests/all.tests | 4 +
tests/spec/gles-2.0/CMakeLists.gles2.txt | 3 +-
tests/spec/gles-2.0/gles2_sanity_test.c | 142 ++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+), 1 deletion(-)
create mode 100644 tests/spec/gles-2.0/gles2_sanity_test.c
diff --git a/tests/all.tests b/tests/all.tests
index c823bcf..aff8a43 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2669,6 +2669,10 @@ egl_khr_create_context['3.2 core profile required'] = plain_test('egl-create-con
egl_khr_create_context['pre-GL3.2 profile'] = plain_test('egl-create-context-pre-GL32-profile')
egl_khr_create_context['verify GL flavor'] = plain_test('egl-create-context-verify-gl-flavor')
+gles20 = Group()
+spec['!OpenGL ES 2.0'] = gles20
+gles20['sanity-test_gles2'] = PlainExecTest(['sanity-test_gles2', '-auto'])
+
gles30 = Group()
spec['!OpenGL ES 3.0'] = gles30
for tex_format in ('rgb8', 'srgb8', 'rgba8', 'srgb8-alpha8', 'r11', 'rg11', 'rgb8-punchthrough-alpha1', 'srgb8-punchthrough-alpha1'):
diff --git a/tests/spec/gles-2.0/CMakeLists.gles2.txt b/tests/spec/gles-2.0/CMakeLists.gles2.txt
index 4d06a02..df3d26c 100644
--- a/tests/spec/gles-2.0/CMakeLists.gles2.txt
+++ b/tests/spec/gles-2.0/CMakeLists.gles2.txt
@@ -2,6 +2,7 @@ link_libraries(
piglitutil_${piglit_target_api}
)
-piglit_add_executable(gles2-invalid-es3-queries invalid-es3-queries.c)
+piglit_add_executable(sanity-test_${piglit_target_api} gles2_sanity_test.c)
+piglit_add_executable(invalid-es3-queries_${piglit_target_api} invalid-es3-queries.c)
# vim: ft=cmake:
diff --git a/tests/spec/gles-2.0/gles2_sanity_test.c b/tests/spec/gles-2.0/gles2_sanity_test.c
new file mode 100644
index 0000000..780690c
--- /dev/null
+++ b/tests/spec/gles-2.0/gles2_sanity_test.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2012 Linaro Inc
+ *
+ * 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.
+ */
+
+/**
+ * A simple triange test for OpenGL ES 2.0.
+ *
+ * \author Tom Gall <tom.gall at linaro.org>
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_es_version = 20;
+ config.requires_displayed_window = true;
+
+ config.window_width = 320;
+ config.window_height = 200;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint prog;
+GLuint frag;
+GLuint vert;
+
+char vertex_shader [] =
+"attribute vec4 vPosition;\n"
+"void main()\n"
+"{\n"
+" gl_Position = vPosition;\n"
+"}";
+
+char fragment_shader [] =
+"precision mediump float;\n"
+"void main()\n"
+"{\n"
+" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
+"}";
+
+enum piglit_result
+validate_results()
+{
+ GLfloat red[4] = {1.0, 0.0, 0.0, 1.0};
+ GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
+
+ /* check that the square was rendered correctly */
+ if (!piglit_probe_rect_rgba(80,50,159,97, red))
+ return PIGLIT_FAIL;
+
+ /* check that the remaining area is black */
+ if (!piglit_probe_rect_rgba(0,0,320,49, black))
+ return PIGLIT_FAIL;
+ if (!piglit_probe_rect_rgba(0,50,79,98, black))
+ return PIGLIT_FAIL;
+ if (!piglit_probe_rect_rgba(240,50,80,98, black))
+ return PIGLIT_FAIL;
+ if (!piglit_probe_rect_rgba(0,150,320,49, black))
+ return PIGLIT_FAIL;
+
+ return PIGLIT_PASS;
+}
+
+void
+link_and_use_shaders(void)
+{
+ prog = glCreateProgram();
+
+ vert=piglit_compile_shader_text(GL_VERTEX_SHADER,vertex_shader);
+ frag=piglit_compile_shader_text(GL_FRAGMENT_SHADER,fragment_shader);
+
+ glAttachShader(prog, vert);
+ glAttachShader(prog, frag);
+
+ glLinkProgram(prog);
+ if (!(piglit_link_check_status(prog))) {
+ piglit_report_result(PIGLIT_FAIL);
+ return;
+ }
+
+ glDeleteShader(vert);
+ glDeleteShader(frag);
+
+ glUseProgram(prog);
+ if (!piglit_check_gl_error(0)) {
+ piglit_report_result(PIGLIT_FAIL);
+ return;
+ }
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ enum piglit_result result;
+ GLfloat vVertices[] = { 0.5, -0.5, 0.0,
+ 0.5, 0.5, 0.0,
+ -0.5, 0.5, 0.0,
+ -0.5, -0.5, 0.0 };
+
+ /* Clear the color buffer */
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Load the vertex data */
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
+ glEnableVertexAttribArray(0);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ piglit_swap_buffers();
+
+ result=validate_results();
+ piglit_report_result(result);
+ return result;
+}
+
+void
+piglit_init(int argc, char *argv[])
+{
+ link_and_use_shaders();
+}
--
1.7.10.4
More information about the Piglit
mailing list