build+ci: enable AddressSanitizer and LeakSanitizer for unit tests
Refs: #2589, #4206
Change-Id: Ie9770134ff87fce438029b97c9ed61dbef3a71a3
diff --git a/.waf-tools/sanitizers.py b/.waf-tools/sanitizers.py
new file mode 100644
index 0000000..a8fe55d
--- /dev/null
+++ b/.waf-tools/sanitizers.py
@@ -0,0 +1,22 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def options(opt):
+ opt.add_option('--with-sanitizer', action='store', default='', dest='sanitizers',
+ help='Comma-separated list of compiler sanitizers to enable [default=none]')
+
+def configure(conf):
+ for san in conf.options.sanitizers.split(','):
+ if not san:
+ continue
+
+ sanflag = '-fsanitize=%s' % san
+ conf.start_msg('Checking if compiler supports %s' % sanflag)
+
+ if conf.check_cxx(cxxflags=['-Werror', sanflag, '-fno-omit-frame-pointer'],
+ linkflags=[sanflag], mandatory=False):
+ conf.end_msg('yes')
+ conf.env.append_unique('CXXFLAGS', [sanflag, '-fno-omit-frame-pointer'])
+ conf.env.append_unique('LINKFLAGS', [sanflag])
+ else:
+ conf.end_msg('no', color='RED')
+ conf.fatal('%s sanitizer is not supported by the current compiler' % san)