All of lore.kernel.org
 help / color / mirror / Atom feed
* YASL Request
@ 2018-04-09 22:27 Patrick Venture
  2018-04-10  2:45 ` Lei YU
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Patrick Venture @ 2018-04-09 22:27 UTC (permalink / raw)
  To: OpenBMC Maillist, Brad Bishop, Emily Shaffer

Everyone,

I'm working on unit-testing in openbmc, and have cracked most of
sdbusplus into mockable pieces and verified I can in fact test against
those mocks with a downstream daemon.  I'll be grabbing an upstream
daemon (or providing a piece of one) to demonstrate how to leverage
the mocks to test OpenBMC.  If one designs with testing in mind, the
designs come out very differently if not, and so getting unit-tests
throughout OpenBMC will be a lot of breaking things apart into
testable pieces.  Anyways, where I'm going with this email is that
everything we do within a daemon needs to be something that can be
mocked -- basically.

***
What do I mean specifically?  Consider, file access.  If a daemon
routes all file accesses throug a common object implementation
provided by a shared library, that shared library can easily also
provide a mock interface for those accesses, such that one can easily
verify behaviors based on file contents without implementing local
files or trying to inject errors.  With a mock's file system
interface, you can simply say that a file was unable to be read, or
written, or opened, etc.  Another example is mocking ctime.  If you
want to test whether something happens after some sleep or period, if
your code can receive a mock version of that library, one can
deliberately control the results of 'time' or 'difftime', etc.  I have
to build these interfaces for some of our downstream daemons and
likely for other parts of OpenBMC, and to avoid code duplication it'll
help to have them in some library.

YASL (yet-another-shared-library) Request.

Previous conversations along these lines lead to the idea that we need
multiple new libraries for various things.  So, this is yet another
use case.  The library itself should be written in such a way that it
can be tested via unit-tests, but depending on how thin of a shim it
is, that isn't always practical.  See:

class FileInterface {
  public:
     virtual int open(const char *filename, int flags) = 0;
};

class FileImplementation : public FileInterface {
  public:
    int open(const char *filename, int flags) override {
        return ::open(filename, flags);
    }
};

class FileMock : public FileInterface {
   public:
     MOCK_METHOD2(open, int(const char *, int));
};

.... then one just uses the FileInterface for their normally direct
posix-style file access.  This can easily wrap iostream, or fstream,
or anything.  And then if we provide some libraries for use by
daemons, they can transition over to them over time, and then they get
mocks for free :D  For a daemon downstream, I've written a ctime
wrapper, I'll submit it for consideration later tonight along with a
few other things, and then I'll reply to this email with links.

***Not meant as a unit-test primer, just trying to provide some real examples.

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-04-16 19:11 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 22:27 YASL Request Patrick Venture
2018-04-10  2:45 ` Lei YU
2018-04-10  3:19   ` Patrick Venture
2018-04-10 17:59     ` Patrick Venture
2018-04-11  3:52   ` Brad Bishop
2018-04-11 15:59     ` Patrick Venture
2018-04-11  2:34 ` Brad Bishop
2018-04-11 15:56   ` Patrick Venture
2018-04-12 14:25   ` Alexander Amelkin
2018-04-12 15:20     ` Patrick Venture
2018-04-13 10:16       ` Alexander Amelkin
2018-04-13 15:42         ` Patrick Venture
2018-04-13  3:56 ` Andrew Jeffery
2018-04-13 15:21   ` Brad Bishop
2018-04-13 16:03     ` Patrick Venture
2018-04-14  0:14       ` Patrick Venture
2018-04-16  2:50     ` Lei YU
2018-04-16 19:10       ` Patrick Venture
2018-04-14  4:12   ` Patrick Venture

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.