[Piglit] [PATCH] sso: Verify glActiveShaderProgram with invalid program parameter
Ian Romanick
idr at freedesktop.org
Wed Feb 19 19:43:13 PST 2014
On 02/19/2014 07:35 PM, Jordan Justen wrote:
> On Wed, Feb 19, 2014 at 4:55 PM, Ian Romanick <idr at freedesktop.org> wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> There are several cases outlined in the GL 4.4 spec where
>> glActiveShaderProgram should generate specific errors. In addition,
>> section 2.3.1 (Errors) says:
>>
>> "Currently, when an error flag is set, results of GL operation are
>> undefined only if an OUT_OF_MEMORY error has occurred. In other
>> cases, there are no side effects unless otherwise noted; the command
>> which generates the error is ignored so that it has no effect on GL
>> state or framebuffer contents."
>>
>> After calling glActiveShaderProgram with an invalid parameter, verify
>> that the active program state has not been modified.
>>
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>> Cc: Jordan Justen <jordan.l.justen at intel.com>
>> ---
>> tests/all.py | 1 +
>> .../ActiveShaderProgram-invalid-program.c | 171 +++++++++++++++++++++
>> .../arb_separate_shader_objects/CMakeLists.gl.txt | 1 +
>> 3 files changed, 173 insertions(+)
>> create mode 100644 tests/spec/arb_separate_shader_objects/ActiveShaderProgram-invalid-program.c
>>
>> diff --git a/tests/all.py b/tests/all.py
>> index 8558ba6..f19763e 100644
>> --- a/tests/all.py
>> +++ b/tests/all.py
>> @@ -1757,6 +1757,7 @@ add_concurrent_test(arb_occlusion_query, 'gen_delete_while_active')
>> # Group ARB_separate_shader_objects
>> arb_separate_shader_objects = Group()
>> spec['ARB_separate_shader_objects'] = arb_separate_shader_objects
>> +arb_separate_shader_objects['ActiveShaderProgram with invalid program'] = concurrent_test('arb_separate_shader_object-ActiveShaderProgram-invalid-program')
>> arb_separate_shader_objects['GetProgramPipelineiv'] = concurrent_test('arb_separate_shader_object-GetProgramPipelineiv')
>> arb_separate_shader_objects['IsProgramPipeline'] = concurrent_test('arb_separate_shader_object-IsProgramPipeline')
>> arb_separate_shader_objects['UseProgramStages - non-separable program'] = concurrent_test('arb_separate_shader_object-UseProgramStages-non-separable')
>> diff --git a/tests/spec/arb_separate_shader_objects/ActiveShaderProgram-invalid-program.c b/tests/spec/arb_separate_shader_objects/ActiveShaderProgram-invalid-program.c
>> new file mode 100644
>> index 0000000..89fd5e6
>> --- /dev/null
>> +++ b/tests/spec/arb_separate_shader_objects/ActiveShaderProgram-invalid-program.c
>> @@ -0,0 +1,171 @@
>> +/*
>> + * Copyright © 2013 Intel Corporation
>
> 2014
Stupid copy-and-paste...
>> + * 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.
>> + */
>> +
>> +/**
>> + * \name ActiveShaderProgram-invalid-program.c
>> + * Verify glActiveShaderProgram with invalid program parameter
>> + *
>> + * There are several cases outlined in the GL 4.4 spec where
>> + * glActiveShaderProgram should generate specific errors. In addition,
>> + * section 2.3.1 (Errors) says:
>> + *
>> + * "Currently, when an error flag is set, results of GL operation are
>> + * undefined only if an OUT_OF_MEMORY error has occurred. In other cases,
>> + * there are no side effects unless otherwise noted; the command which
>> + * generates the error is ignored so that it has no effect on GL state or
>> + * framebuffer contents."
>> + *
>> + * After calling glActiveShaderProgram with an invalid parameter, verify that
>> + * the active program state has not been modified.
>> + */
>> +
>> +#include "piglit-util-gl-common.h"
>> +
>> +PIGLIT_GL_TEST_CONFIG_BEGIN
>> +
>> + config.supports_gl_compat_version = 20;
>> + config.supports_gl_core_version = 31;
>> +
>> +PIGLIT_GL_TEST_CONFIG_END
>> +
>> +static const char vs_code_template[] =
>> + "#version %u\n"
>> + "void main() { gl_Position = vec4(0); }\n"
>> + ;
>> +
>> +static const char *const invalid_code =
>> + "#version 123456789\n"
>> + "void main() { gl_Position = jambon_bahn_mi(); }\n"
>
> jambon_banh_mi?
>
> or jambon_bánh_mì? :)
I was limited by ASCII!
>> + ;
>> +
>> +void
>> +piglit_init(int argc, char **argv)
>> +{
>> + bool pass = true;
>> + GLuint pipe;
>> + GLuint vs_prog;
>> + GLuint active_prog;
>> + GLuint unlinked_prog;
>> + GLuint shader;
>> + unsigned glsl_version;
>> + bool es;
>> + int glsl_major;
>> + int glsl_minor;
>> + char *source;
>> +
>> + piglit_require_extension("GL_ARB_separate_shader_objects");
>> +
>> + piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);
>> + glsl_version = ((glsl_major * 100) + glsl_minor) >= 140
>> + ? 140 : ((glsl_major * 100) + glsl_minor);
>> +
>> + glGenProgramPipelines(1, &pipe);
>> + pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
>> +
>> + glBindProgramPipeline(pipe);
>> +
>> + asprintf(&source, vs_code_template, glsl_version);
>> + vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
>> + (const GLchar *const *) &source);
>> + piglit_link_check_status(vs_prog);
>> +
>> + /* First, make a valid program active.
>> + */
>> + glActiveShaderProgram(pipe, vs_prog);
>> + pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
>> +
>> + /* Next, try to make an invalid program active and verify that the
>> + * correct error is generated. Also make sure the old program is
>> + * still active.
>> + *
>> + * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
>> + * the OpenGL 4.4 spec says:
>> + *
>> + * "An INVALID_VALUE error is generated if program is not zero and
>> + * is not the name of either a program or shader object."
>> + */
>> + glActiveShaderProgram(pipe, ~vs_prog);
>
> ~vs_prog? not guaranteed, but probably fine...
Since we've only created one pipeline, and, since it can't be 0,
~vs_prog != vs_prog, it seemed safe enough.
>> + pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
>> +
>> + glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
>> + if (active_prog != vs_prog) {
>> + printf("glActiveShaderProgram with an invalid program name "
>> + "changed the active program state.\n");
>> + pass = false;
>> + }
>> +
>> + /* Try the same thing with a valid shader object (that is not part of
>> + * a linked program). Verify that the correct error is generated, and
>> + * make sure the old program is still active.
>> + *
>> + * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
>> + * the OpenGL 4.4 spec says:
>> + *
>> + * "An INVALID_OPERATION error is generated if program is the name
>> + * of a shader object."
>> + */
>> + shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
>> + glActiveShaderProgram(pipe, shader);
>> + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
>> +
>> + glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
>> + if (active_prog != vs_prog) {
>
> reset to vs_prog for next test?
How do you mean?
>> + printf("glActiveShaderProgram with a shader object "
>> + "changed the active program state.\n");
>> + pass = false;
>> + }
>> +
>> + /* Finally, try the same thing with a valid program that is not lined.
>
> linked
>
> Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
>
>> + * Verify that the correct error is generated, and make sure the old
>> + * program is still active.
>> + *
>> + * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
>> + * the OpenGL 4.4 spec says:
>> + *
>> + * "An INVALID_OPERATION error is generated if program is not zero
>> + * and has not been linked, or was last linked unsuccessfully."
>> + */
>> + unlinked_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
>> + (const GLchar *const *) &invalid_code);
>> +
>> + glActiveShaderProgram(pipe, unlinked_prog);
>> + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
>> +
>> + glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
>> + if (active_prog != vs_prog) {
>> + printf("glActiveShaderProgram with an unlinked program "
>> + "changed the active program state.\n");
>> + pass = false;
>> + }
>> +
>> +
>> + free(source);
>> + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
>> +}
>> +
>> +enum piglit_result
>> +piglit_display(void)
>> +{
>> + /* UNREACHED */
>> + return PIGLIT_FAIL;
>> +}
>> diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
>> index 2e2e1b8..397ff9a 100644
>> --- a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
>> +++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
>> @@ -10,6 +10,7 @@ link_libraries (
>> )
>>
>> piglit_add_executable (arb_separate_shader_object-400-combinations 400-combinations.c)
>> +piglit_add_executable (arb_separate_shader_object-ActiveShaderProgram-invalid-program ActiveShaderProgram-invalid-program.c)
>> piglit_add_executable (arb_separate_shader_object-GetProgramPipelineiv GetProgramPipelineiv.c)
>> piglit_add_executable (arb_separate_shader_object-IsProgramPipeline IsProgramPipeline.c)
>> piglit_add_executable (arb_separate_shader_object-mix_pipeline_useprogram mix_pipeline_useprogram.c)
>> --
>> 1.8.1.4
>>
>> _______________________________________________
>> Piglit mailing list
>> Piglit at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list