Skip to content

WIP: internal static tests

Peter Hutterer requested to merge whot/libinput:wip/static-tests into master

We have a bunch of static functions all over the source code, some of which should really have tests. This MR adds the basic scaffolding for enabling such tests, relying on some linker flags so we can get easy access to those test. There are three components here:

  • minicheck.h is a header that uses ELF sections to store the test cases and provides a minimal main() that sets up the check test suite/cases for us. This saves us having to do the check boilerplate in every test file.
  • linker arg -Wl,--unresolved-symbols=ignore-all means we ignore unresolved symbols, so we can #include any source file to get access to the static functions
  • linker arg -Wl,-zmuldefs allows for multiple definitions so we can add the source file to the meson executable. This isn't strictly required but nice for convenience (and that meson rebuilds correctly)

Our default test file for a source file foo.c then looks like this:

#include "minicheck.h"
#include "foo.c"

MINICHECK_START(test_some_function)
{
   ck_assert(some_function());
}
MINICHECK_END

And the minimum required meson snippet would be:

+       test('test-foo',
+            executable('test-foo',
+                       'foo.c', 'test-foo.c', 'minicheck.h',
+                       dependencies : [dep_check],
+                       link_args : ['-Wl,--unresolved-symbols=ignore-all',
+                                    '-Wl,-zmuldefs'],
+                       install : false)
+       )
+

Merge request reports