[libvirt] [PATCH v4 5/8] virmock.h: Introduce VIR_MOCK_CALL_STAT
Roman Bogorodskiy
bogorodskiy at gmail.com
Sat May 14 15:15:13 UTC 2016
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 at redhat.com>
> > ---
> > 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160514/8e8e4032/attachment-0001.sig>
More information about the libvir-list
mailing list