summaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-01-19 17:54:30 +1100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:50:20 +0200
commit982bf4f3897a1ff9253cac7bc2f90a7984207f37 (patch)
tree7637ebef3ba36ff438eb0054b15b0f2c38a4dd08 /meson.build
parentb378688cfed10574fc103527aaa230f0cb4c498d (diff)
Hook up oss-fuzz test cases as tests
This is a bit painful because a separate build of systemd is necessary. The tests are guarded by tests!=false and slow-tests==true. Running them is not slow, but compilation certainly is. If this proves unwieldy, we can add a separate option controlling those builds later. The build for each sanitizer has its own directory, and we build all fuzzer tests there, and then pull them out one-by-one by linking into the target position as necessary. It would be nicer to just build the desired fuzzer, but we need to build the whole nested build as one unit. [I also tried making systemd and nested meson subproject. This would work nicely, but meson does not allow that because the nested target names are the same as the outer project names. If that is ever fixed, that would be the way to go.] v2: - make sure things still work if memory sanitizer is not available v3: - switch to syntax which works with meson 0.42.1 found in Ubuntu
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build66
1 files changed, 63 insertions, 3 deletions
diff --git a/meson.build b/meson.build
index 4331af1fd..2e592cee6 100644
--- a/meson.build
+++ b/meson.build
@@ -323,6 +323,7 @@ substs.set('VARLOGDIR', varlogdir)
cc = meson.get_compiler('c')
pkgconfig = import('pkgconfig')
check_compilation_sh = find_program('tools/meson-check-compilation.sh')
+meson_build_sh = find_program('tools/meson-build.sh')
if get_option('tests') != 'false'
cxx = find_program('c++', required : false)
@@ -449,6 +450,20 @@ foreach arg : ['-Wl,-z,relro',
endif
endforeach
+# Check if various sanitizers are supported
+sanitizers = []
+foreach arg : ['address']
+
+ have = run_command(check_compilation_sh,
+ cc.cmd_array(), '-x', 'c',
+ '-fsanitize=@0@'.format(arg),
+ '-include', link_test_c).returncode() == 0
+ message('@0@ sanitizer supported: @1@'.format(arg, have ? 'yes' : 'no'))
+ if have
+ sanitizers += arg
+ endif
+endforeach
+
if get_option('buildtype') != 'debug'
foreach arg : ['-ffunction-sections',
'-fdata-sections']
@@ -581,6 +596,7 @@ awk = find_program('awk')
m4 = find_program('m4')
stat = find_program('stat')
git = find_program('git', required : false)
+env = find_program('env')
meson_make_symlink = meson.source_root() + '/tools/meson-make-symlink.sh'
#if 1 /// Needed by elogind
@@ -665,8 +681,7 @@ conf.set('GPERF_LEN_TYPE', gperf_len_type,
if not cc.has_header('sys/capability.h')
error('POSIX caps headers not found')
endif
-foreach header : ['crypt.h',
- 'linux/btrfs.h',
+foreach header : ['linux/btrfs.h',
'linux/memfd.h',
'linux/vm_sockets.h',
'sys/auxv.h',
@@ -1360,10 +1375,11 @@ endforeach
want_tests = get_option('tests')
install_tests = get_option('install-tests')
+slow_tests = get_option('slow-tests')
tests = []
fuzzers = []
-conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', get_option('slow-tests'))
+conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', slow_tests)
#####################################################################
@@ -2884,6 +2900,50 @@ endforeach
############################################################
+prev = ''
+foreach p : fuzz_regression_tests
+ a = p.split('/')[-3]
+ b = p.split('/')[-2]
+ c = p.split('/')[-1]
+
+ if a == 'address'
+ build = sanitize_address
+ else
+ error('unknown sanitizer @0@'.format(a))
+ endif
+
+ name = '@1@:@0@'.format(a, b)
+
+ if name != prev
+ if want_tests == 'false'
+ message('Not compiling @0@ because tests is set to false'.format(name))
+ elif not sanitizers.contains(a)
+ message('Not compiling @0@ because @1@ sanitizer is not available'.format(name, a))
+ elif slow_tests
+ exe = custom_target(
+ name,
+ output : name,
+ depends : build,
+ command : [env, 'ln', '-fs',
+ join_paths(build.full_path(), b),
+ '@OUTPUT@'],
+ build_by_default : true)
+ else
+ message('Not compiling @0@ because slow-tests is set to false'.format(name))
+ endif
+ endif
+ prev = name
+
+ if want_tests != 'false' and slow_tests
+ test(c, env, args : [exe.full_path(),
+ join_paths(meson.source_root(),
+ 'test/fuzz-regressions',
+ p)])
+ endif
+endforeach
+
+############################################################
+
if git.found()
all_files = run_command(
git,