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

Tom Gall tom.gall at linaro.org
Thu Dec 6 05:43:57 PST 2012


Any comment on this patch series? 

It would be nice to get tests/spec/gles-2.0 going.

Regards,
Tom


Begin forwarded message:

> From: Tom Gall <tom.gall at linaro.org>
> Date: December 2, 2012, 7:55:38 AM EST
> To: piglit at lists.freedesktop.org
> Cc: Tom Gall <tom.gall at linaro.org>
> Subject: [PATCH 1/4] gles2: add sanity test
> 
> 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.
> 
> Signed-off-by: Tom Gall <tom.gall at linaro.org>
> ---
> tests/all_es2.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  |  140 ++++++++++++++++++++++++++++++
> tests/util/piglit-util-gl-common.c       |   32 +++++++
> tests/util/piglit-util-gl-common.h       |    1 +
> 7 files changed, 194 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_es2.tests b/tests/all_es2.tests
> index ac1b636..f5dc1da 100644
> --- a/tests/all_es2.tests
> +++ b/tests/all_es2.tests
> @@ -21,4 +21,8 @@ oes_compressed_etc1_rgb8_texture = Group()
> spec['OES_compressed_ETC1_RGB8_texture'] = oes_compressed_etc1_rgb8_texture
> oes_compressed_etc1_rgb8_texture['miptree'] = PlainExecTest(['oes_compressed_etc1_rgb8_texture-miptree', '-auto'])
> 
> +gles2_tests = Group()
> +spec['gles2_tests'] = gles2_tests
> +gles2_tests['gles2_sanity_test'] = PlainExecTest(['gles2_sanity_test', '-auto'])
> +
> profile.tests['spec'] = spec
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index c2a7886..ed76f39 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 (glx_arb_create_context)
> add_subdirectory (glx_ext_import_context)
> add_subdirectory (glx_oml_sync_control)
> 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..d1c74a1
> --- /dev/null
> +++ b/tests/spec/gles-2.0/gles2_sanity_test.c
> @@ -0,0 +1,140 @@
> +/*
> + * 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_es2 = true;
> +    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)
> +{
> +    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();
> +
> +    return validate_results();
> +}
> +
> +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 9000673..c8e9b8e 100644
> --- a/tests/util/piglit-util-gl-common.c
> +++ b/tests/util/piglit-util-gl-common.c
> @@ -224,6 +224,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
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20121206/aebfc0e7/attachment-0001.html>


More information about the Piglit mailing list