This patch has 3 interrelated components.

1) Add the following fields to piglit_gl_test_config:
    supports_gl_core_version
    supports_gl_compat_version
    supports_gl_es1
    supports_gl_es2

These allow a test to specify what GL flavors under which it can run.  For
details, see the documentation for struct piglit_gl_test_config.

2. In tests/util/piglit-framework-gl, implement support for the new
fields.

3. In each GL test source, add one of the new fields to the
PIGLIT_GL_TEST_CONFIG_BEGIN/END block.

For GLES1 tests, add `supports_gl_es1 = true`. For GLES2 tests, add
`supports_gl_es2 = true`.  For desktop GL tests, add
`supports_gl_compat_version = 10`. For an explanation of why version 1.0
is used for desktop GL tests, see the documentation for
supports_gl_compat_version. No tests yet require a GL core context.

Signed-off-by: Chad Versace <chad.vers...@linux.intel.com>

=======================================================================

This is a giant sed-job patch. Here are example diffs to the test files, one
for each of GL, GLES1, and GLES2.

diff --git a/tests/asmparsertest/asmparsertest.c 
b/tests/asmparsertest/asmparsertest.c
index b916555..6dfc744 100644
--- a/tests/asmparsertest/asmparsertest.c
+++ b/tests/asmparsertest/asmparsertest.c
@@ -32,6 +32,8 @@
 
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
+       config.supports_gl_compat_version = 10;
+
        config.window_width = 250;
        config.window_height = 250;
        config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_SINGLE | 
PIGLIT_GL_VISUAL_DEPTH;

diff --git 
a/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-basic.c
 
b/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-basic.c
index 197d81c..d52d6fb 100644
--- 
a/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-basic.c
+++ 
b/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-basic.c
@@ -29,6 +29,8 @@
 
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
+       config.supports_gl_es1 = true;
+
        config.window_width = 100;
        config.window_height = 100;
        config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;

diff --git 
a/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-miptree.c
 
b/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-miptree.c
index c1e53ca..d038de4 100644
--- 
a/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-miptree.c
+++ 
b/tests/spec/oes_compressed_etc1_rgb8_texture/oes_compressed_etc1_rgb8_texture-miptree.c
@@ -55,6 +55,8 @@ static const int window_height = 2 * level0_height;
 
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
+       config.supports_gl_es2 = true;
+
        config.window_width = window_width;
        config.window_height = window_height;
        config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;


==========================================================================================

And here is the complete diff for tests/util.

diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 568318d..96df3b8 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -56,10 +56,94 @@ enum piglit_gl_visual {
  * This is named piglit_gl_test_config, rather than piglit_test_config, in
  * order to distinguish it from other test types, such as EGL and GLX tests.
  *
- * TODO: Add fields here that declare test requirements on GL context
- * TODO: flavor, extensions, and window system.
+ * At least one of the `supports` fields must be set.
+ *
+ * If `supports_gl_core_version` and `supports_gl_compat_version` are both
+ * set, then Piglit will first attempt to run the test under a GL core context
+ * of the requested version. If context creation fails, then Piglit will then
+ * attempt to run the test under a GL compatibility context of the requested
+ * version.
  */
 struct piglit_gl_test_config {
+       /**
+        * If this field is non-zero, then the test is able to run under a GL
+        * core context having at least the given version.
+        *
+        * When attempting run a test under a GL core context, Piglit chooses
+        * a waffle_config with the following attributes set.  (Note that
+        * Waffle ignores the profile attribute for versions less than 3.2).
+        *     - WAFFLE_CONTEXT_PROFILE       = WAFFLE_CONTEXT_CORE_PROFILE
+        *     - WAFFLE_CONTEXT_MAJOR_VERSION = supports_gl_core_version / 10
+        *     - WAFFLE_CONTEXT_MINOR_VERSION = supports_gl_core_version % 10
+        * If Piglit fails to acquire the waffle_config or to create the
+        * waffle_context, then it skips its attempt to run the test under
+        * a GL core context.
+        *
+        * It is an error if this field is less than 3.1 because the concept
+        * of "core context" does not apply before GL 3.1.
+        *
+        * Piglit handles a request for a GL 3.1 core context as a special
+        * case.  As noted above, Waffle ignores the profile attribute when
+        * choosing a 3.1 config. However, the concept of "core profile" is
+        * still applicable to 3.1 contexts and is indicated by the context's
+        * lack of support for the GL_ARB_compatibility extension. Therefore,
+        * Piglit attempts to run the test under a GL 3.1 core context by
+        * first creating the context and then skipping the attempt if the
+        * context supports the GL_ARB_compatibility extension.
+        *
+        * If this field is 0, then the test is not able to run under a GL
+        * core context of any version.
+        */
+       int supports_gl_core_version;
+
+       /**
+        * If this field is non-zero, then the test is able to run under a GL
+        * compatibility context having at least the given version.
+        *
+        * When attempting run a test under a GL compatibility context, Piglit
+        * chooses a waffle_config with the following attributes set.  (Note
+        * that Waffle ignores the profile attribute for versions less than
+        * 3.2).
+        *     - WAFFLE_CONTEXT_PROFILE       = 
WAFFLE_CONTEXT_COMPATIBILITY_PROFILE
+        *     - WAFFLE_CONTEXT_MAJOR_VERSION = supports_gl_core_version / 10
+        *     - WAFFLE_CONTEXT_MINOR_VERSION = supports_gl_core_version % 10
+        * If Piglit fails to acquire the waffle_config or to create the
+        * waffle_context, then it skips its attempt to run the test under
+        * a GL compatibility context.
+        *
+        * Piglit handles a request for a GL 3.1 compatibility context as
+        * a special case.  As noted above, Waffle ignores the profile
+        * attribute when choosing a 3.1 config. However, the concept of
+        * "compatibility profile" is still applicable to 3.1 contexts and is
+        * indicated by the context's support for the GL_ARB_compatibility
+        * extension. Therefore, Piglit attempts to run under a GL 3.1
+        * compatibility context by first creating the context and then
+        * skipping the attempt if the context lacks the GL_ARB_compatibility
+        * extension.
+        *
+        * Be aware that, if this field is greater than 10, then the test will
+        * skip on platforms for which specifying a context version is
+        * unsupported (that is, GLX that lacks GLX_ARB_create_context and EGL
+        * that lacks EGL_KHR_create_context). If the test requires a GL
+        * version greater than 1.0, then consider setting this field to 10
+        * and checking the GL version from within the test with
+        * piglit_require_gl_version().
+        *
+        * If this field is 0, then the test is not able to run under a GL
+        * compatibility context of any version.
+        */
+       int supports_gl_compat_version;
+
+       /**
+        * The test is able to run under an OpenGL ES1 context.
+        */
+       bool supports_gl_es1;
+
+       /**
+        * The test is able to run under an OpenGL ES2 context.
+        */
+       bool supports_gl_es2;
+
        int window_width;
        int window_height;
 
diff --git a/tests/util/piglit-framework-gl/piglit_gl_framework.c 
b/tests/util/piglit-framework-gl/piglit_gl_framework.c
index f1ede1c..11edbe0 100644
--- a/tests/util/piglit-framework-gl/piglit_gl_framework.c
+++ b/tests/util/piglit-framework-gl/piglit_gl_framework.c
@@ -21,10 +21,12 @@
  * IN THE SOFTWARE.
  */
 
+#include <stdio.h>
 #include <string.h>
 
 #include "piglit-util-gl-common.h"
 #include "piglit_gl_framework.h"
+#include "piglit-util-gl-common.h"
 
 #ifdef PIGLIT_USE_WAFFLE
 #      include "piglit_fbo_framework.h"
@@ -54,10 +56,50 @@ piglit_gl_framework_factory(const struct 
piglit_gl_test_config *test_config)
 #endif
 }
 
+static void
+validate_supported_apis(const struct piglit_gl_test_config *test_config)
+{
+       int supported_apis = !!test_config->supports_gl_core_version
+                          + !!test_config->supports_gl_compat_version
+                          + !!test_config->supports_gl_es1
+                          + !!test_config->supports_gl_es2;
+
+       if (supported_apis == 0) {
+               printf("The test config supports no GL API's.\n");
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       if (test_config->supports_gl_core_version > 0 &&
+           test_config->supports_gl_core_version < 31) {
+               printf("Config attribute 'supports_gl_core_version' is %d, "
+                      "but must be either 0 or at least 31\n",
+                      test_config->supports_gl_core_version);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+#if defined(PIGLIT_USE_OPENGL)
+       if (!test_config->supports_gl_core_version
+           && !test_config->supports_gl_compat_version) {
+               piglit_report_result(PIGLIT_SKIP);
+       }
+#elif defined(PIGLIT_USE_OPENGL_ES1)
+       if (!test_config->supports_gl_es1) {
+               piglit_report_result(PIGLIT_SKIP);
+       }
+#elif defined(PIGLIT_USE_OPENGL_ES2)
+       if (!test_config->supports_gl_es2) {
+               piglit_report_result(PIGLIT_SKIP);
+       }
+#else
+#      error
+#endif
+}
+
 bool
 piglit_gl_framework_init(struct piglit_gl_framework *gl_fw,
                          const struct piglit_gl_test_config *test_config)
 {
+       validate_supported_apis(test_config);
        memset(gl_fw, 0, sizeof(*gl_fw));
        gl_fw->test_config = test_config;
        return true;
diff --git a/tests/util/piglit-framework-gl/piglit_glut_framework.c 
b/tests/util/piglit-framework-gl/piglit_glut_framework.c
index 032e032..29c75ec 100644
--- a/tests/util/piglit-framework-gl/piglit_glut_framework.c
+++ b/tests/util/piglit-framework-gl/piglit_glut_framework.c
@@ -159,6 +159,12 @@ piglit_glut_framework_create(const struct 
piglit_gl_test_config *test_config)
 {
        bool ok = true;
 
+       if (!test_config->supports_gl_compat_version) {
+               printf("GLUT can create only GL compatibility contexts, "
+                       "which the test does not support running under.\n");
+               piglit_report_result(PIGLIT_SKIP);
+       }
+
        ok = piglit_gl_framework_init(&glut_fw.gl_fw, test_config);
        if (!ok)
                return NULL;
diff --git a/tests/util/piglit-framework-gl/piglit_wfl_framework.c 
b/tests/util/piglit-framework-gl/piglit_wfl_framework.c
index 530c3fc..29f09e8 100644
--- a/tests/util/piglit-framework-gl/piglit_wfl_framework.c
+++ b/tests/util/piglit-framework-gl/piglit_wfl_framework.c
@@ -28,6 +28,13 @@
 
 #include "piglit_wfl_framework.h"
 
+enum context_flavor {
+       CONTEXT_GL_CORE,
+       CONTEXT_GL_COMPAT,
+       CONTEXT_GL_ES1,
+       CONTEXT_GL_ES2,
+};
+
 struct piglit_wfl_framework*
 piglit_wfl_framework(struct piglit_gl_framework *gl_fw)
 {
@@ -89,21 +96,6 @@ piglit_wfl_framework_choose_platform(void)
        return 0;
 }
 
-static int32_t
-get_context_api(void)
-{
-       /* FINISHME: Choose the OpenGL API at runtime. */
-#if defined(PIGLIT_USE_OPENGL)
-       return  WAFFLE_CONTEXT_OPENGL;
-#elif defined(PIGLIT_USE_OPENGL_ES1)
-       return WAFFLE_CONTEXT_OPENGL_ES1;
-#elif defined(PIGLIT_USE_OPENGL_ES2)
-       return WAFFLE_CONTEXT_OPENGL_ES2;
-#else
-#      error
-#endif
-}
-
 /**
  * \brief Concatenate two zero-terminated attribute lists.
  *
@@ -128,35 +120,256 @@ concat_attrib_lists(const int32_t a[], const int32_t b[])
 
        int32_t *r = piglit_calloc(r_size);
        memcpy(r, a, a_copy_size);
-       memcpy(r + a_copy_size, b, b_copy_size);
-       r[r_size - 1] = 0;
+       memcpy(r + 2 * a_length, b, b_copy_size);
+       r[2 * r_length] = 0;
        return r;
 }
 
-static void
+static struct waffle_config*
 choose_config(struct piglit_wfl_framework *wfl_fw,
+              enum context_flavor flavor,
               const int32_t partial_attrib_list[])
 {
-       int32_t head_attrib_list[3];
+       const struct piglit_gl_test_config *test_config = 
wfl_fw->gl_fw.test_config;
+
+       struct waffle_config *config;
+       int32_t head_attrib_list[64];
        int32_t *full_attrib_list;
        int32_t junk;
+       int i;
+
+       /* Derived class must not provide any context attributes. */
+       assert(waffle_attrib_list_get(partial_attrib_list, WAFFLE_CONTEXT_API, 
&junk) == false);
+       assert(waffle_attrib_list_get(partial_attrib_list, 
WAFFLE_CONTEXT_PROFILE, &junk) == false);
+       assert(waffle_attrib_list_get(partial_attrib_list, 
WAFFLE_CONTEXT_MAJOR_VERSION, &junk) == false);
+       assert(waffle_attrib_list_get(partial_attrib_list, 
WAFFLE_CONTEXT_MINOR_VERSION, &junk) == false);
+
+       switch (flavor) {
+               case CONTEXT_GL_CORE:
+                       assert(test_config->supports_gl_core_version);
 
-       /* Derived class must not provide the context api. */
-       assert(waffle_attrib_list_get(partial_attrib_list,
-                                     WAFFLE_CONTEXT_API,
-                                     &junk) == false);
+                       i = 0;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_API;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_OPENGL;
 
-       head_attrib_list[0] = WAFFLE_CONTEXT_API;
-       head_attrib_list[1] = get_context_api();
-       head_attrib_list[2] = 0;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_MAJOR_VERSION;
+                       head_attrib_list[i++] = 
test_config->supports_gl_core_version / 10;
+
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_MINOR_VERSION;
+                       head_attrib_list[i++] = 
test_config->supports_gl_compat_version % 10;
+
+                       head_attrib_list[i++] = 0;
+                       break;
+
+               case CONTEXT_GL_COMPAT:
+                       assert(test_config->supports_gl_compat_version);
+
+                       i = 0;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_API;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_OPENGL;
+
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_MAJOR_VERSION;
+                       head_attrib_list[i++] = 
test_config->supports_gl_compat_version / 10;
+
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_MINOR_VERSION;
+                       head_attrib_list[i++] = 
test_config->supports_gl_compat_version % 10;
+
+                       head_attrib_list[i++] = 0;
+                       break;
+
+               case CONTEXT_GL_ES1:
+                       assert(test_config->supports_gl_es1);
+
+                       i = 0;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_API;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_OPENGL_ES1;
+                       head_attrib_list[i++] = 0;
+                       break;
+
+               case CONTEXT_GL_ES2:
+                       assert(test_config->supports_gl_es2);
+
+                       i = 0;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_API;
+                       head_attrib_list[i++] = WAFFLE_CONTEXT_OPENGL_ES2;
+                       head_attrib_list[i++] = 0;
+                       break;
+
+               default:
+                       assert(0);
+                       break;
+       }
 
        full_attrib_list = concat_attrib_lists(head_attrib_list,
                                               partial_attrib_list);
-       wfl_fw->config = wfl_checked_config_choose(wfl_fw->display,
-                                                  full_attrib_list);
+
+       config = waffle_config_choose(wfl_fw->display,
+                                     full_attrib_list);
+       if (!config)
+               wfl_log_debug("waffle_config_choose");
+
        free(full_attrib_list);
+       return config;
+}
+
+/**
+ * Handle the special case when a test requests GL 3.1.
+ */
+static bool
+special_case_gl_31(const struct piglit_gl_test_config *test_config,
+                   enum context_flavor flavor)
+{
+       int gl_version;
+
+       if (flavor == CONTEXT_GL_CORE
+           && test_config->supports_gl_core_version == 31) {
+
+               gl_version = piglit_get_gl_version();
+               assert(gl_version >= 31);
+
+               if (gl_version == 31
+                   && piglit_is_extension_supported("GL_ARB_compatibility"))
+                       return false;
+               else
+                       return true;
+
+       } else if (flavor == CONTEXT_GL_COMPAT
+                  && test_config->supports_gl_compat_version == 31) {
+
+               gl_version = piglit_get_gl_version();
+               assert(gl_version >= 31);
+
+               if (gl_version == 31
+                   && !piglit_is_extension_supported("GL_ARB_compatibility"))
+                       return false;
+               else
+                       return true;
+       } else {
+               /* No need to check the special case. */
+               return true;
+       }
+}
+
+static bool
+make_context_current_singlepass(struct piglit_wfl_framework *wfl_fw,
+                                const struct piglit_gl_test_config 
*test_config,
+                                enum context_flavor flavor,
+                                const int32_t partial_config_attrib_list[])
+{
+       bool ok;
+
+       assert(wfl_fw->config == NULL);
+       assert(wfl_fw->context == NULL);
+       assert(wfl_fw->window == NULL);
+
+       wfl_fw->config = choose_config(wfl_fw, flavor,
+                                      partial_config_attrib_list);
+       if (!wfl_fw->config)
+               goto fail;
+
+       wfl_fw->context = waffle_context_create(wfl_fw->config, NULL);
+       if (!wfl_fw->context) {
+               wfl_log_debug("waffle_context_create");
+               goto fail;
+       }
+
+       wfl_fw->window = wfl_checked_window_create(wfl_fw->config,
+                                                  test_config->window_width,
+                                                  test_config->window_height);
+
+       wfl_checked_make_current(wfl_fw->display,
+                                wfl_fw->window,
+                                wfl_fw->context);
+
+#ifdef PIGLIT_USE_OPENGL
+       piglit_dispatch_default_init();
+#endif
+
+       ok = special_case_gl_31(test_config, flavor);
+       if (!ok)
+               goto fail;
+
+       return true;
+
+fail:
+       waffle_window_destroy(wfl_fw->window);
+       waffle_context_destroy(wfl_fw->context);
+       waffle_config_destroy(wfl_fw->config);
+
+       wfl_fw->window = NULL;
+       wfl_fw->context = NULL;
+       wfl_fw->config = NULL;
+
+       return false;
+}
+
+static void
+make_context_current(struct piglit_wfl_framework *wfl_fw,
+                     const struct piglit_gl_test_config *test_config,
+                     const int32_t partial_config_attrib_list[])
+{
+       bool ok = false;
+
+#if defined(PIGLIT_USE_OPENGL)
+
+       if (test_config->supports_gl_core_version) {
+               ok = make_context_current_singlepass(wfl_fw, test_config,
+                                                    CONTEXT_GL_CORE,
+                                                    
partial_config_attrib_list);
+               if (ok) {
+                       return;
+               } else {
+                       printf("piglit: info: Failed to create GL %d.%d "
+                              "core context\n",
+                              test_config->supports_gl_core_version / 10,
+                              test_config->supports_gl_core_version % 10);
+               }
+       }
+
+       if (test_config->supports_gl_compat_version) {
+               ok = make_context_current_singlepass(wfl_fw, test_config,
+                                                    CONTEXT_GL_COMPAT,
+                                                    
partial_config_attrib_list);
+               if (ok) {
+                       return;
+               } else {
+                       printf("piglit: info: Failed to create GL %d.%d "
+                              "compatibility context\n",
+                              test_config->supports_gl_compat_version / 10,
+                              test_config->supports_gl_compat_version % 10);
+               }
+       }
+
+#elif defined(PIGLIT_USE_OPENGL_ES1)
+       ok = make_context_current_singlepass(wfl_fw, test_config,
+                                            CONTEXT_GL_ES1,
+                                            partial_config_attrib_list);
+
+       if (ok)
+               return;
+       else
+               printf("piglit: info: Failed to create GL ES1 context\n");
+
+#elif defined(PIGLIT_USE_OPENGL_ES2)
+       ok = make_context_current_singlepass(wfl_fw, test_config,
+                                            CONTEXT_GL_ES2,
+                                            partial_config_attrib_list);
+
+       if (ok)
+               return;
+       else
+               printf("piglit: info: Failed to create GL ES2 context\n");
+#else
+#      error
+#endif
+
+       if (!ok) {
+               printf("piglit: info: Failed to create any GL context\n");
+               piglit_report_result(PIGLIT_SKIP);
+       }
 }
 
+
 bool
 piglit_wfl_framework_init(struct piglit_wfl_framework *wfl_fw,
                           const struct piglit_gl_test_config *test_config,
@@ -187,18 +400,7 @@ piglit_wfl_framework_init(struct piglit_wfl_framework 
*wfl_fw,
 
        wfl_fw->platform = platform;
        wfl_fw->display = wfl_checked_display_connect(NULL);
-       choose_config(wfl_fw, partial_config_attrib_list);
-       wfl_fw->context = wfl_checked_context_create(wfl_fw->config, NULL);
-       wfl_fw->window = wfl_checked_window_create(wfl_fw->config,
-                                                  test_config->window_width,
-                                                  test_config->window_height);
-       wfl_checked_make_current(wfl_fw->display,
-                                wfl_fw->window,
-                                wfl_fw->context);
-
-#ifdef PIGLIT_USE_OPENGL
-       piglit_dispatch_default_init();
-#endif
+       make_context_current(wfl_fw, test_config, partial_config_attrib_list);
 
        return true;
 
-- 
1.7.12.1

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to