Skip to content

Commit

Permalink
mtest: set MSAN_OPTIONS to abort by default
Browse files Browse the repository at this point in the history
Followup to 7b7d2e0 which handles ASAN and UBSAN.

It turns out that MSAN needs the same treatment. I've checked other sanitizers
like HWASAN and TSAN - it looks like they may both need it too, but Meson doesn't
currently suppose those anyway (see mesonbuild#12648).

Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
thesamesam committed Feb 13, 2024
1 parent 6f7e745 commit 5ad73d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/markdown/Unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ set to a random value between 1..255. This can help find memory leaks on
configurations using glibc, including with non-GCC compilers. This feature
can be disabled as discussed in [[test]].

### ASAN_OPTIONS and UBSAN_OPTIONS
### ASAN_OPTIONS, UBSAN_OPTIONS, and MSAN_OPTIONS

By default, the environment variables `ASAN_OPTIONS` and `UBSAN_OPTIONS` are
set to enable aborting on detected violations and to give a backtrace. This
feature can be disabled as discussed in [[test]].
By default, the environment variables `ASAN_OPTIONS`, `UBSAN_OPTIONS`, and
`MSAN_OPTIONS` are set to enable aborting on detected violations and to give a
backtrace. This feature can be disabled as discussed in [[test]].

## Coverage

Expand Down
6 changes: 6 additions & 0 deletions docs/markdown/snippets/sanitizers_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Tests now abort on errors by default under more sanitizers

Sanitizers like MemorySanitizer do not abort
by default on detected violations. Meson now exports `MSAN_OPTIONS` (in addition to
`ASAN_OPTIONS` and `UBSAN_OPTIONS` from a previous release) when unset in the
environment to provide sensible abort-by-default behavior.
7 changes: 4 additions & 3 deletions docs/yaml/functions/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ description: |
test(..., env: nomalloc, ...)
```
By default, the environment variables `ASAN_OPTIONS` and `UBSAN_OPTIONS` are
set to enable aborting on detected violations and to give a backtrace. To suppress
this, `ASAN_OPTIONS` and `UBSAN_OPTIONS` can be set in the environment.
By default, the environment variables `ASAN_OPTIONS`, `UBSAN_OPTIONS`,
and `MSAN_OPTIONS` are set to enable aborting on detected violations and to
give a backtrace. To suppress this, `ASAN_OPTIONS` and `UBSAN_OPTIONS` can be
set in the environment.
In addition to running individual executables as test cases, `test()`
can also be used to invoke an external test harness. In this case,
Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,8 @@ def __init__(self, test: TestSerialisation, env: T.Dict[str, str], name: str,
env['ASAN_OPTIONS'] = 'halt_on_error=1:abort_on_error=1:print_summary=1'
if ('UBSAN_OPTIONS' not in env or not env['UBSAN_OPTIONS']):
env['UBSAN_OPTIONS'] = 'halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1'
if ('MSAN_OPTIONS' not in env or not env['MSAN_OPTIONS']):
env['UBSAN_OPTIONS'] = 'halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1'

if self.options.gdb or self.test.timeout is None or self.test.timeout <= 0:
timeout = None
Expand Down

0 comments on commit 5ad73d0

Please sign in to comment.