summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-03-07 11:41:18 +0100
committerEli Schwartz <eschwartz93@gmail.com>2025-03-09 18:06:14 -0400
commit43ea11ea49948635b1d672fef1bd397233b65b19 (patch)
treee1fa9be70e178fb12d6d01ca8c07d3d4fa437ab9 /unittests
parente629d191b99119c360605b056b954fff0905c83f (diff)
downloadmeson-43ea11ea49948635b1d672fef1bd397233b65b19.tar.gz
compilers: convert `b_sanitize` to a free-form array option
In the preceding commit we have started to perform compiler checks for the value of `b_sanitize`, which allows us to detect sanitizers that aren't supported by the compiler toolchain. But we haven't yet loosened the option itself to accept arbitrary values, so until now it's still only possible to pass sanitizer combinations known by Meson, which is quite restrictive. Lift that restriction by adapting the `b_sanitize` option to become a free-form array. Like this, users can pass whatever combination of comma-separated sanitizers to Meson, which will then figure out whether that combination is supported via the compiler checks. This lifts a couple of restrictions and makes the supporting infrastructure way more future proof. A couple of notes regarding backwards compatibility: - All previous values of `b_sanitize` will remain valid as the syntax for free-form array values and valid combo choices is the same. We also treat 'none' specially so that we know to convert it into an empty array. - Even though the option has been converted into a free-form array, callers of `get_option('b_sanitize')` continue to get a string as value. We may eventually want to introduce a kwarg to alter this behaviour, but for now it is expected to be good enough for most use cases. Fixes #8283 Fixes #7761 Fixes #5154 Fixes #1582 Co-authored-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Patrick Steinhardt <ps@pks.im>
Diffstat (limited to 'unittests')
-rw-r--r--unittests/allplatformstests.py5
-rw-r--r--unittests/linuxliketests.py22
2 files changed, 25 insertions, 2 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 7f4e1e788..84d5245d9 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2016-2021 The Meson development team
+# Copyright © 2023-2024 Intel Corporation
import subprocess
import re
@@ -2770,7 +2771,7 @@ class AllPlatformTests(BasePlatformTests):
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.optstore.get_value('bindir'), 'bar')
self.assertEqual(obj.optstore.get_value('buildtype'), 'release')
- self.assertEqual(obj.optstore.get_value('b_sanitize'), 'thread')
+ self.assertEqual(obj.optstore.get_value('b_sanitize'), ['thread'])
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dbar'])
self.setconf(['--bindir=bar', '--bindir=foo',
'-Dbuildtype=release', '-Dbuildtype=plain',
@@ -2779,7 +2780,7 @@ class AllPlatformTests(BasePlatformTests):
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.optstore.get_value('bindir'), 'foo')
self.assertEqual(obj.optstore.get_value('buildtype'), 'plain')
- self.assertEqual(obj.optstore.get_value('b_sanitize'), 'address')
+ self.assertEqual(obj.optstore.get_value('b_sanitize'), ['address'])
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dfoo'])
self.wipe()
except KeyError:
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py
index 08eb4b93a..01862b61e 100644
--- a/unittests/linuxliketests.py
+++ b/unittests/linuxliketests.py
@@ -1930,3 +1930,25 @@ class LinuxlikeTests(BasePlatformTests):
self.check_has_flag(compdb, mainsrc, '-O3')
self.check_has_flag(compdb, sub1src, '-O2')
self.check_has_flag(compdb, sub2src, '-O2')
+
+ def test_sanitizers(self):
+ testdir = os.path.join(self.unit_test_dir, '125 sanitizers')
+
+ with self.subTest('no b_sanitize value'):
+ try:
+ out = self.init(testdir)
+ self.assertRegex(out, 'value *: *none')
+ finally:
+ self.wipe()
+
+ for value, expected in { '': 'none',
+ 'none': 'none',
+ 'address': 'address',
+ 'undefined,address': 'address,undefined',
+ 'address,undefined': 'address,undefined' }.items():
+ with self.subTest('b_sanitize=' + value):
+ try:
+ out = self.init(testdir, extra_args=['-Db_sanitize=' + value])
+ self.assertRegex(out, 'value *: *' + expected)
+ finally:
+ self.wipe()