UnitTest using the /tmp file system

Lei Yu yulei.sh at bytedance.com
Wed Mar 24 14:12:54 AEDT 2021


On Tue, Mar 23, 2021 at 11:08 PM Joseph Reynolds <jrey at linux.ibm.com> wrote:
>
> On 3/23/21 12:44 AM, Sunitha Harish wrote:
> > Any views please ?
> >
> > On 21-03-2021 09:30, Sunitha Harish wrote:
> >> Hi,
> >>
> >> 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.
>
> Are the files written to the BMC's file system or to the test platform's
> file system?  I don't understand why this is important either way.
> Can't we just erase the file when the unit test is complete?
>

I agree it is better to mock as many interfaces as possible to avoid
accessing host's file system.

But in certain cases, I do want to test the functions that involves filesystem.
In such case, I usually use mkdtemp() to create a temp dir in test
case's ctor or setup(), and remove it on test case's dtor or
tearDown().

-- 
BRs,
Lei YU


More information about the openbmc mailing list