[PATCH/RFC] Scanner for tests
Bryce W. Harrington
b.harrington at samsung.com
Mon Dec 2 13:18:48 PST 2013
On Fri, Nov 29, 2013 at 04:36:56PM +0200, Pekka Paalanen wrote:
> 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.
I agree this looks like a better approach. I wonder if the define could
be named differently to more clearly indicate that the function is
normally static? So maybe like WL_STATIC_TESTABLE or some such?
More information about the wayland-devel