[libvirt] [PATCH v3 2/4] tests: Introduce global mock library

Michal Privoznik mprivozn at redhat.com
Thu May 12 15:44:46 UTC 2016


On 12.05.2016 17:30, Michal Privoznik wrote:
> On 12.05.2016 16:34, Peter Krempa wrote:
>> On Thu, May 12, 2016 at 14:36:22 +0200, Michal Privoznik wrote:
>>> The intent is that this library is going to be called every time
>>> to check if we are not touching anything outside srcdir or
>>> builddir.
>>>
>>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>>> ---
>>>  cfg.mk                |   2 +-
>>>  tests/Makefile.am     |  13 +++-
>>>  tests/testutils.c     |   9 +++
>>>  tests/testutils.h     |  10 +--
>>>  tests/vircgroupmock.c |  15 ++---
>>>  tests/virpcimock.c    |  14 ++--
>>>  tests/virtestmock.c   | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>>  7 files changed, 210 insertions(+), 28 deletions(-)
>>>  create mode 100644 tests/virtestmock.c
>>>
>>
>> [...]
>>
>>> diff --git a/tests/testutils.c b/tests/testutils.c
>>> index 79d0763..595b64d 100644
>>> --- a/tests/testutils.c
>>> +++ b/tests/testutils.c
>>
>> [...]
>>
>>> @@ -842,6 +845,12 @@ int virtTestMain(int argc,
>>>      char *oomstr;
>>>  #endif
>>>  
>>> +#ifdef __linux__
>>> +    VIRT_TEST_PRELOAD(TEST_MOCK);
>>
>> So I was thinking about it a bit. I think we should pre-load this only
>> conditionally on a ENV var which will enable it.
> 
> Yeah, I was thinking the same when implementing this. Problem with that
> approach would be that nobody would do that. But I guess for now it's a
> fair trade and once we get the whitelist rules complete we can make
> 'make check' to actually set the variable and possibly die on an error
> if the perl script founds one. Got any good idea about the var name?
> What if I reuse VIR_TEST_FILE_ACCESS (introduced in 3/4) just for this
> purpose, to enable this whole feature; and then introduce
> VIR_TEST_FILE_ACCESS_OUTPUT to redirect output into a different file
> than the default one.
> If so, do you want me to send another version of these patches?

I just realized, it's not going to be that easy. Problem is, my mock
lib, implements both lstat and __lxstat, and stat and __xstat. Now, due
to changes made to other mocks (i.e. virpcimock and vircgroupmock),
without my library linked tests using the other mocks will just crash as
soon as they try to stat(). So what I can do, is to suppress any output
(and checking of accessed paths) until VIR_TEST_FILE_ACCESS var is set
(or whatever name we decide on).

Michal




More information about the libvir-list mailing list