]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/fuzz/meson.build
b6bcb52551570d99268969c22effb15c0c49bdd7
[thirdparty/systemd.git] / test / fuzz / meson.build
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 generate_directives_py = find_program('generate-directives.py')
4
5 fuzz_regression_tests = {}
6
7 directives = [['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],
10 ]
11
12 foreach tuple : directives
13 directive = custom_target(
14 tuple[1],
15 output: tuple[1],
16 command: [generate_directives_py, tuple[2]],
17 capture: true)
18
19 dict = { 'directives' : [directive] }
20 fuzz_regression_tests += { tuple[0] : dict }
21 endforeach
22
23 unit_directives = []
24 foreach 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
27 name = 'directives.@0@'.format(unit_type)
28 unit_directives += custom_target(
29 name,
30 output: name,
31 command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type],
32 capture: true)
33 endforeach
34 dict = { 'directives' : unit_directives }
35 fuzz_regression_tests += { 'fuzz-unit-file' : dict }
36
37 ############################################################
38
39 # TODO: Use native string formatting with meson >= 1.3.0
40 if get_option('auto_features').enabled()
41 sanitize_auto_features = 'enabled'
42 elif get_option('auto_features').disabled()
43 sanitize_auto_features = 'disabled'
44 else
45 sanitize_auto_features = 'auto'
46 endif
47
48 fuzz_c_args = get_option('c_args')
49 if cxx_cmd != ''
50 fuzz_cpp_args = get_option('cpp_args')
51 else
52 fuzz_cpp_args = []
53 endif
54
55 sanitize_address_undefined = custom_target(
56 'sanitize-address-undefined-fuzzers',
57 output : 'sanitize-address-undefined-fuzzers',
58 command : [meson_build_sh,
59 project_source_root,
60 '@OUTPUT@',
61 'fuzzers',
62 ' '.join(fuzz_c_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'),
63 ' '.join(fuzz_cpp_args + '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION'),
64 '-Dfuzz-tests=true -Db_lundef=false -Db_sanitize=address,undefined --optimization=@0@ @1@ --auto-features=@2@'.format(
65 get_option('optimization'),
66 get_option('werror') ? '--werror' : '',
67 sanitize_auto_features
68 ),
69 ' '.join(cc.cmd_array()),
70 cxx_cmd])
71
72 fuzz_sanitizers = [['address,undefined', sanitize_address_undefined]]
73 fuzz_testsdir = 'test/fuzz'
74
75 if git.found() and fs.is_dir(project_source_root / '.git')
76 out = run_command(env, '-u', 'GIT_WORK_TREE',
77 git, '--git-dir=@0@/.git'.format(project_source_root),
78 'ls-files', ':/@0@/*/*'.format(fuzz_testsdir),
79 check: true)
80 else
81 out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(project_source_root, fuzz_testsdir), check: true)
82 endif
83
84 # Add crafted fuzz inputs we have in the repo
85 foreach p : out.stdout().split()
86 # Remove the last entry which is ''.
87 #
88 # Also, backslashes get mangled, so skip test. See
89 # https://github.com/mesonbuild/meson/issues/1564.
90 if p.contains('\\')
91 continue
92 endif
93 fuzzer = fs.name(fs.parent(p))
94 fuzz_in = fs.name(p)
95
96 dict = fuzz_regression_tests.get(fuzzer, {})
97 dict += { 'files' : dict.get('files', []) + files(fuzzer / fuzz_in) }
98 fuzz_regression_tests += { fuzzer : dict }
99 endforeach