util/wfl: Fallback gracefully for OpenGL 3.1 weirdness

OpenGL 3.1 profiles are weird.  Strictly speaking, an OpenGL 3.1 context
has no profile. (See the EGL_KHR_create_context spec for the ugly
details [1]). If the user does request a specific OpenGL 3.1 profile,
though, then let's do what the user wants.

If the user requests a OpenGL 3.1 Core Context, and the returned context
is exactly an OpenGL 3.1 context but it exposes GL_ARB_compatibility,
then fallback to requesting an OpenGL 3.2 Core Context because, if
context creation succeeds, then Waffle guarantees that an OpenGL 3.2
Context will have the requested profile. Likewise for OpenGL 3.1
Compatibility Contexts.

[1] http://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_create_context.txt

Reported-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
registry: Import gl.xml from Khronos registry

Import revision 26792 on 2014-05-22 from
(https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml).

I'm importing the Khronos XML because I want to generate piglit-dispatch
code from it rather than scraping GL headers and unmaintained *.spec
files.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Rename generated dispatch files

Rename the files "generated_dispatch.[ch]" to
"piglit-dispatch-gen.[ch]".  They now follow the same filename
convention ("piglit-*.[ch]") used by most other files in tests/util.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
dispatch: Generate piglit-dispatch from Khronos XML

Khronos now generates its headers from XML and no longer maintains the
old, crufty *.spec files. Piglit should do the same. Otherwise,
piglit-dispatch won't be able to pick up new extension functions.

As a really really big bonus, after Piglit starts generating its GL
dispatch code from gl.xml, it will be a small step to start generating
EGL and GLX dispatch from egl.xml and glx.xml.

This patch imports 'gl.xml' into a new toplevel "registry" directory, to
follow the precedent of libepoxy.

This patch follows the precedent of libepoxy by importing "gl.xml" into
a new toplevel "registry" directory.

I did *not* try to redesign piglit-dispatch in this patch. To the
contrary, I attempted to keep the newly generated dispatch code to be as
similar as possible as the old generated code. Despite wanting to clean
up piglit-dispatch's design, I refrained because "a patch should do one
thing, and do it well".

I strove to keep separate concerns in separate files. File
"registry/gl.py" parses "registry/gl.xml". File
"tests/util/gen_dispatch.py" generates code from the that parsed result.
This decision kept gen_dispatch.py small and focused.

I hope everyone finds the rewritten gen_dispatch.py more maintainable
and easy to read.

The generated code has changed as following:

  - It now contains the GLES1 API, because gl.xml contains information
    on all OpenGL APIs.

  - The comment block for each function alias set now contains more
    information. For each function in the set, it now lists the
    complete set of providers.

    For example:
      /* glActiveTexture (GL_VERSION_1_3) (GL_VERSION_ES_CM_1_0) (GL_ES_VERSION_2_0) */
      /* glActiveTextureARB (GL_ARB_multitexture) */
      extern PFNGLACTIVETEXTUREPROC piglit_dispatch_glActiveTexture;
      #define glActiveTexture piglit_dispatch_glActiveTexture
      #define glActiveTextureARB piglit_dispatch_glActiveTexture

  - Enums are sorted by group then by value. Old dispatch sorted only by
    value.

    For example:
      /* Enum Group MapBufferUsageMask */
      #define GL_MAP_READ_BIT 0x0001
      #define GL_MAP_READ_BIT_EXT 0x0001
      #define GL_MAP_WRITE_BIT 0x0002
      #define GL_MAP_WRITE_BIT_EXT 0x0002
      ...

Tested for regressions with:
    piglit run -p x11_egl -x glx -x glean
    Mesa 10.2.1
    Intel Ivybridge
    Fedora 20

