]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
scripts/test-wrapper.sh: convert to sanitizer-env.sh
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 17 Oct 2024 15:48:13 +0000 (16:48 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 18 Oct 2024 18:22:11 +0000 (13:22 -0500)
Convert the existing wrapper script, into one that we source to set the
environment aka LD_PRELOAD.

Thus a developer can, use/test/debug the tests without using meson.
Namely:
 - source scripts/sanitizer-env.sh
 - build/testsuite/test-depmod

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Makefile.am
meson.build
scripts/sanitizer-env.sh [new file with mode: 0755]
scripts/test-wrapper.sh [deleted file]
testsuite/meson.build

index c3b17497a38eca7ca26b2da015504c09125da05a..93d461ce071738ffe0cdc998b16a6302ba923558 100644 (file)
@@ -23,8 +23,8 @@ EXTRA_DIST += \
        meson_options.txt \
        testsuite/meson.build \
        scripts/build-scdoc.sh \
+       scripts/sanitizer-env.sh \
        scripts/test-gtkdoc.sh \
-       scripts/test-wrapper.sh \
        scripts/kmod-symlink.sh
 
 AM_CPPFLAGS = \
index 39ac3f07047ca2157e2dda0aed812a6709b131ef..9a14195dfcc35930a0b342b09a04a361296ee978 100644 (file)
@@ -453,10 +453,11 @@ endforeach
 # ------------------------------------------------------------------------------
 
 if get_option('build-tests')
+  bash = find_program('bash')
+  sanitizer_env = find_program('scripts/sanitizer-env.sh')
   setup_modules = find_program('scripts/setup-modules.sh')
   setup_rootfs = find_program('scripts/setup-rootfs.sh')
   top_include = include_directories('.')
-  test_wrapper = find_program('scripts/test-wrapper.sh')
   subdir('testsuite')
 endif
 
diff --git a/scripts/sanitizer-env.sh b/scripts/sanitizer-env.sh
new file mode 100755 (executable)
index 0000000..9c759a8
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# set -euo pipefail # don't set these, since this script is sourced
+
+OUR_PRELOAD=$(gcc -print-file-name=libasan.so)
+
+if test -n "$OUR_PRELOAD"; then
+    # In some cases, like in Fedora, the file is a script which cannot be
+    # preloaded. Attempt to extract the details from within.
+    if grep -q INPUT "$OUR_PRELOAD"; then
+        input=$(sed -r -n "s/INPUT \( (.*) \)/\1/p" "$OUR_PRELOAD")
+        test -f "$input" && OUR_PRELOAD="$input"
+    fi
+
+    LD_PRELOAD=${LD_PRELOAD+${LD_PRELOAD}:}$OUR_PRELOAD
+    export LD_PRELOAD
+    echo "LD_PRELOAD has been set to \"$LD_PRELOAD\"."
+    echo "The sanitizer might report issues with ANY process you execute."
+fi
+unset OUR_PRELOAD
diff --git a/scripts/test-wrapper.sh b/scripts/test-wrapper.sh
deleted file mode 100755 (executable)
index 073446f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-if [[ ${ASAN_OPTIONS-} || ${UBSAN_OPTIONS-} || ${MSAN_OPTIONS-} ]]; then
-    LD_PRELOAD=$(gcc -print-file-name=libasan.so)
-    # In some cases, like in Fedora, the file is a script which cannot be
-    # preloaded. Attempt to extract the details from within.
-    if grep -q INPUT "$LD_PRELOAD"; then
-        input=$(sed -r -n "s/INPUT \( (.*) \)/\1/p" "$LD_PRELOAD")
-        test -f "$input" && LD_PRELOAD="$input"
-    fi
-    export LD_PRELOAD
-fi
-
-exec "$@"
index c786196cf15fd3cf5c7d55aaecdb7115778a0e04..a9ea513395586f6d4a2274206fbe295b0a1f4f77 100644 (file)
@@ -96,18 +96,28 @@ _testsuite = [
   'test-weakdep',
 ]
 
+if get_option('b_sanitize') != 'none'
+  source_env = 'source @0@;'.format(sanitizer_env.full_path())
+else
+  source_env = ''
+endif
+
 foreach input : _testsuite
+  exec = executable(
+    input,
+    files('@0@.c'.format(input)),
+    include_directories : top_include,
+    c_args : testsuite_c_args,
+    link_with : [libshared, libkmod_internal, libtestsuite],
+    build_by_default : false,
+  )
   test(
     input,
-    test_wrapper,
-    args : executable(
-      input,
-      files('@0@.c'.format(input)),
-      include_directories : top_include,
-      c_args : testsuite_c_args,
-      link_with : [libshared, libkmod_internal, libtestsuite],
-      build_by_default : false,
-    ),
-    depends : [internal_kmod_symlinks, create_rootfs, test_override_mods],
+    bash,
+    args : [
+      '-c',
+      '@0@@1@'.format(source_env, exec.full_path()),
+    ],
+    depends : [exec, internal_kmod_symlinks, create_rootfs, test_override_mods],
   )
 endforeach