openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Williams <patrick@stwcx.xyz>
To: Sunitha Harish <sunithaharish04@gmail.com>
Cc: openbmc@lists.ozlabs.org, deepak.kodihalli.83@gmail.com,
	edtanous@google.com, bradleyb@fuzziesquirrel.com,
	gmills@us.ibm.com, geissonator@yahoo.com,
	ratagupt@linux.vnet.ibm.com
Subject: Re: UnitTest using the /tmp file system
Date: Sat, 27 Mar 2021 09:03:55 -0500	[thread overview]
Message-ID: <YF87S2Y9texS/ac0@heinlein> (raw)
In-Reply-To: <158971a4-119a-eeb4-bf83-72ed17e29d9f@gmail.com>

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

On Sun, Mar 21, 2021 at 09:30:30AM +0530, Sunitha Harish wrote:

> This is regarding the unit tests in various repos under openbmc like: 
> phosphor-bmc-code-management, phosphor-logging, phosphor-networkd, pldm 
> etc . I have seen the testcases using the /tmp filesystem to create the 
> directories/files when the UT is run.
> 
> I followed the similar way of writing the UT in one of my commits 
> https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/37352 .  As per 
> the review comments in this commit, using the /tmp file system for UT is 
> anti-pattern, and this needs to be changed by mocking the same. I agree 
> that this is a valid thing to do.

With respect to this being an "anti-pattern", I'm not sure where this
statement is coming from.  Generally we have very few statements on how
unit-testing should be done across the project and this is certainly not
an "anti-pattern" documented in our usual place[1].

In terms of "what is appropriate to do in a unit test", I see two
possible perspectives:
    1. Anything is permissible and appropriate to do in a unit test (and
       thus nothing is *required* to be mocked).
    2. No system calls may be called from the unit test (and thus all
       system calls are required to be mocked).

Anything other than these two possibilities seems, to me, relatively
arbitrary without specific evidence that the un-mocked code is
problematic.  Nobody actually follows #2 because if you did you'd need
to mock even the 'sbrk' call which is used to create your heap.  So, the
question is why is one set of system calls reasonable to use in a
unit-test and another not?

We have many unit tests across the project that interact with either
the file system or dbus.  Whoever wrote them probably decided that was
the most pragmatic way to test their code and gain the coverage they
were looking for and whoever maintained the repository accepted that as
a solution.  In this case, I would encourage you to dig deeper into the
maintainer's opinion as to why this is an inappropriate approach for
this particular repository or unit-test.

There is one specific problem area we have encountered with fs-using UTs
and it is aggravated by the fact that we run tests in parallel and
sometimes Jenkins jobs land on the same machine: any files you create in
the file system, or dbus services you create, should use some sort of
randomness to avoid collisions between separate UTs.  I see in your
original commit, before the UTs were removed, that you used 'mkdtemp'
with an XXXXXX pattern which should resolve this potential issue.

1. https://github.com/openbmc/docs/blob/0f6c884822ca2d101e2a0bf3256ecf4f6f2431a3/anti-patterns.md

-- 
Patrick Williams

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-03-27 14:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21  4:00 UnitTest using the /tmp file system Sunitha Harish
2021-03-23  5:44 ` Sunitha Harish
2021-03-23 15:03   ` Joseph Reynolds
2021-03-24  3:12     ` Lei Yu
2021-03-24  5:07       ` Sunitha Harish
2021-03-27 14:03 ` Patrick Williams [this message]
2021-03-29  4:29   ` Sunitha Harish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YF87S2Y9texS/ac0@heinlein \
    --to=patrick@stwcx.xyz \
    --cc=bradleyb@fuzziesquirrel.com \
    --cc=deepak.kodihalli.83@gmail.com \
    --cc=edtanous@google.com \
    --cc=geissonator@yahoo.com \
    --cc=gmills@us.ibm.com \
    --cc=openbmc@lists.ozlabs.org \
    --cc=ratagupt@linux.vnet.ibm.com \
    --cc=sunithaharish04@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).