[Piglit] [PATCH 2/2] util: Add function piglit_check_gl_error

Chad Versace chad at chad-versace.us
Fri Aug 19 12:03:21 PDT 2011


This checks for unexpected GL errors and terminates the test if an
unexpected error is enountered.

v2: unchanged

CC: Henri Verbeet <hverbeet at gmail.com>
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 tests/util/piglit-util.c |   37 +++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.h |    8 ++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 84f6942..75020f7 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -168,6 +168,43 @@ const char* piglit_get_gl_error_name(GLenum error)
     }
 }
 
+void piglit_check_gl_error(GLenum expected_error, enum piglit_result result)
+{
+	GLenum actual_error;
+	const char *expected_name;
+	const char *actual_name;
+
+	actual_error = glGetError();
+	if (actual_error == expected_error) {
+		return;
+	}
+
+	/*
+	 * If the lookup of the error's name is successful, then print
+	 *     Unexpected GL error: NAME 0xHEX
+	 * Else, print
+	 *     Unexpected GL error: 0xHEX
+	 */
+	printf("Unexpected GL error:");
+	actual_name = piglit_get_gl_error_name(actual_error);
+	if (actual_name) {
+		printf(" %s", actual_name);
+	}
+	printf(" 0x%x\n", actual_error);
+
+	/* Only print the expected error if an error was really expected. */
+	if (expected_error != GL_NO_ERROR) {
+		printf("Expected GL error:");
+		expected_name = piglit_get_gl_error_name(expected_error);
+		if (expected_name) {
+			printf(" %s", expected_name);
+		}
+		printf(" 0x%x\n", expected_error);
+	}
+
+	piglit_report_result(result);
+}
+
 /* These texture coordinates should have 1 or -1 in the major axis selecting
  * the face, and a nearly-1-or-negative-1 value in the other two coordinates
  * which will be used to produce the s,t values used to sample that face's
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 2173148..29ca411 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -126,6 +126,14 @@ bool piglit_is_extension_supported(const char *name);
  */
 const char* piglit_get_gl_error_name(GLenum error);
 
+/**
+ * \brief Check for unexpected GL errors and possibly terminate the test.
+ *
+ * If glGetError() returns an error other than \c expected_error, then
+ * print a diagnostic and terminate the test with the given \c result.
+ */
+void piglit_check_gl_error(GLenum expected_error, enum piglit_result result);
+
 int FindLine(const char *program, int position);
 void piglit_report_result(enum piglit_result result);
 void piglit_require_extension(const char *name);
-- 
1.7.6



More information about the Piglit mailing list