[waffle] [PATCH 0/3] Add the waffle_teardown API

Emil Velikov emil.l.velikov at gmail.com
Fri Jan 30 08:21:25 PST 2015


On 20 January 2015 at 18:46, Chad Versace <chad.versace at intel.com> wrote:
> On 01/15/2015 05:31 AM, Emil Velikov wrote:
>> On 15 January 2015 at 15:21, Emil Velikov <emil.l.velikov at gmail.com> wrote:
>>> Hello all,
>>>
>>> As mentioned a while back, here is the function waffle_teardown. Its purpose
>>> is to cleanup the global state (the api_platform variable and the respective
>>> platform private data).
>>>
>>> This makes valgrind a bit happier (-20k of still reachable) and will allow
>>> the user to use multiple platforms within a single application. For example
>>>
>>> static const int32_t init_attribs_list[][] = {
>>>  { WAFFLE_PLATFORM, WAFFLE_PLATFORM_GLX, 0 },
>>>  { WAFFLE_PLATFORM, WAFFLE_PLATFORM_X11_EGL, 0 },
>>> };
>>>
>>> for (i = 0, i < ARRAYSIZE(init_attribs_list[]), i++) {
>>>    waffle_init(WAFFLE_PLATFORM_GLX);
>>>    ...
>>>    waffle_teardown()
>>> }
>>>
>>>
>>>
>>> I'm not 100% happy with the function name - waffle_teardown, so if you have
>>> any suggestions please put them forward.
>>>
>>> This work has pointed out a bug (leak) in mesa's libGL/dri2 implementation,
>>> which I'll send a patch for shortly.
>>>
>>> The series can be found in my repo in the wip/waffle-teardown branch.
>>>
>> Forgot to mention - I would like to make use of this in gl_basic_test,
>> yet the level of macros is getting the best of me.
>> If anyone has any tips that would be appreciated.
>
> The gl_basic_draw() macro simulates a function having named parameters
> with default values. It relies on the C99 behavior that, in a designated
> struct initializer, members may be initialized multiple times and the
> last initialization wins.
>
> #define gl_basic_draw(...) \
>     \
>     gl_basic_draw__((struct gl_basic_draw_args__) { \
>         .api = 0, \
>         .version = WAFFLE_DONT_CARE, \
>         .profile = WAFFLE_DONT_CARE, \
>         .forward_compatible = false, \
>         .debug = false, \
>         .alpha = false, \
>         .expect_error = WAFFLE_NO_ERROR, \
>         __VA_ARGS__ \
>         })
>
> For example, here are some syntactically valid uses of the macro:
>
>     gl_basic_draw(.version = 79, .debug = true);
>     gl_basic_draw(.version = 63, .debug = false, .expect_error = WAFFLE_ERROR_BAD_ATTRIBUTE);
>
> If you want to ensure that waffle_teardown is called at the end of each successful call to
> gl_basic_draw(), I think you need the below diff. But, I don't exactly know your plans, so
> I'm just guessing.
>
Hi Chad,

I've been meaning to address the leaks that gl_basic_test produces and
was hoping that waffle_teardown will make it easier.
After a long hard look at this here is my overall idea and my current
on fixing it:

Needed:
 - (Optional) Avoid the tests if *init fails.
 - Keep track if waffle_init was successful and it so run the
waffle_teardown test.
 - Cleanup the leaks - check and call the relevant dtors prior to each
of TEST_* and ASSERT_TRUE

My idea:
 - Drop the *_init test and fold it in as the wt_runner's setup hook.
 - Move the test's storage (struct waffle_{display,dpy...} *) as a global.
 - Fold a complete teardown - ctx, window.... waffle_teardown()) in
the wt_runner's teardown hook.
 - Keep the asserts on teardown, but do a null check prior to calling
the relevant dtor.
 - Wire up for the wt_runner teardown hook to be executed on TEST_*
and ASSERT_TRUE.
 - Add TEST_PASS() at the end of the gl_basic_draw__() function.

Imho it's a rather clever solution, yet depending on one's POV it
might look messy :P

What are your thoughts on this ?

Cheers,
Emil


More information about the waffle mailing list