v3, for Dylan:
  - Replace ElementTree with cElementTree, for speed.
  - Each method $foo in KeyedOrderedSet that returns
    a generator, rename it to iter${foo} to follow Python2 (not 3)
    naming conventions.
  - Python 2.6 lacks OrderedDict, so don't use it.
  - Remove unused import 'dedent'.
  - Python 2.6 does not recognize the syntax for set literals, so
    replace each set literal with a list literal or generator literal.
  - Replace sys.stderr.write with print(file=sys.stderr).
  - Remove hand-coded OrderedKeyedSet.copy and instead use copy module.
  - Prefer the 'lxml' module (it uses libxml2) over Python's builtin 'xml' module.
  - Replace methods ``def foo(x, y):`` with ``def foo(self, other):``.
  - Replace lists with generators in methods Command.c_*_param_list.
  - PEP8: Separate all toplevel items with 2 newlines.
  - PEP8: Fix minor whitespace issues.
  - PEP8: Replace some ``== None`` with ``is None``.
  - Replace None-check for --out-dir with add_argument(..., required=True)
  - Remove 'prog' assignment when calling ArgumentParser(prog=PROG_NAME).
    Instead, use default value

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
glapi: Remove the glapi directory

Piglit no longer uses the directory because it now generates
piglit-dispatch from the Khronos XML.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Generate piglit_get_gl_enum_name() and friends

This patch removes the files "piglit-util-gl*-enum.c" and replaces them
with a single file "piglit-util-gl-enum-gen.c" generated from the
Khronos XML.

The two functions now generated are:
    piglit_get_gl_enum_name(GLenum param)
    piglit_get_prim_name(GLenum prim)

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Remove unused files piglit-util-gl*-enum.c

The generated file piglit-util-gl-enum-gen.c has replaced them.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
dispatch: Use piglit-dispatch for GLES1

After having migrated piglit-dispatch to the Khronos XML,
moving GLES1 to piglit-dispatch was easy. This patch:

  1. Fixes gl_wrap.h to include piglit-dispatch-gen.h instead of
     <GLES/*.h>.
  2. Deletes some ugly macro workarounds for GLES1 that piglit-dispatch
     obsoletes.
  3. Add piglit-dispatch*.c to libpiglitutil_gles1 in the CMake.
  4. Call piglit_dispatch_init(PIGLIT_DISPATCH_ES1).

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cmake: Don't link to libGLESv1

Now that the GLES1 tests use piglit-dispatch, they no longer need to
link to the GLES1 library.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
gl-3.0-render-integer: add a new test for rendering to integer textures

Reviewed-by: Charmaine Lee <charmainel@vmware.com>
arb_uniform_buffer_object/maxblocks: minor whitespace fix
gleantest_tests.py: Make one test more robust

The test for glean returncodes relied on unsetting os.environ to cause
glean to fail. This is fairly reliable, but it is possible to break it.
A much more robust implementation is to just set
instance.result['returncode'] = 1 and then run interpret_result(), with
the added bonus of focusing the test better.

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
utils.py: add boilerplate to work around nose bug

The gist of the bug is that the way nose uses generators to create tests
it yields the same instance multiple times, and it uses an instance
attribute to set the name of the test. It then prints the results of the
tests all at once, meaning that the final assignment of that instance
attribute is displayed for all failing tests.

The class is a proxy object that is used to create a unique instance for
each test. This works around the bug since the attribute that stores the
test description isn't overwritten each time a new test is generated.

The decorator is used for generators to transparently replace the
function yielded by the test generator with a proxy object. This allows
generated tests to return the correct name; all without any modification
to the test generator. This means that if nose ever solves this problem
making use of nose's solution is a single deleted line per generator.

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
core_tests.py: Use the utils.nose_generator decorator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
dmesg_tests.py: Use utils.nose_generator decorator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
log_tests.py: use utils.nose_generator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
status_tests.py: use utils.nose_generator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
summary_tests.py: use utils.nose_generator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
test_lists.py: use utils.nose_generator

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
status_tests.py: Convert large test case into generator

This gives more fine-grained results