On 06/20/2012 02:32 AM, Kenneth Graunke wrote:
> On 06/12/2012 04:02 PM, Chad Versace wrote:
>> 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.vers...@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
> 
> I would coalesce these into one block, to be a bit more concise:
>
> #ifdef __cplusplus
> #  define _PIGLIT_GL_TEST_EXTERN_C_BEGIN extern "C" {
> #  define _PIGLIT_GL_TEST_EXTERN_C_END }
> #else
> #  define _PIGLIT_GL_TEST_EXTERN_C_BEGIN
> #  define _PIGLIT_GL_TEST_EXTERN_C_END
> #endif

Good idea. I'll do that before pushing the series today.

> You probably could also just call them EXTERN_C_BEGIN and EXTERN_C_END.
>  It looks like a few other projects use that convention, though not any
> we'd #include headers from (which could cause conflicts).

I generally frown upon public headers that define non-prefixed symbols for 
commonly used names.
Wayland does that for container_of(), and it has caused all sorts of problems 
with Waffle. I'm
going to keep the PIGLIT_ prefix, but thanks for the advice.
_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to