[Piglit] [PATCH 2/9] Simplify piglit_glx_get_all_proc_addresses API.

Jamey Sharp jamey at minilop.net
Wed Apr 23 17:27:16 PDT 2014


I couldn't stand the number of ways this API could be misused and the
amount of code duplication it forced--two closely related issues.

This also fixes a bug: The "Failed to get function pointer" test could
never have triggered unless the caller passed incorrect arguments,
which is not the kind of error it was intended to be testing for.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
Signed-off-by: Theo Hill <Theo0x48 at gmail.com>
---
 tests/spec/glx_ext_import_context/common.c | 27 ++++++++++-----------------
 tests/spec/glx_oml_sync_control/common.c   | 30 +++++++++++-------------------
 tests/spec/glx_oml_sync_control/common.h   | 10 +++++-----
 tests/util/piglit-glx-util.c               | 11 +++++------
 tests/util/piglit-glx-util.h               | 10 ++++++++--
 5 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/tests/spec/glx_ext_import_context/common.c b/tests/spec/glx_ext_import_context/common.c
index 9048472..862dd36 100644
--- a/tests/spec/glx_ext_import_context/common.c
+++ b/tests/spec/glx_ext_import_context/common.c
@@ -31,6 +31,15 @@ PFNGLXGETCONTEXTIDEXTPROC __piglit_glXGetContextIDEXT = NULL;
 PFNGLXIMPORTCONTEXTEXTPROC __piglit_glXImportContextEXT = NULL;
 PFNGLXFREECONTEXTEXTPROC __piglit_glXFreeContextEXT = NULL;
 
+#define ADD_FUNC(name) PIGLIT_GLX_PROC(__piglit_##name, name)
+static const struct piglit_glx_proc_reference procedures[] = {
+	ADD_FUNC(glXGetCurrentDisplayEXT),
+	ADD_FUNC(glXQueryContextInfoEXT),
+	ADD_FUNC(glXGetContextIDEXT),
+	ADD_FUNC(glXImportContextEXT),
+	ADD_FUNC(glXFreeContextEXT),
+};
+
 Display *dpy = NULL;
 XVisualInfo *visinfo = NULL;
 GLXContext directCtx = NULL;
@@ -63,22 +72,6 @@ void GLX_EXT_import_context_setup_for_child(void)
 
 void GLX_EXT_import_context_setup(void)
 {
-	const char *const names[] = {
-		"glXGetCurrentDisplayEXT",
-		"glXQueryContextInfoEXT",
-		"glXGetContextIDEXT",
-		"glXImportContextEXT",
-		"glXFreeContextEXT"
-	};
-
-	__GLXextFuncPtr *procedures[ARRAY_SIZE(names)] = {
-		(__GLXextFuncPtr *) & __piglit_glXGetCurrentDisplayEXT,
-		(__GLXextFuncPtr *) & __piglit_glXQueryContextInfoEXT,
-		(__GLXextFuncPtr *) & __piglit_glXGetContextIDEXT,
-		(__GLXextFuncPtr *) & __piglit_glXImportContextEXT,
-		(__GLXextFuncPtr *) & __piglit_glXFreeContextEXT
-	};
-
 	const char *vendor;
 
 	dpy = piglit_get_glx_display();
@@ -113,7 +106,7 @@ void GLX_EXT_import_context_setup(void)
 		piglit_require_glx_extension(dpy, "GLX_EXT_import_context");
 	}
 
-	piglit_glx_get_all_proc_addresses(procedures, names, ARRAY_SIZE(names));
+	piglit_glx_get_all_proc_addresses(procedures, ARRAY_SIZE(procedures));
 
 	visinfo = piglit_get_glx_visual(dpy);
 
diff --git a/tests/spec/glx_oml_sync_control/common.c b/tests/spec/glx_oml_sync_control/common.c
index d5011a8..b83e886 100644
--- a/tests/spec/glx_oml_sync_control/common.c
+++ b/tests/spec/glx_oml_sync_control/common.c
@@ -39,6 +39,16 @@ PFNGLXGETMSCRATEOMLPROC __piglit_glXGetMscRateOML;
 PFNGLXSWAPBUFFERSMSCOMLPROC __piglit_glXSwapBuffersMscOML;
 PFNGLXWAITFORMSCOMLPROC __piglit_glXWaitForMscOML;
 PFNGLXWAITFORSBCOMLPROC __piglit_glXWaitForSbcOML;
+
+#define ADD_FUNC(name) PIGLIT_GLX_PROC(__piglit_##name, name)
+static const struct piglit_glx_proc_reference procs[] = {
+	ADD_FUNC(glXGetSyncValuesOML),
+	ADD_FUNC(glXGetMscRateOML),
+	ADD_FUNC(glXSwapBuffersMscOML),
+	ADD_FUNC(glXWaitForMscOML),
+	ADD_FUNC(glXWaitForSbcOML),
+};
+
 Window win;
 XVisualInfo *visinfo;
 
