Re: [PATCH v4 5/8] virmock.h: Introduce VIR_MOCK_CALL_STAT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  Roman Bogorodskiy wrote:

>   Michal Privoznik wrote:
> 
> > There is some magic going on when it comes to stat() or lstat().
> > Basically, stat() can either be a regular function, an inline
> > function that calls __xstat(_STAT_VER, ...) or a macro that does
> > the same as the inline func. Don't ask why is that, just read the
> > documentation in sys/stat.h and make sure you have a bucket next
> > to you. Anyway, currently there will not be both stat and __xstat
> > symbols at the same time, as one of them gets overwritten to the
> > other one during compilation. But this is not true anymore once
> > we start chaining our mocking libraries. Therefore we need a
> > wrapper that calls desired function from glibc.
> > 
> > Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> > ---
> >  tests/vircgroupmock.c | 14 +++++++-------
> >  tests/virmock.h       | 23 +++++++++++++++++++++++
> >  tests/virpcimock.c    | 19 +++++++++----------
> >  3 files changed, 39 insertions(+), 17 deletions(-)
> 
> ...
> 
> > diff --git a/tests/virmock.h b/tests/virmock.h
> > index 62a7c8f..27c03ba 100644
> > --- a/tests/virmock.h
> > +++ b/tests/virmock.h
> > @@ -27,6 +27,7 @@
> >  # endif
> >  # include <stdlib.h>
> >  # include <stdio.h>
> > +# include <sys/stat.h>
> >  
> >  # include "internal.h"
> >  
> > @@ -254,6 +255,28 @@
> >      static void (*real_##name)(void);                                   \
> >      void name(void)
> >  
> > +static inline int
> > +callStat(int (*realStat)(const char *, struct stat *),
> > +         int (*realXstat)(int, const char *, struct stat *),
> > +         int __ver, const char *__filename, struct stat *__stat_buf)
> > +{
> > +    if (!realXstat) {
> > +        if (__ver == _STAT_VER) {
> > +            return realStat(__filename, __stat_buf);
> > +        } else {
> > +            fprintf(stderr, "Not handled __xstat(ver=%d)", __ver);
> > +            abort();
> > +        }
> > +    }
> > +
> > +    return realXstat(__ver, __filename, __stat_buf);
> > +}
> 
> Hm, this fails on FreeBSD with:
> 
>   CC       nssmock_la-nssmock.lo
> In file included from nssmock.c:24:
> ./virmock.h:264:22: error: use of undeclared identifier '_STAT_VER'
>         if (__ver == _STAT_VER) {
>                      ^
> 1 error generated.
> Makefile:4932: recipe for target 'nssmock_la-nssmock.lo' failed
> gmake: *** [nssmock_la-nssmock.lo] Error 1

I was to "fix" that by trivially adding

+# ifndef _STAT_VER
+#  define _STAT_VER     0
+# endif
+

I'm not quite sure that's a right way to go though, because I haven't had a
chance to wrap my brain around this new mock thing yet.

Roman Bogorodskiy

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]