From: Emil Velikov Date: Thu, 17 Oct 2024 15:48:13 +0000 (+0100) Subject: scripts/test-wrapper.sh: convert to sanitizer-env.sh X-Git-Tag: v34~216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b3c45e5c99f858ed836a7451120782c2e572741;p=thirdparty%2Fkmod.git scripts/test-wrapper.sh: convert to sanitizer-env.sh 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 Link: https://github.com/kmod-project/kmod/pull/172 Signed-off-by: Lucas De Marchi --- diff --git a/Makefile.am b/Makefile.am index c3b17497..93d461ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = \ diff --git a/meson.build b/meson.build index 39ac3f07..9a14195d 100644 --- a/meson.build +++ b/meson.build @@ -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 index 00000000..9c759a82 --- /dev/null +++ b/scripts/sanitizer-env.sh @@ -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 index 073446f1..00000000 --- a/scripts/test-wrapper.sh +++ /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 "$@" diff --git a/testsuite/meson.build b/testsuite/meson.build index c786196c..a9ea5133 100644 --- a/testsuite/meson.build +++ b/testsuite/meson.build @@ -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