[Piglit] [PATCH 11/14] util: Define PIGLIT_GL_TEST_MAIN() and friends
Chad Versace
chad.versace at linux.intel.com
Tue Jun 12 16:02:57 PDT 2012
PIGLIT_GL_TEST_MAIN() defines a boilerplate main() that should be suitable
for most OpenGL test executables.
This patch redefines piglit-framework.c:main() with PIGLIT_GL_TEST_MAIN().
In an upcoming patch, each test executable will define its own main()
likewise.
This patch also defines the following, which are used by
PIGLIT_GL_TEST_MAIN():
struct piglit_gl_test_info
piglit_gl_test_info_init()
piglit_gl_test_run()
Even though piglit_gl_test_run() takes an info struct as input, it does
not yet use that info struct. A follow-on patch fixes this.
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
tests/util/piglit-framework.c | 19 +++++++-
tests/util/piglit-framework.h | 98 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+), 2 deletions(-)
diff --git a/tests/util/piglit-framework.c b/tests/util/piglit-framework.c
index 16b8516..7d9dcce 100644
--- a/tests/util/piglit-framework.c
+++ b/tests/util/piglit-framework.c
@@ -55,6 +55,12 @@ __attribute__((weak)) void piglit_init(int argc, char **argv)
}
#endif
+void
+piglit_gl_test_info_init(struct piglit_gl_test_info *info)
+{
+ memset(info, 0, sizeof(*info));
+}
+
static void
delete_arg(char *argv[], int argc, int arg)
{
@@ -118,10 +124,16 @@ process_args(int *argc, char *argv[])
}
}
-int main(int argc, char *argv[])
+void
+piglit_gl_test_run(int argc, char *argv[],
+ const struct piglit_gl_test_info *info)
{
process_args(&argc, argv);
+ piglit_width = info->window_width;
+ piglit_height = info->window_height;
+ piglit_window_mode = info->window_visual;
+
if (piglit_use_fbo) {
if (!piglit_framework_fbo_init())
piglit_use_fbo = false;
@@ -139,5 +151,8 @@ int main(int argc, char *argv[])
}
assert(false);
- return 0;
}
+
+PIGLIT_GL_TEST_MAIN(piglit_width,
+ piglit_height,
+ piglit_window_mode)
diff --git a/tests/util/piglit-framework.h b/tests/util/piglit-framework.h
index fcf38cf..04894bb 100644
--- a/tests/util/piglit-framework.h
+++ b/tests/util/piglit-framework.h
@@ -23,8 +23,106 @@
#pragma once
+#include <assert.h>
#include <stdbool.h>
+/**
+ * @brief Info needed to run an OpenGL test.
+ *
+ * To run a test, pass this to piglit_gl_test_run().
+ *
+ * This is named piglit_gl_test_info, rather than piglit_test_info, in
+ * order to distinguish it from other test types, such as EGL and GLX tests.
+ *
+ * TODO: Add fields here that declare test requirements on GL context
+ * TODO: flavor, extensions, and window system.
+ */
+struct piglit_gl_test_info {
+ int window_width;
+ int window_height;
+
+ /** A bitmask such as `GLUT_RGBA | GLUT_DOUBLE`. */
+ int window_visual;
+
+ /**
+ * This is called once per test, after the GL context has been created
+ * and made current but before display() is called.
+ */
+ void
+ (*init)(int argc, char *argv[]);
+
+ /**
+ * If the test is run in auto mode, then this is called once after
+ * init(). Otherwise, it is called repeatedly from some ill-defined
+ * event loop.
+ */
+ enum piglit_result
+ (*display)(void);
+};
+
+/**
+ * Initialize @a info with default values.
+ */
+void
+piglit_gl_test_info_init(struct piglit_gl_test_info *info);
+
+/**
+ * Run the OpenGL test described by @a info. Does not return.
+ */
+void
+piglit_gl_test_run(int argc, char *argv[],
+ const struct piglit_gl_test_info *info);
+
+#ifdef __cplusplus
+# define _PIGLIT_GL_TEST_EXTERN_C_BEGIN extern "C" {
+#else
+# define _PIGLIT_GL_TEST_EXTERN_C_BEGIN
+#endif
+
+#ifdef __cplusplus
+# define _PIGLIT_GL_TEST_EXTERN_C_END }
+#else
+# define _PIGLIT_GL_TEST_EXTERN_C_END
+#endif
+
+/**
+ * Define a boilerplate main() that should be suitable for most OpenGL test
+ * executables.
+ */
+#define PIGLIT_GL_TEST_MAIN(_window_width, \
+ _window_height, \
+ _window_visual) \
+ \
+ _PIGLIT_GL_TEST_EXTERN_C_BEGIN \
+ \
+ void \
+ piglit_init(int argc, char *argv[]); \
+ \
+ enum piglit_result \
+ piglit_display(void); \
+ \
+ _PIGLIT_GL_TEST_EXTERN_C_END \
+ \
+ int \
+ main(int argc, char *argv[]) \
+ { \
+ struct piglit_gl_test_info info; \
+ \
+ piglit_gl_test_info_init(&info); \
+ \
+ info.window_width = _window_width; \
+ info.window_height = _window_height; \
+ info.window_visual = _window_visual; \
+ \
+ info.init = piglit_init; \
+ info.display = piglit_display; \
+ \
+ piglit_gl_test_run(argc, argv, &info); \
+ \
+ assert(false); \
+ return 0; \
+ }
+
extern int piglit_automatic;
extern int piglit_window_mode;
--
1.7.10.4
More information about the Piglit
mailing list