shared: add WESTON_EXPORT_FOR_TESTS

This is a new function exporting macro that intends to make writing unit
tests in the Weston test suite easier.

A test needs to access a private function to be able to verify its
behavior. Previously we have used things like putting such functions in
a separate .c file and then building that file into the corresponding
test. That is a bit awkward and can lead to proliferation of arbitrary
.c files for no good reason. It may also require pre-processor magic,
and sometimes copying chunks of code causing a risk of deviating the
code being tested from the code actually used.

This patch proposes another approach: a private export from a DSO.
Except, private exports do not really exist, and this is just a normal
export with a specific C macro, and omitting the function from public
headers.

Once exported, a test program can link the DSO during build, be that a
shared library or even a plugin, use the private header declaring the
function, and simply call the function in the test.

The declaration of WESTON_EXPORT_FOR_TESTS is in shared/helpers.h so
that it is available to all components equally while still not being in
a public header. Other places that were considered:

- include/libweston/libweston.h is a public header, but external users
  should not know about the macro.

- libweston/libweston-private.h is too private and not available to all
  components, particularly color-lcms plugin.

- libweston/backend.h is not appropriate for color-lcms plugin either.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 3 years ago committed by Pekka Paalanen
parent 8e2c67c317
commit 32a790f774
  1. 12
      shared/helpers.h

@ -159,6 +159,18 @@ do { \
tmp___; }) tmp___; })
#endif #endif
/** Private symbol export for tests
*
* Symbols tagged with this are private libweston functions that are exported
* only for the test suite to allow unit testing. Nothing else internal or
* external to libweston is allowed to use these exports.
*
* Therefore, the ABI exported with this tag is completely unversioned, and
* is allowed to break at any time without any indication or version bump.
* This may happen in all git branches, including stable release branches.
*/
#define WESTON_EXPORT_FOR_TESTS __attribute__ ((visibility("default")))
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

Loading…
Cancel
Save