meson: Store fuzz tests in structured way

Put fuzzer tests into dictionary that maps `fuzzer->list of inputs`
instead of the flat list.
This is just refactoring with no intentional .
This commit is contained in:
Michal Koutný 2022-10-06 19:06:08 +02:00
parent f4a4493eb5
commit 7db5761dda
2 changed files with 44 additions and 45 deletions

View file

@ -4007,19 +4007,14 @@ foreach tuple : fuzzers
build_by_default : fuzzer_build) build_by_default : fuzzer_build)
fuzzer_exes += exe fuzzer_exes += exe
if want_tests != 'false' if want_tests != 'false' and name in fuzz_regression_tests
# Run the fuzz regression tests without any sanitizers enabled. # Run the fuzz regression tests without any sanitizers enabled.
# Additional invocations with sanitizers may be added below. # Additional invocations with sanitizers may be added below.
foreach p : fuzz_regression_tests foreach fuzz_in : fuzz_regression_tests[name]
b = p.split('/')[-2] test('@0@_@1@'.format(name, fuzz_in),
c = p.split('/')[-1] exe,
suite : 'fuzzers',
if b == name args : [project_source_root / fuzz_testsdir / name / fuzz_in])
test('@0@_@1@'.format(b, c),
exe,
suite : 'fuzzers',
args : [project_source_root / p])
endif
endforeach endforeach
endif endif
endforeach endforeach
@ -4122,45 +4117,39 @@ endif
############################################################ ############################################################
# Enable tests for all supported sanitizers # Enable tests for all supported sanitizers
foreach tuple : sanitizers foreach tuple : fuzz_sanitizers
sanitizer = tuple[0] sanitizer = tuple[0]
build = tuple[1] build = tuple[1]
if cc.has_link_argument('-fsanitize=@0@'.format(sanitizer)) if cc.has_link_argument('-fsanitize=@0@'.format(sanitizer))
prev = '' foreach fuzzer, fuzz_ins : fuzz_regression_tests
foreach p : fuzz_regression_tests name = '@0@:@1@'.format(fuzzer, sanitizer)
b = p.split('/')[-2] if want_tests == 'false'
c = p.split('/')[-1] message('Not compiling @0@ because tests is set to false'.format(name))
continue
name = '@0@:@1@'.format(b, sanitizer)
if name != prev
if want_tests == 'false'
message('Not compiling @0@ because tests is set to false'.format(name))
elif fuzz_tests
exe = custom_target(
name,
output : name,
depends : build,
command : [ln, '-fs',
build.full_path() / b,
'@OUTPUT@'],
build_by_default : true)
else
message('Not compiling @0@ because fuzz-tests is set to false'.format(name))
endif
endif endif
prev = name if not fuzz_tests
message('Not compiling @0@ because fuzz-tests is set to false'.format(name))
continue
endif
exe = custom_target(
name,
output : name,
depends : build,
command : [ln, '-fs',
build.full_path() / fuzzer,
'@OUTPUT@'],
build_by_default : true)
if fuzz_tests foreach fuzz_in : fuzz_ins
test('@0@_@1@_@2@'.format(b, c, sanitizer), test('@0@_@1@_@2@'.format(fuzzer, fuzz_in, sanitizer),
env, env,
suite : 'fuzz+san', suite : 'fuzz+san',
env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
timeout : 60, timeout : 60,
args : [exe.full_path(), args : [exe.full_path(),
project_source_root / p]) project_source_root / fuzz_testsdir / fuzzer / fuzz_in])
endif endforeach
endforeach endforeach
endif endif
endforeach endforeach

View file

@ -16,24 +16,34 @@ sanitize_address_undefined = custom_target(
' '.join(cc.cmd_array()), ' '.join(cc.cmd_array()),
cxx_cmd]) cxx_cmd])
sanitizers = [['address,undefined', sanitize_address_undefined]] fuzz_sanitizers = [['address,undefined', sanitize_address_undefined]]
fuzz_testsdir = 'test/fuzz'
if git.found() and fs.exists(project_source_root / '.git') if git.found() and fs.exists(project_source_root / '.git')
out = run_command(env, '-u', 'GIT_WORK_TREE', out = run_command(env, '-u', 'GIT_WORK_TREE',
git, '--git-dir=@0@/.git'.format(project_source_root), git, '--git-dir=@0@/.git'.format(project_source_root),
'ls-files', ':/test/fuzz/*/*', 'ls-files', ':/@0@/*/*'.format(fuzz_testsdir),
check: true) check: true)
else else
out = run_command(sh, '-c', 'cd "@0@"; echo test/fuzz/*/*'.format(project_source_root), check: true) out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(project_source_root, fuzz_testsdir), check: true)
endif endif
fuzz_regression_tests = [] fuzz_regression_tests = {}
foreach p : out.stdout().split() foreach p : out.stdout().split()
# Remove the last entry which is ''. # Remove the last entry which is ''.
# #
# Also, backslashes get mangled, so skip test. See # Also, backslashes get mangled, so skip test. See
# https://github.com/mesonbuild/meson/issues/1564. # https://github.com/mesonbuild/meson/issues/1564.
if not p.contains('\\') if p.contains('\\')
fuzz_regression_tests += p continue
endif endif
fuzzer = p.split('/')[-2]
fuzz_in = p.split('/')[-1]
if fuzzer not in fuzz_regression_tests
fuzz_regression_tests += {fuzzer: []}
endif
# Meson parser provision for: fuzz_regression_tests[fuzzer] += [fuzz_in]
l = fuzz_regression_tests[fuzzer]
l += [fuzz_in]
fuzz_regression_tests += {fuzzer: l}
endforeach endforeach