Skip to content

Commit 7b7d2e0

Browse files
thesamesameli-schwartz
authored andcommitted
mtest: set ASAN_OPTIONS and UBSAN_OPTIONS to abort by default
Do as we do for MALLOC_PERTURB and set a sensible value for both ASAN_OPTIONS and UBSAN_OPTIONS to abort on failure and give more helpful output at the same time. We do not set these options if the user has exported a value themselves to allow override. In the last week alone, I've observed two cases where people were expecting sanitizers to abort on failure and were surprised when it didn't: 1) git/git@252d693 2) https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/c47df433f7bc9936fc59b323ca5e53ea4a04f40e Correct this - which is in-line with meson's DWIM/DTRT philosophy. Signed-off-by: Sam James <[email protected]>
1 parent e2a87af commit 7b7d2e0

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎docs/markdown/Unit-tests.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ set to a random value between 1..255. This can help find memory leaks on
3838
configurations using glibc, including with non-GCC compilers. This feature
3939
can be disabled as discussed in [[test]].
4040

41+
### ASAN_OPTIONS and UBSAN_OPTIONS
42+
43+
By default, the environment variables `ASAN_OPTIONS` and `UBSAN_OPTIONS` are
44+
set to enable aborting on detected violations and to give a backtrace. This
45+
feature can be disabled as discussed in [[test]].
46+
4147
## Coverage
4248

4349
If you enable coverage measurements by giving Meson the command line
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Tests now abort on errors by default under sanitizers
2+
3+
Sanitizers like AddressSanitizer and UndefinedBehaviorSanitizer do not abort
4+
by default on detected violations. Meson now exports `ASAN_OPTIONS` and `UBSAN_OPTIONS`
5+
when unset in the environment to provide sensible abort-by-default behavior.

‎docs/yaml/functions/test.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ description: |
3333
test(..., env: nomalloc, ...)
3434
```
3535
36+
By default, the environment variables `ASAN_OPTIONS` and `UBSAN_OPTIONS` are
37+
set to enable aborting on detected violations and to give a backtrace. To suppress
38+
this, `ASAN_OPTIONS` and `UBSAN_OPTIONS` can be set in the environment.
39+
3640
In addition to running individual executables as test cases, `test()`
3741
can also be used to invoke an external test harness. In this case,
3842
it is best to use `verbose: true` *(since 0.62.0)* and, if supported

‎mesonbuild/mtest.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,15 @@ def __init__(self, test: TestSerialisation, env: T.Dict[str, str], name: str,
14181418
if ('MALLOC_PERTURB_' not in env or not env['MALLOC_PERTURB_']) and not options.benchmark:
14191419
env['MALLOC_PERTURB_'] = str(random.randint(1, 255))
14201420

1421+
# Sanitizers do not default to aborting on error. This is counter to
1422+
# expectations when using -Db_sanitize and has led to confusion in the wild
1423+
# in CI. Set our own values of {ASAN,UBSAN}_OPTOINS to rectify this, but
1424+
# only if the user has not defined them.
1425+
if ('ASAN_OPTIONS' not in env or not env['ASAN_OPTIONS']):
1426+
env['ASAN_OPTIONS'] = 'halt_on_error=1:abort_on_error=1:print_summary=1'
1427+
if ('UBSAN_OPTIONS' not in env or not env['UBSAN_OPTIONS']):
1428+
env['UBSAN_OPTIONS'] = 'halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1'
1429+
14211430
if self.options.gdb or self.test.timeout is None or self.test.timeout <= 0:
14221431
timeout = None
14231432
elif self.options.timeout_multiplier is None:

0 commit comments

Comments
 (0)