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

Martin Kletzander mkletzan at redhat.com
Mon Mar 7 10:43:05 UTC 2022


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.

>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 :|
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20220307/f4c9c540/attachment.sig>


More information about the libvir-list mailing list