]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Lookup extended stat/lstat in mocks
authorRoman Bolshakov <r.bolshakov@yadro.com>
Wed, 21 Aug 2019 16:13:20 +0000 (19:13 +0300)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 23 Aug 2019 10:26:26 +0000 (11:26 +0100)
macOS syscall interface (/usr/lib/system/libsystem_kernel.dylib) has
three kinds of stat but only one of them can be used to fill
"struct stat": stat$INODE64.

virmockstathelpers looks up regular stat instead of stat$INODE64.  That
causes a failure in qemufirmwaretest because "struct stat" is laid out
differently from the values returned by stat.

Introduce VIR_MOCK_REAL_INIT_ALIASED that can be used to lookup
stat$INODE64 and lstat$INODE64 and use it to setup real functions on
macOS.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
tests/virmock.h
tests/virmockstathelpers.c

index 74bb0d5b1531e6006a3f4e89a9fd2e1e85ecae1f..7520bb5d6e6476385c8c379e80783307cdea6e2d 100644 (file)
             abort(); \
         } \
     } while (0)
+
+#define VIR_MOCK_REAL_INIT_ALIASED(name, alias) \
+    do { \
+        if (real_##name == NULL && \
+            !(real_##name = dlsym(RTLD_NEXT, \
+                                  alias))) { \
+            fprintf(stderr, "Missing symbol '" alias "'\n"); \
+            abort(); \
+        } \
+    } while (0)
index 0bbea4b4373a7602c37ecc1d98970cc1aed4a1d4..485063be8498f2c8f0858ae9c2acf3c304938153 100644 (file)
@@ -138,7 +138,11 @@ static void virMockStatInit(void)
     debug = getenv("VIR_MOCK_STAT_DEBUG");
 
 #ifdef MOCK_STAT
+# ifdef __APPLE__
+    VIR_MOCK_REAL_INIT_ALIASED(stat, "stat$INODE64");
+# else
     VIR_MOCK_REAL_INIT(stat);
+# endif
     fdebug("real stat %p\n", real_stat);
 #endif
 #ifdef MOCK_STAT64
@@ -154,7 +158,11 @@ static void virMockStatInit(void)
     fdebug("real __xstat64 %p\n", real___xstat64);
 #endif
 #ifdef MOCK_LSTAT
+# ifdef __APPLE__
+    VIR_MOCK_REAL_INIT_ALIASED(stat, "lstat$INODE64");
+# else
     VIR_MOCK_REAL_INIT(lstat);
+# endif
     fdebug("real lstat %p\n", real_lstat);
 #endif
 #ifdef MOCK_LSTAT64