[libvirt PATCH 5/5] tests: Allow expansion of mocked stat symbols

Daniel P. Berrangé berrange at redhat.com
Mon Mar 7 10:44:10 UTC 2022


On Mon, Mar 07, 2022 at 11:43:05AM +0100, Martin Kletzander wrote:
> On Mon, Mar 07, 2022 at 10:01:40AM +0000, Daniel P. Berrangé wrote:
> > On Mon, Mar 07, 2022 at 10:04:06AM +0100, Martin Kletzander wrote:
> > > When libc uses a define to rewrite stat64 to stat our mocks do not work if they
> > > are chained because the symbol that we are looking up is being stringified and
> > > therefore preventing the stat64->stat expansion per C-preprocessor rules.  One
> > > stringification macro is just enough to make it work.
> > 
> > This doesn't sound right to me.
> > 
> > If we're implementing a mock for 'stat64', we should not be looking
> > up 'stat'.  We should  be implmenting a mock for 'stat' instead.
> > 
> > It sounds more like we got MOCK_STAT and MOCK_STAT64 incorrectly
> > defined surely.
> > 
> 
> I spent three days trying to figure this out.  But with this fix we are
> actually doing what you are suggesting.  All the (l)stat64 are being
> replaced by (l)stat, so even:
> 
> int lstat64(const char *path, struct stat64 *statbuf)
> 
> is actually rewritten to
> 
> int lstat(const char *path, struct stat *statbuf)
> 
> because the define applies to the struct name as well.  The only
> difference is that internally it will use the real_lstat64 function
> pointer, but the function declaration is correct.  And if you enable
> debugging it will say that lstat64 is being redirected, but that's a
> pretty minor issue, if it is one at all.
> 
> What we could do is rewrite the macros so that all of the above is
> properly expanded/substituted, but I do not think that is the way we
> want to do things as it looked a bit messy (I probably still have that
> commit somewhere.

Ok, thanks for the explanation.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


More information about the libvir-list mailing list