[Piglit] [PATCH 3/5] util: Add piglit_expect_egl_error()

Chad Versace chad at chad-versace.us
Wed Oct 19 18:37:48 PDT 2011


This function checks for unexpected EGL errors.  If eglGetError() returns
an unexpected error, then this it prints a diagnostic and terminates the
test.

Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 tests/util/CMakeLists.txt    |    7 ++++
 tests/util/piglit-util-egl.c |   76 ++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-egl.h |   55 ++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 0 deletions(-)
 create mode 100644 tests/util/piglit-util-egl.c
 create mode 100644 tests/util/piglit-util-egl.h

diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index 3daccea..798cd8a 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -17,4 +17,11 @@ set(UTIL_SOURCES
 	rgb9e5.c
 	)
 
+if(OPENGL_egl_LIBRARY)
+	set(UTIL_SOURCES
+	    ${UTIL_SOURCES}
+	    piglit-util-egl.c
+	    )
+endif(OPENGL_egl_LIBRARY)
+
 piglit_include_target_api()
diff --git a/tests/util/piglit-util-egl.c b/tests/util/piglit-util-egl.c
new file mode 100644
index 0000000..b286ee5
--- /dev/null
+++ b/tests/util/piglit-util-egl.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) Intel 2011
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "piglit-util-egl.h"
+
+const char* piglit_get_egl_error_name(EGLint error) {
+#define CASE(x) case x: return #x;
+    switch (error) {
+    CASE(EGL_SUCCESS)
+
+    CASE(EGL_BAD_ACCESS)
+    CASE(EGL_BAD_ALLOC)
+    CASE(EGL_BAD_ATTRIBUTE)
+    CASE(EGL_BAD_CONFIG)
+    CASE(EGL_BAD_CONTEXT)
+    CASE(EGL_BAD_CURRENT_SURFACE)
+    CASE(EGL_BAD_DISPLAY)
+    CASE(EGL_BAD_MATCH)
+    CASE(EGL_BAD_NATIVE_PIXMAP)
+    CASE(EGL_BAD_NATIVE_WINDOW)
+    CASE(EGL_BAD_PARAMETER)
+    CASE(EGL_BAD_SURFACE)
+    CASE(EGL_CONTEXT_LOST)
+    CASE(EGL_NOT_INITIALIZED)
+    default:
+        return "(unrecognized error)";
+    }
+#undef CASE
+}
+
+void piglit_expect_egl_error(EGLint expected_error, enum piglit_result result)
+{
+	EGLint actual_error;
+
+	actual_error = eglGetError();
+	if (actual_error == expected_error) {
+		return;
+	}
+
+	/*
+	 * If the lookup of the error's name is successful, then print
+	 *     Unexpected EGL error: NAME 0xHEX
+	 * Else, print
+	 *     Unexpected EGL error: 0xHEX
+	 */
+	printf("Unexpected EGL error: %s 0x%x\n",
+               piglit_get_egl_error_name(actual_error), actual_error);
+
+	/* Print the expected error, but only if an error was really expected. */
+	if (expected_error != EGL_SUCCESS) {
+		printf("Expected EGL error: %s 0x%x\n",
+		piglit_get_gl_error_name(expected_error), expected_error);
+        }
+
+	piglit_report_result(result);
+}
diff --git a/tests/util/piglit-util-egl.h b/tests/util/piglit-util-egl.h
new file mode 100644
index 0000000..1fa68e5
--- /dev/null
+++ b/tests/util/piglit-util-egl.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) Intel 2011
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <EGL/egl.h>
+
+#include "piglit-util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Convert an EGL error to a string.
+ *
+ * For example, given EGL_BAD_DRAWABLE, return "EGL_BAD_DRAWABLE".
+ *
+ * Return "(unrecognized error)" if the enum is not recognized.
+ */
+const char* piglit_get_egl_error_name(EGLint error);
+
+/**
+ * \brief Check for unexpected EGL errors and possibly terminate the test.
+ *
+ * If eglGetError() returns an error other than \c expected_error, then
+ * print a diagnostic and terminate the test with the given result.
+ *
+ * If you expect no error, then set \code expected_error = EGL_SUCCESS \endcode.
+ */
+void piglit_expect_egl_error(EGLint expected_error, enum piglit_result result);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
-- 
1.7.6.4



More information about the Piglit mailing list