@@ -47,24 +57,6 @@ piglit_oml_sync_control_test_run(enum piglit_result (*draw)(Display *dpy))
 {
 	Display *dpy;
 	GLXContext ctx;
-	const int proc_count = 5;
-	__GLXextFuncPtr *procs[proc_count];
-	const char *names[proc_count];
-	int i;
-
-#define ADD_FUNC(name)							\
-	do {								\
-		procs[i] = (__GLXextFuncPtr *)&(__piglit_##name);	\
-		names[i] = #name;					\
-		i++;							\
-	} while (0)
-
-	i = 0;
-	ADD_FUNC(glXGetSyncValuesOML);
-	ADD_FUNC(glXGetMscRateOML);
-	ADD_FUNC(glXSwapBuffersMscOML);
-	ADD_FUNC(glXWaitForMscOML);
-	ADD_FUNC(glXWaitForSbcOML);
 
 	dpy = XOpenDisplay(NULL);
 	if (dpy == NULL) {
@@ -73,7 +65,7 @@ piglit_oml_sync_control_test_run(enum piglit_result (*draw)(Display *dpy))
 	}
 
 	piglit_require_glx_extension(dpy, "GLX_OML_sync_control");
-	piglit_glx_get_all_proc_addresses(procs, names, ARRAY_SIZE(procs));
+	piglit_glx_get_all_proc_addresses(procs, ARRAY_SIZE(procs));
 
 	visinfo = piglit_get_glx_visual(dpy);
 	win = piglit_get_glx_window(dpy, visinfo);
diff --git a/tests/spec/glx_oml_sync_control/common.h b/tests/spec/glx_oml_sync_control/common.h
index c06bdd7..40ef4a3 100644
--- a/tests/spec/glx_oml_sync_control/common.h
+++ b/tests/spec/glx_oml_sync_control/common.h
@@ -1,8 +1,8 @@
-#define glXGetSyncValuesOML __piglit_glXGetSyncValuesOML
-#define glXGetMscRateOML __piglit_glXGetMscRateOML
-#define glXSwapBuffersMscOML __piglit_glXSwapBuffersMscOML
-#define glXWaitForMscOML __piglit_glXWaitForMscOML
-#define glXWaitForSbcOML __piglit_glXWaitForSbcOML
+#define glXGetSyncValuesOML(dpy, drawable, ust, msc, sbc) __piglit_glXGetSyncValuesOML(dpy, drawable, ust, msc, sbc)
+#define glXGetMscRateOML(dpy, drawable, numerator, denominator) __piglit_glXGetMscRateOML(dpy, drawable, numerator, denominator)
+#define glXSwapBuffersMscOML(dpy, drawable, target_msc, divisor, remainder) __piglit_glXSwapBuffersMscOML(dpy, drawable, target_msc, divisor, remainder)
+#define glXWaitForMscOML(dpy, drawable, target_msc, divisor, remainder, ust, msc, sbc) __piglit_glXWaitForMscOML(dpy, drawable, target_msc, divisor, remainder, ust, msc, sbc)
+#define glXWaitForSbcOML(dpy, drawable, target_sbc, ust, msc, sbc) __piglit_glXWaitForSbcOML(dpy, drawable, target_sbc, ust, msc, sbc)
 
 extern PFNGLXGETSYNCVALUESOMLPROC __piglit_glXGetSyncValuesOML;
 extern PFNGLXGETMSCRATEOMLPROC __piglit_glXGetMscRateOML;
diff --git a/tests/util/piglit-glx-util.c b/tests/util/piglit-glx-util.c
index 3805618..1faec8f 100644
--- a/tests/util/piglit-glx-util.c
+++ b/tests/util/piglit-glx-util.c
@@ -468,19 +468,18 @@ piglit_glx_error_string(int err)
  * \c piglit_report_result with \c PIGLIT_FAIL.
  */
 void
-piglit_glx_get_all_proc_addresses(__GLXextFuncPtr **procedures,
-				  const char *const *names,
+piglit_glx_get_all_proc_addresses(const struct piglit_glx_proc_reference *procedures,
 				  unsigned num)
 {
 	unsigned i;
 
 	for (i = 0; i < num; i++) {
-		*(procedures[i]) =
-			glXGetProcAddress((const GLubyte *) names[i]);
-		if (procedures[i] == NULL) {
+		*procedures[i].procedure =
+			glXGetProcAddress((const GLubyte *) procedures[i].name);
+		if (*procedures[i].procedure == NULL) {
 			fprintf(stderr,
 				"Failed to get function pointer for %s.\n",
-				names[i]);
+				procedures[i].name);
 			piglit_report_result(PIGLIT_FAIL);
 		}
 	}
diff --git a/tests/util/piglit-glx-util.h b/tests/util/piglit-glx-util.h
index e74ac29..aebed15 100644
--- a/tests/util/piglit-glx-util.h
+++ b/tests/util/piglit-glx-util.h
@@ -65,7 +65,13 @@ piglit_glx_get_error(Display *dpy, XErrorEvent *err);
 const char *
 piglit_glx_error_string(int err);
 
+struct piglit_glx_proc_reference {
+	__GLXextFuncPtr *procedure;
+	const char *name;
+};
+
+#define PIGLIT_GLX_PROC(var, name) { (__GLXextFuncPtr *)&(var), #name }
+
 void
-piglit_glx_get_all_proc_addresses(__GLXextFuncPtr **procedures,
-				  const char *const *names,
+piglit_glx_get_all_proc_addresses(const struct piglit_glx_proc_reference *procedures,
 				  unsigned num);
-- 
1.8.5.3



More information about the Piglit mailing list