Save and restore platform for piglit

This patch adds support in piglit-run to save the -p platform
information if it was provided, and adds support in piglit-resume to
restore this information if it is stored.

Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
Simplify piglit threading

This patch simplifies threading in piglit by removing the hand-rolled
threadpool, and instead using the Pool class from multiprocessing.dummy.
This provides a map interface, allowing for very clear succinct code.

The previous implementation ran all tests out of thread pools, a serial
pool and a multi-threaded pool. This patch does the same thing for a
couple of reasons. First, the obvious solution is to use the map()
builtin for serial tests. However, map in python3 returns an iterator
instead of a list so calling map(f, x) will not actually run f(x) until
something tries to use those values. This would require considerable
restructuring to work around. Second, that could easily be split out
into another patch, and limits the number of changes in this patch.

Multiproccessing.dummy is a wrapper around the Threading module,
providing the multiproccessing API, but with threads instead of
processes.

V2: - Renamed run() helper to test()
    - use multiprocessing.dummy.Pool() default thread count value, which
      is equal to multiproccessing.cpu_count(), instead of cpu_count()
      explicitly
V3: - use Pool.imap() instead of Pool.map(), it is slightly faster.
V4: - Remove use of map() builtin

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
cmake: Fix waffle version requirement

CMake is so stupid sometimes :(

When building with waffle, piglit requires waffle >= 1.2.2. Piglit's
CMake captures the required by calling

    pkg_check_modules(WAFFLE REQUIRED waffle-1>=1.2.2)

However, we cannot reliably check the version with pkg_check_modules(). The
problem is that, if one passes a required version to pkg_check_modules(), CMake
validates the required version at most once for the lifetime of the source tree.
If someone changes the required version by editing the CMakeLists, CMake fails
to detect the new requirement.

To workaround this deficiency of CMake, check the version instead with

    if(WAFFLE_VERSION VERSION_LESS 1.2.2)

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
cmake: If using Waffle, require waffle >= 1.3

Subsequent patches will enable creation of forward-compatible and debug
contexts, which arrived in waffle-1.3.

After this patch, you may need to remove CMakeCache.txt and rerun CMake. The
problem is that CMake caches the results of pkg-config queries.  Alternatively,
you may manually update the value of CMakeCache.txt:WAFFLE_VERSION in any text
editor.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/waffle: Print more info when context creation fails

When waffle_config_choose() or waffle_context_create() fails, print
Waffle's error message to stderr. Several people (Carl, Ian, Timothy
Arceri) have requested this.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Tested-by: Timothy Arceri <t_arceri@yahoo.com.au>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/wfl: Refactor make_context_current_singlepass()

Let make_context_current_singlepass() directly call
waffle_config_choose(). Add helper function make_config_attrib_list()
that makes the attribute list passed to waffle_config_choose(). This
refactor will make possible better error messages.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Tested-by: Timothy Arceri <t_arceri@yahoo.com.au>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/waffle: Improve error messages when context creation fails

Unify the 3 occurences of message "Failed to create ... context", and
move the message closer to the failure.

Print a more helpful message when special_case_gl_31() fails.

Add helper function make_context_description(), used in the newer better
error messages.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Tested-by: Timothy Arceri <t_arceri@yahoo.com.au>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/gl: Support creation of forward-compatible contexts

Add a new boolean flag to the PIGLIT_GL_TEST_CONFIG block,
`config.require_forward_compatible_context`. If the test is unable to
create a foward-compatible context, then the test skips.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/gl: Support creation of debug contexts

Add a new boolean flag to the PIGLIT_GL_TEST_CONFIG block,
`config.require_debug_context`. If the test is unable to create a debug
context, then the test skips.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Tested-by: Timothy Arceri <t_arceri@yahoo.com.au>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
util/wfl: Remove hacks for compat contexts

When a test requested a compatibility context, Piglit did not pass the
context version to Waffle. Instead, Piglit requested an unversioned
compatibility context and then verified with piglit_get_gl_version()
that the actual version was >= requested version.

This hack prevented Piglit from creating forward-compatible contexts,
because, according to thw EGL_KHR_create_context spec, "requesting
a forward-compatible context for OpenGL versions less than
3.0 will generate an error."

Remove the hack. Pass the requested context version to Waffle.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Tested-by: Timothy Arceri <t_arceri@yahoo.com.au>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
gl-3.0: Add test for the forward-compatible bit

Create a context with or without the forward-compatible bit, according to
a command line flag.  Then verify that GL_CONTEXT_FLAGS does or does not
contain GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
*.tests: set __all__ = ['profile']

This makes the only publicly declared object in the .tests files the
profile object. This is groundwork for importing the profile rather than
running it via execfile().

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
Add support to load multiple test profiles

This patch gives piglit run the ability to take one or more test
proflies as arguments rather than just one. It loads the profiles,
merging them from left to right, overwriting conflicting results. This
will allow the oglconform and es3conform loaders to be taken out of
all.tests.

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
all.tests: Remove execfile(es3conform.tests)

This option is now redundant, since it can be given explicitly at the
command-line.

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
tests/all.tests: Remove unused blacklist feature

This feature is never used (nor does it seem like it should ever have
been used), so lets get rid of it.

V2: - split this out of the next patch

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
tests/all.py: load glean glsl, frag, and vert tests internally

This patch converts the glean glsl1, fragPrgo1, and vertProg1 tests from
external files that are called by execfile into lists of arguments, and
uses a loop to add the tests.

This removes test files that are not in fact loadable test files, and
lack a TestProfile instance, which means they will not be importable.

V2: - rename glean_glsl1_tests to glean_glsl_tests
    - rename glean_frag_tests to glean_fp_tests
    - rename glean_vert_Tests to glean_vp_tests
    - split removal of blacklist out of this patch

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
Rename all tests files from .tests to .py

This patch renames the .tests files to .py files; which is required for
the python interpreter to allow importing them.

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
tests: treat the tests folder as part of the python package

By adding __init__.py to tests folder python can search that folder for
modules to import.

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
tests/sanity.tests: Make sanity.tests importable

This allows sanity.py to export a profile instance, meaning it can be
used as an import instead of an execfile.

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
quick.tests: Make quick.tests import all.tests

Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>