openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* How to mock journal related methods
@ 2018-06-27 14:26 Nagaraju Goruganti
  2018-06-27 15:24 ` Patrick Venture
  0 siblings, 1 reply; 2+ messages in thread
From: Nagaraju Goruganti @ 2018-06-27 14:26 UTC (permalink / raw)
  To: openbmc

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

Hi Team,

I am writing unit test-cases to phospher-logging server.

As it gets information form the journal log for event and logging 
creation,it needs to make calls to
below given journal related methods:

sd_journal_open(sd_journal**,int)(
https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L86
)
sd_journal_get_data(sd_journal*,const char *,const void **,size_t) (
https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L115
)
sd_journal_close(sd_journal *) (
https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L175
)

I am able make calls to these methods, without any issue, on host 
machine(inside x86 sandbox) where we don't have journal service is 
running.

Is it the correct way(don't we need to mock these methods) ? 

If not, Please someone let me know how to mock these methods?



Thanks and Regards,
Nagaraju G


[-- Attachment #2: Type: text/html, Size: 1936 bytes --]

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

* Re: How to mock journal related methods
  2018-06-27 14:26 How to mock journal related methods Nagaraju Goruganti
@ 2018-06-27 15:24 ` Patrick Venture
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Venture @ 2018-06-27 15:24 UTC (permalink / raw)
  To: Nagaraju Goruganti; +Cc: OpenBMC Maillist

On Wed, Jun 27, 2018 at 7:26 AM, Nagaraju Goruganti <ngorugan@in.ibm.com> wrote:
> Hi Team,
>
> I am writing unit test-cases to phospher-logging server.
>
> As it gets information form the journal log for event and logging
> creation,it needs to make calls to
> below given journal related methods:
>
> sd_journal_open(sd_journal**,int)(https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L86)
> sd_journal_get_data(sd_journal*,const char *,const void **,size_t)
> (https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L115)
> sd_journal_close(sd_journal *)
> (https://github.com/openbmc/phosphor-logging/blob/master/log_manager.cpp#L175)

From how these are used, there are a couple options.
1) You can try to write a different test implementation and link your
tests against that.  This has some complexity because you'll need to
trap those calls to your fake library methods.  I've seen this done
using a singleton object that is called by a thin function:

int sd_journal_open(sd_journal **ret, int flags)  {
  return GetSingleTon->sd_journal_open(ret, flags);
}

And your GetSingleTon will return the singleton instance, and previous
to this call you've set an expectation on the single mock instance
that it'll receive that call.

2) You can implement an interface.  There's already an sdbus and
message in one interface.  It might make sense to use that and add to
it, or implement one just for the journal calls, s.t. you can have
that be passed into the methods you want to test (or more likely,
passed into the initial object and used by the methods).

>
> I am able make calls to these methods, without any issue, on host
> machine(inside x86 sandbox) where we don't have journal service is running.
>
> Is it the correct way(don't we need to mock these methods) ?
>
> If not, Please someone let me know how to mock these methods?
>
>
>
> Thanks and Regards,
> Nagaraju G

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

end of thread, other threads:[~2018-06-27 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27 14:26 How to mock journal related methods Nagaraju Goruganti
2018-06-27 15:24 ` Patrick Venture

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).