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

Martin Kletzander posted 5 patches 3 years, 11 months ago
[libvirt PATCH 5/5] tests: Allow expansion of mocked stat symbols
Posted by Martin Kletzander 3 years, 11 months ago
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.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 tests/virmock.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/virmock.h b/tests/virmock.h
index 5250e733a156..300ba17174d4 100644
--- a/tests/virmock.h
+++ b/tests/virmock.h
@@ -296,12 +296,14 @@
     do {} while (0)
 #endif
 
+#define VIR_MOCK_STRINGIFY_SYMBOL(name) #name
+
 #define VIR_MOCK_REAL_INIT(name) \
     do { \
         VIR_MOCK_REAL_INIT_MAIN(name, #name); \
         if (real_##name == NULL && \
             !(real_##name = dlsym(RTLD_NEXT, \
-                                  #name))) { \
+                                  VIR_MOCK_STRINGIFY_SYMBOL(name)))) { \
             fprintf(stderr, "Missing symbol '" #name "'\n"); \
             abort(); \
         } \
-- 
2.35.1
Re: [libvirt PATCH 5/5] tests: Allow expansion of mocked stat symbols
Posted by Daniel P. Berrangé 3 years, 11 months ago
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.

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 :|