[Piglit] [PATCH 1/4] gles2: add sanity test
Tom Gall
tom.gall at linaro.org
Fri Dec 14 08:19:13 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/CMakeLists.txt | 1 +
tests/spec/gles-2.0/CMakeLists.gles2.txt | 15 ++++
tests/spec/gles-2.0/CMakeLists.txt | 1 +
tests/spec/gles-2.0/gles2_sanity_test.c | 142 ++++++++++++++++++++++++++++++
5 files changed, 163 insertions(+)
create mode 100644 tests/spec/gles-2.0/CMakeLists.gles2.txt
create mode 100644 tests/spec/gles-2.0/CMakeLists.txt
create mode 100644 tests/spec/gles-2.0/gles2_sanity_test.c
diff --git a/tests/all.tests b/tests/all.tests
index a471203..581c35d 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2662,6 +2662,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['gles2-sanity-test'] = PlainExecTest(['gles2-sanity-test', '-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/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 46a91bd..2a8607f 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -51,6 +51,7 @@ add_subdirectory (gl-2.0)
add_subdirectory (gl-2.1)
add_subdirectory (gl-3.0)
add_subdirectory (gl-3.1)
+add_subdirectory (gles-2.0)
add_subdirectory (gles-3.0)
add_subdirectory (glx_arb_create_context)
add_subdirectory (glx_ext_import_context)
diff --git a/tests/spec/gles-2.0/CMakeLists.gles2.txt b/tests/spec/gles-2.0/CMakeLists.gles2.txt
new file mode 100644
index 0000000..93fbf58
--- /dev/null
+++ b/tests/spec/gles-2.0/CMakeLists.gles2.txt
@@ -0,0 +1,15 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+ ${OPENGL_INCLUDE_PATH}
+ )
+
+link_libraries(
+ ${OPENGL_gles2_LIBRARY}
+ ${OPENGL_egl_LIBRARY}
+ piglitutil_gles2
+ )
+
+piglit_add_executable(${piglit_target_api}-sanity-test gles2_sanity_test.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/gles-2.0/CMakeLists.txt b/tests/spec/gles-2.0/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/gles-2.0/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
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