phosphor-logging in testing

Brad Bishop bradleyb at fuzziesquirrel.com
Fri Aug 10 04:10:59 AEST 2018


> On Aug 9, 2018, at 12:46 PM, Patrick Venture <venture at google.com> wrote:
> 
> So, phosphor-logging/log.hpp requires one to link in systemd, so 
> technically I can already argue it isn't a header-only code-base.

This isn’t really what I think of when I think of header only.  But maybe
the distinction doesn’t matter anyway - this isn’t any different than sdbusplus
needing libsystemd.  Both phosphor-logging/log.hpp and the sdbusplus bus and
message APIs were intended to be C++ language bindings only.  So no abstractions
beyond what libsystemd already provides.  For the most part.  Now elog.hpp is
another story...

> That said, I'm looking at how to enable testing such that we can
> easily validate error code paths.

I suggest you do the same as what you did for sdbusplus.  Don’t mock the
language binding apis provided by log.hpp - mock the libsystemd (journal)
apis and set your expectations on those.

> 
> One approach is to move the code in the header such that it calls some
> code in the library itself that we can swap out with a "body double."
> Another approach is to have some global variable in that library that
> one can flip when they want such that the tests throw an exception or
> something useful to catch in a test.  Or just do nothing.
> 
> Is there anyone already tackling this problem?
> 
> Patrick


More information about the openbmc mailing list