]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/fuzz/meson.build
meson: use ternary op for brevity
[thirdparty/systemd.git] / test / fuzz / meson.build
CommitLineData
db9ecf05 1# SPDX-License-Identifier: LGPL-2.1-or-later
b68dfb9e 2
7e343b53 3generate_directives_py = find_program('generate-directives.py')
7e343b53 4
cbc55c4c 5fuzz_regression_tests = {}
7e343b53 6
cbc55c4c
YW
7directives = [['fuzz-network-parser', 'directives.network', networkd_network_gperf_gperf],
8 ['fuzz-netdev-parser', 'directives.netdev', networkd_netdev_gperf_gperf],
9 ['fuzz-link-parser', 'directives.link', udev_link_gperf_gperf],
7e343b53
MK
10 ]
11
12foreach tuple : directives
cbc55c4c
YW
13 directive = custom_target(
14 tuple[1],
15 output: tuple[1],
16 command: [generate_directives_py, tuple[2]],
7e343b53 17 capture: true)
cbc55c4c
YW
18
19 dict = { 'directives' : [directive] }
20 fuzz_regression_tests += { tuple[0] : dict }
7e343b53
MK
21endforeach
22
cbc55c4c 23unit_directives = []
7e343b53
MK
24foreach section : ['Automount', 'Mount', 'Path', 'Scope', 'Service', 'Slice', 'Socket', 'Swap', 'Timer']
25 unit_type = section.to_lower()
26 sec_rx = section == 'Service' ? '(Service|Unit|Install)' : section
cbc55c4c
YW
27 name = 'directives.@0@'.format(unit_type)
28 unit_directives += custom_target(
29 name,
30 output: name,
7e343b53
MK
31 command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type],
32 capture: true)
33endforeach
cbc55c4c
YW
34dict = { 'directives' : unit_directives }
35fuzz_regression_tests += { 'fuzz-unit-file' : dict }
7e343b53 36
7e343b53
MK
37############################################################
38
7f9a0d6d
JJ
39# TODO: Use native string formatting with meson >= 1.3.0
40if get_option('auto_features').enabled()
41 sanitize_auto_features = 'enabled'
42elif get_option('auto_features').disabled()
43 sanitize_auto_features = 'disabled'
44else
45 sanitize_auto_features = 'auto'
46endif
47
a3d3bf55 48fuzz_c_args = get_option('c_args')
3e0cf732 49fuzz_cpp_args = cxx_cmd != '' ? get_option('cpp_args') : []
a3d3bf55 50
89767158
EV
51sanitize_address_undefined = custom_target(
52 'sanitize-address-undefined-fuzzers',
53 output : 'sanitize-address-undefined-fuzzers',
b68dfb9e 54 command : [meson_build_sh,
1485aacb 55 project_source_root,
b68dfb9e
ZJS
56 '@OUTPUT@',
57 'fuzzers',
a3d3bf55
FS
58 ' '.join(fuzz_c_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'),
59 ' '.join(fuzz_cpp_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'),
17ee59c9 60 '-Dfuzz-tests=true -Db_lundef=false -Db_sanitize=address,undefined --optimization=@0@ @1@ --auto-features=@2@'.format(
7847b548 61 get_option('optimization'),
be496d6a 62 get_option('werror') ? '--werror' : '',
7f9a0d6d 63 sanitize_auto_features
7847b548 64 ),
f6d783ac 65 ' '.join(cc.cmd_array()),
9b0ca019 66 cxx_cmd])
b68dfb9e 67
7db5761d
MK
68fuzz_sanitizers = [['address,undefined', sanitize_address_undefined]]
69fuzz_testsdir = 'test/fuzz'
52d4d1d3 70
edd84b8e 71if git.found() and fs.is_dir(project_source_root / '.git')
0f4c4f38
ZJS
72 out = run_command(env, '-u', 'GIT_WORK_TREE',
73 git, '--git-dir=@0@/.git'.format(project_source_root),
7db5761d 74 'ls-files', ':/@0@/*/*'.format(fuzz_testsdir),
68a06b3c 75 check: true)
e6bad674 76else
7db5761d 77 out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(project_source_root, fuzz_testsdir), check: true)
e6bad674
ZJS
78endif
79
7e343b53 80# Add crafted fuzz inputs we have in the repo
e6bad674
ZJS
81foreach p : out.stdout().split()
82 # Remove the last entry which is ''.
83 #
84 # Also, backslashes get mangled, so skip test. See
85 # https://github.com/mesonbuild/meson/issues/1564.
7db5761d
MK
86 if p.contains('\\')
87 continue
e6bad674 88 endif
739a62bb
JJ
89 fuzzer = fs.name(fs.parent(p))
90 fuzz_in = fs.name(p)
cbc55c4c
YW
91
92 dict = fuzz_regression_tests.get(fuzzer, {})
93 dict += { 'files' : dict.get('files', []) + files(fuzzer / fuzz_in) }
94 fuzz_regression_tests += { fuzzer : dict }
e6bad674 95endforeach