]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Revert "testsuite/path: match the full rootpath"
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 5 Nov 2024 00:25:39 +0000 (00:25 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 8 Nov 2024 17:51:52 +0000 (11:51 -0600)
This reverts commit ae0c0c4c89f60fd379133f46b10c37686eef0c6c.

The commit reasoning was correct, but did not consider the case where
other third-party files are created. Namely: when generating the code
coverage files.

Thus the gcna files were created in $test_rootdir/$abs_top_builddir
which meant they won't get picked when the coverage info/xml/html files
were created and the statistics reported were quite wrong.

Revert the commit and add an inline comment, so we don't feel tempted to
change it in the future.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/229
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Makefile.am
shared/util.h
testsuite/meson.build
testsuite/path.c

index 1a48756b77d99b176a2fc70573e939034502234a..554409fcd5f8f149faebc84d7ac727cd8d632c09 100644 (file)
@@ -255,6 +255,8 @@ EXTRA_DIST += \
 check_LTLIBRARIES = $(TESTSUITE_OVERRIDE_LIBS)
 
 testsuite_uname_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS)
+testsuite_path_la_CPPFLAGS = $(AM_CPPFLAGS) \
+       -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"
 testsuite_path_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS)
 
 testsuite_delete_module_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS)
index 579217f30f6ed5103a161ecf0c7c0356f59747b7..a9ce00a30cb0e9661320e8c7ca44614c1e98afb8 100644 (file)
@@ -16,7 +16,6 @@
 /* ************************************************************************ */
 #define streq(a, b) (strcmp((a), (b)) == 0)
 #define strstartswith(a, b) (strncmp(a, b, strlen(b)) == 0)
-#define strnstartswith(a, b, n) (strncmp(a, b, n) == 0)
 char *strchr_replace(char *s, char c, char r);
 _nonnull_all_ void *memdup(const void *p, size_t n);
 
index ca22026fa7da2f904bb256a25c0234c10303856a..e82f6082130d011229cd97d7e9a2bbe86edb3895 100644 (file)
@@ -51,6 +51,7 @@ foreach mod : _test_override_mods
     mod,
     files('@0@.c'.format(mod)),
     include_directories : top_include,
+    c_args : '-DABS_TOP_BUILDDIR="@0@"'.format(meson.project_build_root()),
     dependencies : libdl,
     link_with : [libshared, libkmod_internal],
     gnu_symbol_visibility : 'hidden',
index aba9cf8840e4b3ff5da87323778e4aa2b5da4673..b896885a00de143c91ccec7d53eb3e760cde4fe0 100644 (file)
@@ -32,8 +32,16 @@ static size_t rootpathlen;
 
 static inline bool need_trap(const char *path)
 {
-       return path != NULL && path[0] == '/' &&
-              !strnstartswith(path, rootpath, rootpathlen);
+       /*
+        * Always consider the ABS_TOP_BUILDDIR as the base root of anything we do.
+        *
+        * Changing this to rootpath is tempting but incorrect, since it won't consider
+        * any third-party files managed through this LD_PRELOAD library, eg coverage.
+        *
+        * In other words: if using rootpath, the coverage gcna files will end up created
+        * in the wrong location eg. $rootpath/$ABS_TOP_BUILDDIR.
+        */
+       return path != NULL && path[0] == '/' && !strstartswith(path, ABS_TOP_BUILDDIR);
 }
 
 static const char *trap_path(const char *path, char buf[PATH_MAX * 2])