Skip to content

Commit

Permalink
meson: Generate fuzzer inputs with directives
Browse files Browse the repository at this point in the history
The lists of directives for fuzzer tests are maintained manually in the
repo. There is a tools/check-directives.sh script that runs during test
phase and reports stale directive lists.
Let's rework the script into a generator so that these directive files
are created on-the-flight and needn't be updated whenever a unit file
directives change. The scripts is rewritten in Python to get rid of gawk
dependency and each generated file is a separate meson target so that
incremental builds refresh what is just necessary (and parallelize
(negligible)).

Note: test/fuzz/fuzz-unit-file/directives-all.slice is kept since there
is not automated way to generate it (it is not covered by the check
script neither).
  • Loading branch information
Werkov committed Oct 20, 2022
1 parent 7db5761 commit 7e343b5
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 2,265 deletions.
31 changes: 13 additions & 18 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,7 @@ foreach tuple : fuzzers
else
sources += 'src/fuzz/fuzz-main.c'
endif
sources += fuzz_generated_directives

# FIXME: Use fs.stem() with meson >= 0.54.0
name = '@0@'.format(sources[0]).split('/')[-1].split('.')[0]
Expand All @@ -4010,11 +4011,14 @@ foreach tuple : fuzzers
if want_tests != 'false' and name in fuzz_regression_tests
# Run the fuzz regression tests without any sanitizers enabled.
# Additional invocations with sanitizers may be added below.
foreach fuzz_in : fuzz_regression_tests[name]
foreach tuple : fuzz_regression_tests[name]
fuzz_dir = tuple[0]
fuzz_in = tuple[1]
test('@0@_@1@'.format(name, fuzz_in),
exe,
suite : 'fuzzers',
args : [project_source_root / fuzz_testsdir / name / fuzz_in])
args : [fuzz_dir != '' ? project_source_root / fuzz_dir / name / fuzz_in
: fuzz_generated_in_dir / '@0@_@1@'.format(name, fuzz_in)])
endforeach
endif
endforeach
Expand Down Expand Up @@ -4103,19 +4107,6 @@ foreach exec : public_programs
endif
endforeach

############################################################

check_directives_sh = find_program('tools/check-directives.sh')

if want_tests != 'false'
test('check-directives',
check_directives_sh,
suite : 'dist-check',
args : [project_source_root, project_build_root])
endif

############################################################

# Enable tests for all supported sanitizers
foreach tuple : fuzz_sanitizers
sanitizer = tuple[0]
Expand All @@ -4135,20 +4126,24 @@ foreach tuple : fuzz_sanitizers
exe = custom_target(
name,
output : name,
depends : build,
depends : [build] + fuzz_generated_directives,
command : [ln, '-fs',
build.full_path() / fuzzer,
'@OUTPUT@'],
build_by_default : true)

foreach fuzz_in : fuzz_ins
foreach tuple : fuzz_ins
fuzz_dir = tuple[0]
fuzz_in = tuple[1]

test('@0@_@1@_@2@'.format(fuzzer, fuzz_in, sanitizer),
env,
suite : 'fuzz+san',
env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
timeout : 60,
args : [exe.full_path(),
project_source_root / fuzz_testsdir / fuzzer / fuzz_in])
fuzz_dir != '' ? project_source_root / fuzz_dir / fuzzer / fuzz_in
: fuzz_generated_in_dir / '@0@_@1@'.format(fuzzer, fuzz_in)])
endforeach
endforeach
endif
Expand Down
97 changes: 0 additions & 97 deletions test/fuzz/fuzz-link-parser/directives.link

This file was deleted.

Loading

0 comments on commit 7e343b5

Please sign in to comment.