HomeClusterLabs Projects

Test: libcrmcommon: Add some very simple unit tests with mocked functions.

Description

Test: libcrmcommon: Add some very simple unit tests with mocked functions.

The functions I'm testing here really don't do very much, which makes
them good candidates to test out how the mocked up function stuff works.

On the build side, each new test case needs to:

  • Link against libcrmcommon_test.la instead of libcrmcommon.la.
  • Pass the -Wl,--wrap= flag for each wrapped function that it uses.

The new test cases are largely boilerplate, but that's just how unit
tests go. Each unit test:

  • Defines a __wrap_X function that takes the place of some library function. The body of these functions is very simple, basically just returning a previously defined value with mock_type. Remember that we are not testing the library function. We are testing how a Pacemaker function responds to the library function.
  • Defines one more more test functions. These are just like regular test functions, except we also need to tell __wrap_X what to return. A call to will_return enqueues a value that some future call of mock_type will return. These need to be paired, basically. And then we just call our Pacemaker function and check the result.

Details

Provenance
clumensAuthored on Sep 1 2021, 2:53 PM
Parents
rPb6966c52c8c2: Test: libcrmcommon: Build a special libcrmcommon_test.a library.
Branches
Unknown
Tags
Unknown

Event Timeline