From: Emil Velikov Date: Tue, 5 Nov 2024 00:25:39 +0000 (+0000) Subject: Revert "testsuite/path: match the full rootpath" X-Git-Tag: v34~123 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ebbca1c24054b6a8b3cf0143a2fbf4c88078e6e0;p=thirdparty%2Fkmod.git Revert "testsuite/path: match the full rootpath" 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 Link: https://github.com/kmod-project/kmod/pull/229 Signed-off-by: Lucas De Marchi --- diff --git a/Makefile.am b/Makefile.am index 1a48756b..554409fc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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) diff --git a/shared/util.h b/shared/util.h index 579217f3..a9ce00a3 100644 --- a/shared/util.h +++ b/shared/util.h @@ -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); diff --git a/testsuite/meson.build b/testsuite/meson.build index ca22026f..e82f6082 100644 --- a/testsuite/meson.build +++ b/testsuite/meson.build @@ -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', diff --git a/testsuite/path.c b/testsuite/path.c index aba9cf88..b896885a 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -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])