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 <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>
This commit is contained in:
Emil Velikov 2024-10-17 16:48:13 +01:00 committed by Lucas De Marchi
parent d567219aa8
commit 0b3c45e5c9
5 changed files with 43 additions and 28 deletions

View 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 = \

View 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

20
scripts/sanitizer-env.sh Executable file
View File

@ -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

View File

@ -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 "$@"

View 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