test: v4l2_compat: Enable test with ASan

When libcamera is compiled with the address sanitizer enabled, the
v4l2_compat test generates failures in the link order runtime check, as
the host v4l2-ctl and v4l2-compliance tools are not (generally) linked
to ASan. For this reason, the test is disabled, which sadly shrinks test
coverage.

Fix this by loading the ASan runtime using LD_PRELOAD. This needs to be
done from within the v4l2_compat_test.py Python script, as the Python
interpreter itself leaks memory and would cause test failures if run
with ASan.

To LD_PRELOAD the ASan runtime, the path to the binary needs to be
known. gcc gives us a generic way to get the path, but that doesn't work
with clang as the ASan runtime file name depends on the clang version
and target architecture. We thus have to keep the v4l2_compat test
disabled when ASan is enabled and libcamera is compiled with clang.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2022-12-22 01:04:07 +02:00
parent 9f06cd50cc
commit 121b5de329
3 changed files with 43 additions and 12 deletions

View file

@ -7,6 +7,22 @@ endif
test_enabled = true
# When ASan is enabled, find the path to the ASan runtime needed by multiple
# tests. This currently works with gcc only, as clang uses different file names
# depending on the compiler version and target architecture.
asan_enabled = false
asan_runtime_missing = false
if get_option('b_sanitize').contains('address')
asan_enabled = true
if cc.get_id() == 'gcc'
asan_runtime = run_command(cc, '-print-file-name=libasan.so', check : true).stdout().strip()
else
asan_runtime_missing = true
endif
endif
subdir('libtest')
subdir('camera')