[Piglit] [PATCH 2/3] util/egl: Add piglit_egl_bind_api()

Chad Versace chad.versace at linux.intel.com
Fri Sep 20 19:02:19 PDT 2013


This is a wrapper for eglBindAPI() that does error-checking.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/util/piglit-util-egl.c | 31 +++++++++++++++++++++++++++++++
 tests/util/piglit-util-egl.h | 12 ++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/tests/util/piglit-util-egl.c b/tests/util/piglit-util-egl.c
index 5de93b8..6ba9489 100644
--- a/tests/util/piglit-util-egl.c
+++ b/tests/util/piglit-util-egl.c
@@ -92,3 +92,34 @@ void piglit_require_egl_extension(const char *name)
 		piglit_report_result(PIGLIT_SKIP);
 	}
 }
+
+bool
+piglit_egl_bind_api(EGLenum api)
+{
+	const char *api_string = "";
+
+	if (eglBindAPI(api))
+		return true;
+
+	if (api == EGL_OPENGL_API)
+		api_string = "EGL_OPENGL_API";
+	else if (api == EGL_OPENGL_ES_API)
+		api_string = "EGL_OPENGL_ES_API";
+	else
+		assert(0);
+
+	if (piglit_check_egl_error(EGL_BAD_PARAMETER)) {
+		fprintf(stderr, "eglBindAPI(%s) failed because EGL "
+				"does not support the API",
+			api_string);
+		return false;
+	} else {
+		fprintf(stderr, "unexpected error for "
+				"eglBindAPI(%s)\n",
+				api_string);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	assert(0);
+	return false;
+}
diff --git a/tests/util/piglit-util-egl.h b/tests/util/piglit-util-egl.h
index 2586141..be4e452 100644
--- a/tests/util/piglit-util-egl.h
+++ b/tests/util/piglit-util-egl.h
@@ -61,6 +61,18 @@ bool piglit_is_egl_extension_supported(EGLDisplay egl_dpy, const char *name);
  */
 void piglit_require_egl_extension(const char *name);
 
+/**
+ * \brief Wrapper for eglBindAPI().
+ *
+ * Return true if eglBindAPI succeeds. Return false if eglBindAPI fails
+ * because the EGL implementation does not support the API; in most cases,
+ * the caller should then report SKIP.
+ *
+ * If eglBindAPI fails for unexpected reasons, then the test fails.
+ */
+bool
+piglit_egl_bind_api(EGLenum api);
+
 #ifdef __cplusplus
 } /* end extern "C" */
 #endif
-- 
1.8.3.1



More information about the Piglit mailing list