[PATCH/RFC] Scanner for tests

Pekka Paalanen ppaalanen at gmail.com
Fri Nov 29 06:36:56 PST 2013

On Fri, 29 Nov 2013 14:52:30 +0100
Marek Ch <mchqwerty at gmail.com> wrote:

> Hi!
> I was looking into wayland's code and I saw static wl_buffer_*
> functions and I thought: These would use a test.. But how to do it
> when they are static? I can take the code and copy it into test
> manually, but that is not good. The code can change..
> I solved it by writting simple scanner that is invoked, just like
> the wayland-scanner, when compiling the code. It searches for
> definitions marked by WL_EXPORT_TEST and if it finds one, it
> copies it into tests-private.c (.h, respectively).
> Test can then be linked together with this file, so it is
> guaranteed, that the test will use the code from current HEAD.
> The adventage is that in order to test static function there's
> no need to delete the static keyword and thus make it public.
> The disadvantage is that if the to-be-tested function uses
> any other static function, it must be exported too.
> To sum it up: this is more like experiment but since it worked
> for me, I'd like to ask you for your comments.
> P.S.
> The first patch included is not important for the scanner but
> I wrote the code having it applied so I attached it too
> (it's a patch a sent to devel-list some time ago).
> The third patch is simple example test of wl_buffer_put.


instead of writing a C language parser to copy stuff around, how about
doing what was done with Weston matrix code? See:


and note UNIT_TEST and MATRIX_TEST_EXPORT that give the test code
access to otherwise static functions.


More information about the wayland-devel mailing list