[Piglit] [PATCH 1/4] gles2: add sanity test

Tom Gall tom.gall at linaro.org
Mon Dec 10 07:24:33 PST 2012


new gles2 sanity test which very simply renders a triangle fan and
  validates it was rendered correctly via a newly added
  piglit_probe_rect_rgba_ubyte util function.

Add to tests/util/piglit-util-gl-common.c
piglit_probe_rect_rgba_ubyte which is useful since glReadPixels
utilizes this type.

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 ++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl-common.c       |   32 +++++++
 tests/util/piglit-util-gl-common.h       |    1 +
 7 files changed, 196 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 4581edf..77e13a4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2674,6 +2674,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..fe512aa
--- /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(gles2_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..93ef8c1
--- /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()
+{
+	GLubyte red[4] = {0xff, 0x00, 0x00, 0xff};
+	GLubyte black[4] = {0x00, 0x00, 0x00, 0xff};
+
+	/* check that the square was rendered correctly */
+	if (!piglit_probe_rect_rgba_ubyte(80,50,159,97, red))
+		return PIGLIT_FAIL;
+
+	/* check that the remaining area is black */
+	if (!piglit_probe_rect_rgba_ubyte(0,0,320,49, black))
+		return PIGLIT_FAIL;
+	if (!piglit_probe_rect_rgba_ubyte(0,50,79,98, black))
+		return PIGLIT_FAIL;
+	if (!piglit_probe_rect_rgba_ubyte(240,50,80,98, black))
+		return PIGLIT_FAIL;
+	if (!piglit_probe_rect_rgba_ubyte(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();
+}
diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index b431815..d96b48b 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -226,6 +226,38 @@ void piglit_reset_gl_error(void)
 	}
 }
 
+int
+piglit_probe_rect_rgba_ubyte(int x, int y, int w, int h, const GLubyte *expected)
+{
+	int i, j, p;
+	GLubyte *probe;
+	GLubyte *pixels = malloc(w*h*4*sizeof(GLubyte));
+
+	glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			probe = &pixels[(j*w+i)*4];
+
+			for (p = 0; p < 4; ++p) {
+				if (probe[p] - expected[p]) {
+					printf("Probe at (%i,%i)\n", x+i, y+j);
+					printf("  Expected: %x %x %x %x\n",
+						expected[0], expected[1], expected[2], expected[3]);
+					printf("  Observed: %x %x %x %x\n",
+						probe[0], probe[1], probe[2], probe[3]);
+
+					free(pixels);
+					return 0;
+				}
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
 /* These texture coordinates should have 1 or -1 in the major axis selecting
  * the face, and a nearly-1-or-negative-1 value in the other two coordinates
  * which will be used to produce the s,t values used to sample that face's
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index 2d6bb1a..defbe11 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -111,6 +111,7 @@ int piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expect
 int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
 int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
 int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
+int piglit_probe_rect_rgba_ubyte(int x, int y, int w, int h, const GLubyte* expected);
 void piglit_compute_probe_tolerance(GLenum format, float *tolerance);
 int piglit_compare_images_color(int x, int y, int w, int h, int num_components,
 				const float *tolerance,
-- 
1.7.10.4



More information about the Piglit mailing list