util: Add func streq()

Please. Let's stop writing `!strcmp(...)` and `strcmp(...) == 0`.  This
patch defines a little function streq() that reads much more nicely than
idioms using strcmp.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Refactor parsing subtest args

Pre-patch, piglit-framework-gl.c:process_args() parsed subtest args
'-subtest' and '-list-subtests' with inline code. This patch moves that
code to a new function, piglit_parse_subtest_args().

This prepares for using Piglit's subtest magic in non-GL tests.
Currently, all the code for subtests lives in GL-dependent file
piglit-framework-gl.c, and must be moved to the API-independent file
piglit-util.c so that non-GL tests can use it.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/gl: Reject unrecongized subtest names

If the user specifies "-subtest $NAME" on the command line, but
the test defines no subtest with that name, then
piglit_parse_subtest_args() now reports PIGLIT_FAIL.

The test should fail early as possible on usage errors. Pre-patch, if
the user requested an invalid subtest name, the test did not fail until
it attempted to execute the invalid subtest. Post-patch, the test fails
during arg parsing.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/gl: Rename struct piglit_gl_subtest -> piglit_subtest

This prepares for using Piglit's subtest magic in non-GL tests.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/gl: Rename PIGLIT_GL_SUBTEST_END -> PIGLIT_SUBTEST_END

This prepares for using Piglit's subtest magic for non-GL tests.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Move subtest utils to API-independent files

Pre-patch, piglit-framework-gl.{c,h} defined the function and structs
for working with subtests. This patch moves them to piglit-util.{c,h},
so that they become available for non-GL tests.

This is simply a copy-paste patch. The patch does not modify the
relocated code.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/egl: Add EGLDisplay parameter to piglit_require_egl_extension()

Without an explicit EGLDisplay parameter, it's not possible to call
piglit_require_egl_extension() without first binding the display to
a context with eglMakeCurrent(). Some EGL tests, though, will never need
to or want to create a context.

Also, this makes the signature of piglit_require_egl_extension()
match that of piglit_is_egl_extension_supported().

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/egl: Add piglit_egl_get_default_display()

This function gets the default display for the given platform.

If the given platform platform is EGL_NONE, the the function wraps
eglGetDisplay().  Otherwise, it wraps eglGetPlatformDisplayEXT().  If
EGL does not support the platform extension for the given platform, then
it returns EGL_NO_DISPLAY.

This is useful for EGL tests that need to create a display for
a specific platform.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Add func piglit_gettid()

On Linux, piglit_gettid() wraps the gettid() syscall.
It returns 0 on unsupported systems.

This is useful for printing messages in multi-threaded tests.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util/log: Add logging module

Add new header piglit-log.h which exposes the following functions:
    piglit_log_get_opt()
    piglit_log_set_opt()
    piglit_loge()
    piglit_logi()

This new module should help to reduce redundant logging boilerplate
found in many Piglit files.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Use piglit-log in piglit-util.c

This patch replaces each occurence of printf in piglit-util.c, when
appropriate, with piglit_loge() or piglit_logi().

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cmake: Check for pthreads

Set PIGLIT_HAS_PTHREADS as a CMake variable and cpp feature macro if
CMake succeeds in compiling a small test file that uses pthread_self(),

Future EGL_KHR_fence_sync tests will be multi-threaded.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
EGL_KHR_fence_sync: Add conformance tests

Add the following subtests:
  eglCreateSyncKHR_default_attributes
  eglCreateSyncKHR_invalid_display
  eglCreateSyncKHR_invalid_attrib_list
  eglCreateSyncKHR_wrong_display_same_thread
  eglCreateSyncKHR_with_display_bound_in_other_thread
  eglCreateSyncKHR_invalid_sync_type
  eglCreateSyncKHR_no_current_context
  eglGetSyncAttribKHR_invalid_sync
  eglGetSyncAttribKHR_invalid_attrib
  eglGetSyncAttribKHR_sync_status
  eglClientWaitSyncKHR_invalid_flag
  eglClientWaitSyncKHR_zero_timeout
  eglClientWaitSyncKHR_flag_sync_flush
  eglClientWaitSyncKHR_invalid_sync
  eglClientWaitSyncKHR_nonzero_timeout
  eglDestroySyncKHR_invalid_sync

The set of tests exhaustively cover the EGL_KHR_fence_sync spec, except
for two excerpts documented in the TODO section of the test file.

On Mesa, all tests currently skip.

I did not validate the tests against an existing implementation of
EGL_KHR_fence_sync because I have no access to one. To my knowledge,
Android and ARM ChromeOS provide EGL_KHR_fence_sync, but no desktop EGL
does (except maybe NVidia's recently released 32-bit EGL for Linux).

When an implementation arrives in Mesa, or when someone runs the tests
on ARM, we will likely discover some latent bugs in the tests.

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