From e5cc6d107c0399847c04cbc564625bdca9ae6e63 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 26 Jun 2023 03:46:05 +0900 Subject: [PATCH 1/8] meson: move several test declarations One of the notable change is that previously test-sysusers.sh was installed unconditionally, but now it is installed only when sysusers is enabled. Another change is that test-sysv-generator is now re-introduced which was mistakenly dropped by 6c713961ab0831fe744a2df9c4e9e258b6ba3105. --- meson.build | 126 +--------------------------------- test/meson.build | 173 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 160 insertions(+), 139 deletions(-) diff --git a/meson.build b/meson.build index eba5cf3739..8dcc8ead4a 100644 --- a/meson.build +++ b/meson.build @@ -2466,8 +2466,6 @@ subdir('src/systemd') subdir('src/test') subdir('src/fuzz') -subdir('rules.d') -subdir('test') subdir('src/ukify/test') # needs to be last for test_env variable alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc) @@ -2588,111 +2586,6 @@ endforeach ############################################################ -if want_tests != 'false' - exe = executables_by_name.get('systemd-analyze') - test('test-compare-versions', - test_compare_versions_sh, - args : exe.full_path()) -endif - -if want_tests != 'false' - exe = executables_by_name.get('systemd-fstab-generator') - test('test-fstab-generator', - test_fstab_generator_sh, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path(), - env : test_env, - depends : exe) -endif - -if conf.get('HAVE_BLKID') == 1 and conf.get('ENABLE_BOOTLOADER') == 1 - if want_tests != 'false' - exe = executables_by_name.get('bootctl') - test('test-bootctl-json', - test_bootctl_json_sh, - args : exe.full_path(), - depends : exe) - endif -endif - -if want_tests != 'false' - systemctl = executables_by_name.get('systemctl') - systemd_id128 = executables_by_name.get('systemd-id128') - test('test-systemctl-enable', - test_systemctl_enable_sh, - # https://github.com/mesonbuild/meson/issues/2681 - args : [systemctl.full_path(), - systemd_id128.full_path()]) -endif - -if enable_sysusers - if want_tests != 'false' - exe = executables_by_name.get('systemd-sysusers') - test('test-sysusers', - test_sysusers_sh, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path()) - endif - - if have_standalone_binaries - if want_tests != 'false' - exe = executables_by_name.get('systemd-sysusers.standalone') - test('test-sysusers.standalone', - test_sysusers_sh, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path()) - endif - endif -endif - -if conf.get('ENABLE_TMPFILES') == 1 - if want_tests != 'false' - exe = executables_by_name.get('systemd-tmpfiles') - test('test-systemd-tmpfiles', - test_systemd_tmpfiles_py, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path()) - endif - - if have_standalone_binaries - if want_tests != 'false' - exe = executables_by_name.get('systemd-tmpfiles.standalone') - test('test-systemd-tmpfiles.standalone', - test_systemd_tmpfiles_py, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path()) - endif - endif -endif - -if conf.get('ENABLE_HWDB') == 1 - if want_tests != 'false' - exe = executables_by_name.get('systemd-hwdb') - test('hwdb-test', - hwdb_test_sh, - suite : 'dist', - args : exe.full_path(), - timeout : 90) - endif -endif - -if want_tests != 'false' - exe = executables_by_name.get('udevadm') - test('udev-rules-check', - exe, - suite : 'dist', - args : ['verify', '--resolve-names=never', all_rules]) -endif - -if want_tests != 'false' - exe = executables_by_name.get('systemd-network-generator') - test('test-network-generator-conversion', - test_network_generator_conversion_sh, - # https://github.com/mesonbuild/meson/issues/2681 - args : exe.full_path(), - depends : exe) -endif - ukify = custom_target( 'ukify', input : 'src/ukify/ukify.py', @@ -2705,24 +2598,11 @@ if want_ukify public_programs += ukify endif -if want_tests != 'false' and conf.get('ENABLE_KERNEL_INSTALL') == 1 - kernel_install = executables_by_name.get('kernel-install') - args = [kernel_install.full_path(), loaderentry_install.full_path(), uki_copy_install] - deps = [kernel_install, loaderentry_install] - if want_ukify and boot_stubs.length() > 0 - args += [ukify.full_path(), ukify_install.full_path(), boot_stubs[0]] - deps += [ukify, ukify_install, boot_stubs[0]] - endif - - test('test-kernel-install', - test_kernel_install_sh, - env : test_env, - args : args, - depends: deps) -endif - ############################################################ +subdir('rules.d') +subdir('test') + runtest_env = custom_target( 'systemd-runtest.env', output : 'systemd-runtest.env', diff --git a/test/meson.build b/test/meson.build index b48434a356..f41c01fa35 100644 --- a/test/meson.build +++ b/test/meson.build @@ -49,30 +49,118 @@ if install_tests unittestsdir / 'testdata') endif -test_bootctl_json_sh = find_program('test-bootctl-json.sh') -test_fstab_generator_sh = find_program('test-fstab-generator.sh') -test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh') -test_systemctl_enable_sh = find_program('test-systemctl-enable.sh') -test_systemd_tmpfiles_py = find_program('test-systemd-tmpfiles.py') -hwdb_test_sh = find_program('hwdb-test.sh') +############################################################ + +if conf.get('ENABLE_SYSUSERS') == 1 + test_sysusers_sh = configure_file( + input : 'test-sysusers.sh.in', + output : 'test-sysusers.sh', + configuration : conf) + + if want_tests != 'false' + exe = executables_by_name.get('systemd-sysusers') + test('test-sysusers', + test_sysusers_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : exe.full_path(), + depends : exe) + + if have_standalone_binaries + exe = executables_by_name.get('systemd-sysusers.standalone') + test('test-sysusers.standalone', + test_sysusers_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : exe.full_path(), + depends : exe) + endif + endif + + if install_tests + install_data(test_sysusers_sh, + install_dir : unittestsdir) + install_subdir('test-sysusers', + exclude_files : '.gitattributes', + install_dir : testdata_dir) + endif +endif ############################################################ -test_sysusers_sh = configure_file( - input : 'test-sysusers.sh.in', - output : 'test-sysusers.sh', - configuration : conf) -if install_tests and conf.get('ENABLE_SYSUSERS') == 1 - install_data(test_sysusers_sh, - install_dir : unittestsdir) - install_subdir('test-sysusers', - exclude_files : '.gitattributes', - install_dir : testdata_dir) +if want_tests != 'false' and conf.get('ENABLE_HWDB') == 1 + hwdb_test_sh = find_program('hwdb-test.sh') + exe = executables_by_name.get('systemd-hwdb') + test('hwdb-test', + hwdb_test_sh, + suite : 'dist', + args : exe.full_path(), + depends : exe, + timeout : 90) +endif + +############################################################ + +if want_tests != 'false' + test_systemctl_enable_sh = find_program('test-systemctl-enable.sh') + systemctl = executables_by_name.get('systemctl') + systemd_id128 = executables_by_name.get('systemd-id128') + test('test-systemctl-enable', + test_systemctl_enable_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : [systemctl.full_path(), + systemd_id128.full_path()], + depends : [systemctl, systemd_id128]) +endif + +############################################################ + +if want_tests != 'false' and conf.get('HAVE_SYSV_COMPAT') == 1 + sysv_generator_test_py = find_program('sysv-generator-test.py') + exe = executables_by_name.get('systemd-sysv-generator') + test('sysv-generator-test', + sysv_generator_test_py, + depends : exe) +endif + +############################################################ + +if want_tests != 'false' and conf.get('HAVE_BLKID') == 1 and conf.get('ENABLE_BOOTLOADER') == 1 + test_bootctl_json_sh = find_program('test-bootctl-json.sh') + exe = executables_by_name.get('bootctl') + test('test-bootctl-json', + test_bootctl_json_sh, + args : exe.full_path(), + depends : exe) +endif + +############################################################ + +if want_tests != 'false' and conf.get('ENABLE_TMPFILES') == 1 + test_systemd_tmpfiles_py = find_program('test-systemd-tmpfiles.py') + exe = executables_by_name.get('systemd-tmpfiles') + test('test-systemd-tmpfiles', + test_systemd_tmpfiles_py, + args : exe.full_path(), + depends : exe) + + if have_standalone_binaries + exe = executables_by_name.get('systemd-tmpfiles.standalone') + test('test-systemd-tmpfiles.standalone', + test_systemd_tmpfiles_py, + args : exe.full_path(), + depends : exe) + endif endif ############################################################ test_compare_versions_sh = files('test-compare-versions.sh') +if want_tests != 'false' + exe = executables_by_name.get('systemd-analyze') + test('test-compare-versions', + test_compare_versions_sh, + args : exe.full_path(), + depends : exe) +endif if install_tests install_data(test_compare_versions_sh, install_dir : unittestsdir) @@ -86,6 +174,12 @@ if want_tests != 'false' rule_syntax_check_py, suite : 'dist', args : all_rules) + + exe = executables_by_name.get('udevadm') + test('udev-rules-check', + exe, + suite : 'dist', + args : ['verify', '--resolve-names=never', all_rules]) endif ############################################################ @@ -94,11 +188,38 @@ if install_tests install_data('run-unit-tests.py', install_mode : 'rwxr-xr-x', install_dir : testsdir) +endif +############################################################ + +test_fstab_generator_sh = find_program('test-fstab-generator.sh') +if want_tests != 'false' + exe = executables_by_name.get('systemd-fstab-generator') + test('test-fstab-generator', + test_fstab_generator_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : exe.full_path(), + env : test_env, + depends : exe) +endif +if install_tests install_data('test-fstab-generator.sh', install_mode : 'rwxr-xr-x', install_dir : unittestsdir) +endif +############################################################ + +test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh') +if want_tests != 'false' + exe = executables_by_name.get('systemd-network-generator') + test('test-network-generator-conversion', + test_network_generator_conversion_sh, + # https://github.com/mesonbuild/meson/issues/2681 + args : exe.full_path(), + depends : exe) +endif +if install_tests install_data('test-network-generator-conversion.sh', install_mode : 'rwxr-xr-x', install_dir : unittestsdir) @@ -162,4 +283,24 @@ if want_tests != 'false' and dmi_arches.contains(host_machine.cpu_family()) endforeach endif +############################################################ + +if want_tests != 'false' and conf.get('ENABLE_KERNEL_INSTALL') == 1 + kernel_install = executables_by_name.get('kernel-install') + args = [kernel_install.full_path(), loaderentry_install.full_path(), uki_copy_install] + deps = [kernel_install, loaderentry_install] + if want_ukify and boot_stubs.length() > 0 + args += [ukify.full_path(), ukify_install.full_path(), boot_stubs[0]] + deps += [ukify, ukify_install, boot_stubs[0]] + endif + + test('test-kernel-install', + test_kernel_install_sh, + env : test_env, + args : args, + depends : deps) +endif + +############################################################ + subdir('fuzz') From ff2dedcffd178ac94b45d78c62f7c4e8c5e782db Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 3 Aug 2023 20:36:51 +0900 Subject: [PATCH 2/8] test: fix test executable name Follow-up for 82a1d6d09625b656c991f25e82b5651c74a55945. --- src/shutdown/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index ca7ea3840d..0b16c431b4 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -33,8 +33,8 @@ executables += [ tests += [ { 'sources' : files( - 'detach-swap.c', 'test-umount.c', + 'detach-swap.c', 'umount.c', ), 'dependencies' : libmount, From 12b4cffdae29445d4bce32567c314c9c9700eb2d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 30 Jul 2023 06:32:53 +0900 Subject: [PATCH 3/8] meson: introduce HAVE_DMI flag The condition is used at several places. Let's introduce a simple flag for that. --- meson.build | 4 ++++ rules.d/meson.build | 2 +- src/udev/meson.build | 3 +-- test/meson.build | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 8dcc8ead4a..430457bb1e 100644 --- a/meson.build +++ b/meson.build @@ -1689,6 +1689,9 @@ if dbus_interfaces_dir == '' or dbus_interfaces_dir == 'yes' endif endif +dmi_arches = ['x86', 'x86_64', 'aarch64', 'arm', 'ia64', 'loongarch64', 'mips'] +conf.set10('HAVE_DMI', host_machine.cpu_family() in dmi_arches) + # We support one or the other. If gcrypt is available, we assume it's there to # be used, and use it in preference. opt = get_option('cryptolib') @@ -3166,6 +3169,7 @@ foreach tuple : [ ['xdg-autostart'], # optional features + ['dmi'], ['idn'], ['polkit'], ['nscd'], diff --git a/rules.d/meson.build b/rules.d/meson.build index 20fca222da..13f25397dc 100644 --- a/rules.d/meson.build +++ b/rules.d/meson.build @@ -36,7 +36,7 @@ rules = [ conf.get('HAVE_KMOD') == 1], [files('70-memory.rules'), - dmi_arches.contains(host_machine.cpu_family())], + conf.get('HAVE_DMI') == 1], [files('70-power-switch.rules'), enable_logind], diff --git a/src/udev/meson.build b/src/udev/meson.build index 932a718651..2c10095941 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -144,8 +144,7 @@ udev_progs = [['ata_id/ata_id.c'], ['mtd_probe/mtd_probe.c', 'mtd_probe/probe_smartmedia.c']] -dmi_arches = ['x86', 'x86_64', 'aarch64', 'arm', 'ia64', 'loongarch64', 'mips'] -if dmi_arches.contains(host_machine.cpu_family()) +if conf.get('HAVE_DMI') == 1 udev_progs += [['dmi_memory_id/dmi_memory_id.c']] endif diff --git a/test/meson.build b/test/meson.build index f41c01fa35..d57736e739 100644 --- a/test/meson.build +++ b/test/meson.build @@ -256,7 +256,7 @@ endif ############################################################ -if want_tests != 'false' and dmi_arches.contains(host_machine.cpu_family()) +if want_tests != 'false' and conf.get('HAVE_DMI') == 1 udev_dmi_memory_id_test = find_program('udev-dmi-memory-id-test.sh') if git.found() and fs.is_dir(project_source_root / '.git') From adedcd39a8a49360875258fbca559b4467d68884 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 26 Jun 2023 05:01:03 +0900 Subject: [PATCH 4/8] meson: use template to declare udev plugins --- src/udev/meson.build | 82 ++++++++++++++++++++++++++------------------ test/meson.build | 5 +-- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/udev/meson.build b/src/udev/meson.build index 2c10095941..bc5c859845 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -116,6 +116,13 @@ libudevd_core = static_library( userspace], build_by_default : false) +udev_plugin_template = executable_template + { + 'public' : true, + 'link_with' : udev_link_with, + 'install_rpath' : udev_rpath, + 'install_dir' : udevlibexecdir, +} + executables += [ executable_template + { 'name' : 'udevadm', @@ -131,41 +138,50 @@ executables += [ ], 'install_rpath' : udev_rpath, }, + udev_plugin_template + { + 'name' : 'ata_id', + 'sources' : files('ata_id/ata_id.c'), + }, + udev_plugin_template + { + 'name' : 'cdrom_id', + 'sources' : files('cdrom_id/cdrom_id.c'), + }, + udev_plugin_template + { + 'name' : 'dmi_memory_id', + 'conditions' : ['HAVE_DMI'], + 'sources' : files('dmi_memory_id/dmi_memory_id.c'), + }, + udev_plugin_template + { + 'name' : 'fido_id', + 'sources' : files( + 'fido_id/fido_id.c', + 'fido_id/fido_id_desc.c', + ), + }, + udev_plugin_template + { + 'name' : 'iocost', + 'sources' : files('iocost/iocost.c'), + }, + udev_plugin_template + { + 'name' : 'mtd_probe', + 'sources' : files( + 'mtd_probe/mtd_probe.c', + 'mtd_probe/probe_smartmedia.c', + ), + }, + udev_plugin_template + { + 'name' : 'scsi_id', + 'sources' : files( + 'scsi_id/scsi_id.c', + 'scsi_id/scsi_serial.c', + ), + }, + udev_plugin_template + { + 'name' : 'v4l_id', + 'sources' : files('v4l_id/v4l_id.c'), + }, ] -udev_progs = [['ata_id/ata_id.c'], - ['cdrom_id/cdrom_id.c'], - ['fido_id/fido_id.c', - 'fido_id/fido_id_desc.c'], - ['iocost/iocost.c'], - ['scsi_id/scsi_id.c', - 'scsi_id/scsi_serial.c'], - ['v4l_id/v4l_id.c'], - ['mtd_probe/mtd_probe.c', - 'mtd_probe/probe_smartmedia.c']] - -if conf.get('HAVE_DMI') == 1 - udev_progs += [['dmi_memory_id/dmi_memory_id.c']] -endif - -udev_prog_paths = {} -foreach prog : udev_progs - name = fs.stem(prog[0]) - - exe = executable( - name, - prog, - include_directories : includes, - dependencies : [userspace], - link_with : udev_link_with, - install_rpath : udev_rpath, - install : true, - install_dir : udevlibexecdir) - - udev_prog_paths += {name : exe} - public_programs += exe -endforeach - meson.add_install_script(meson_make_symlink, bindir / 'udevadm', libexecdir / 'systemd-udevd') diff --git a/test/meson.build b/test/meson.build index d57736e739..99f50828a3 100644 --- a/test/meson.build +++ b/test/meson.build @@ -258,6 +258,7 @@ endif if want_tests != 'false' and conf.get('HAVE_DMI') == 1 udev_dmi_memory_id_test = find_program('udev-dmi-memory-id-test.sh') + exe = executables_by_name.get('dmi_memory_id') if git.found() and fs.is_dir(project_source_root / '.git') out = run_command( @@ -276,10 +277,10 @@ if want_tests != 'false' and conf.get('HAVE_DMI') == 1 test('dmidecode_' + fs.stem(p), udev_dmi_memory_id_test, suite : 'dist', - args : [udev_prog_paths['dmi_memory_id'].full_path(), + args : [exe.full_path(), source, source + '.txt'], - depends : udev_prog_paths['dmi_memory_id']) + depends : exe) endforeach endif From 09fa0a0721e093144550b06f2ab7cb4275212be5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 3 Aug 2023 19:57:41 +0900 Subject: [PATCH 5/8] test: rename udev-rule-runner -> test-udev-rule-runner This partially revert 0454cf05d38d289474ca65c1917d414b2958f6b5. The executable actually does not work with itself, but needs to be combined with test-udev.py. But, even so, the executable is for testing. In the next commit, test and normal executables are declared in the same way, and naming of the executable becomes essential to classify them. Let's rename the executable and prefix with 'test-'. --- meson.build | 2 +- src/test/meson.build | 17 ----------------- src/udev/meson.build | 17 +++++++++++++++++ .../test-udev-rule-runner.c} | 0 test/test-udev.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) rename src/{test/udev-rule-runner.c => udev/test-udev-rule-runner.c} (100%) diff --git a/meson.build b/meson.build index 430457bb1e..fbf50a6ca0 100644 --- a/meson.build +++ b/meson.build @@ -2743,7 +2743,7 @@ if want_tests != 'false' and static_libudev != 'false' endif if want_tests != 'false' - exe = TESTS.get('udev-rule-runner') + exe = TESTS.get('test-udev-rule-runner') test('test-udev', test_udev_py, args : ['-v'], diff --git a/src/test/meson.build b/src/test/meson.build index ab0f091756..0d4dfa7f7e 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -409,23 +409,6 @@ tests += [ 'sources' : files('test-time-util.c'), 'timeout' : 120, }, - { - 'sources' : files('udev-rule-runner.c'), - 'link_with' : [ - libshared, - libudevd_core, - ], - 'dependencies' : [ - libacl, - libblkid, - libkmod, - librt, - libselinux, - threads, - ], - 'includes' : udev_includes, - 'type' : 'manual', - }, { 'sources' : files('test-utmp.c'), 'condition' : 'ENABLE_UTMP', diff --git a/src/udev/meson.build b/src/udev/meson.build index bc5c859845..9807648592 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -262,6 +262,23 @@ tests += [ 'sources' : files('test-udev-node.c'), 'base' : test_libudev_base, }, + { + 'sources' : files('test-udev-rule-runner.c'), + 'link_with' : [ + libshared, + libudevd_core, + ], + 'dependencies' : [ + libacl, + libblkid, + libkmod, + librt, + libselinux, + threads, + ], + 'includes' : udev_includes, + 'type' : 'manual', + }, { 'sources' : files('test-udev-rules.c'), 'base' : test_libudev_base, diff --git a/src/test/udev-rule-runner.c b/src/udev/test-udev-rule-runner.c similarity index 100% rename from src/test/udev-rule-runner.c rename to src/udev/test-udev-rule-runner.c diff --git a/test/test-udev.py b/test/test-udev.py index 710aaed3a9..02383ce4e9 100755 --- a/test/test-udev.py +++ b/test/test-udev.py @@ -43,7 +43,7 @@ SYS_SCRIPT = Path(__file__).with_name('sys-script.py') try: UDEV_BIN = Path(os.environ['UDEV_RULE_RUNNER']) except KeyError: - UDEV_BIN = Path(__file__).parent / 'manual/udev-rule-runner' + UDEV_BIN = Path(__file__).parent / 'manual/test-udev-rule-runner' UDEV_BIN = UDEV_BIN.absolute() # Those will be set by the udev_setup() fixture From 130c87b16a572169a3c4978391ca53fc37a19afe Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 26 Jun 2023 08:52:26 +0900 Subject: [PATCH 6/8] meson: merge declarations of normal and test executables --- meson.build | 241 ++++++++-------------- src/analyze/meson.build | 6 +- src/boot/efi/meson.build | 11 +- src/busctl/meson.build | 5 +- src/core/meson.build | 10 +- src/coredump/meson.build | 15 +- src/import/meson.build | 21 +- src/journal/meson.build | 96 ++++----- src/libsystemd-network/meson.build | 43 ++-- src/libsystemd/meson.build | 4 +- src/libudev/meson.build | 12 -- src/locale/meson.build | 19 +- src/login/meson.build | 45 ++--- src/machine/meson.build | 19 +- src/network/meson.build | 72 ++++--- src/nspawn/meson.build | 32 +-- src/oom/meson.build | 17 +- src/resolve/meson.build | 98 +++++---- src/shutdown/meson.build | 5 +- src/test/meson.build | 255 +++++++++++++----------- src/timesync/meson.build | 21 +- src/tmpfiles/meson.build | 5 +- src/udev/meson.build | 115 +++++------ src/xdg-autostart-generator/meson.build | 5 +- test/meson.build | 10 +- 25 files changed, 521 insertions(+), 661 deletions(-) diff --git a/meson.build b/meson.build index fbf50a6ca0..320302f15d 100644 --- a/meson.build +++ b/meson.build @@ -2172,8 +2172,8 @@ man_page_depends = [] ############################################################ -tests = [] simple_tests = [] +libsystemd_tests = [] fuzzers = [] simple_fuzzers = [] catalogs = [] @@ -2303,6 +2303,27 @@ install_libudev_static = static_library( ############################################################ +runtest_env = custom_target( + 'systemd-runtest.env', + output : 'systemd-runtest.env', + command : [sh, '-c', + '{ echo SYSTEMD_TEST_DATA=@0@; echo SYSTEMD_CATALOG_DIR=@1@; } >@OUTPUT@'.format( + project_source_root / 'test', + project_build_root / 'catalog')], + depends : catalogs, + build_by_default : true) + +test_cflags = ['-DTEST_CODE=1'] +# We intentionally do not do inline initializations with definitions for a +# bunch of _cleanup_ variables in tests, to ensure valgrind is triggered if we +# use the variable unexpectedly. This triggers a lot of maybe-uninitialized +# false positives when the combination of -O2 and -flto is used. Suppress them. +if '-O2' in c_args and '-flto=auto' in c_args + test_cflags += cc.first_supported_argument('-Wno-maybe-uninitialized') +endif + +############################################################ + executable_template = { 'include_directories' : includes, 'link_with' : libshared, @@ -2322,6 +2343,17 @@ executable_additional_kwargs = { 'dependencies' : userspace, } +test_template = executable_template + { + 'build_by_default' : want_tests != 'false', + 'install' : install_tests, + 'install_dir' : unittestsdir, +} + +test_additional_kwargs = { + 'c_args' : test_cflags, + 'link_depends' : runtest_env, +} + nss_template = { 'version' : '2', 'include_directories' : includes, @@ -2475,8 +2507,22 @@ alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc) ############################################################ +foreach test : simple_tests + executables += test_template + { 'sources' : [test] } +endforeach + +foreach test : libsystemd_tests + executables += test_template + test +endforeach + foreach dict : executables - name = dict.get('name') + name = dict.get('name', '') + if name == '' + name = fs.stem(dict.get('sources')[0]) + assert(name.split('-')[0] == 'test') + endif + + is_test = name.startswith('test-') build = true foreach cond : dict.get('conditions', []) @@ -2491,9 +2537,11 @@ foreach dict : executables kwargs = {} foreach key, val : dict - if key in ['name', 'dbus', 'public', 'conditions'] + if key in ['name', 'dbus', 'public', 'conditions', + 'type', 'suite', 'timeout', 'parallel'] continue endif + kwargs += { key : val } endforeach @@ -2501,6 +2549,13 @@ foreach dict : executables kwargs += { key : [ kwargs.get(key, []), val ]} endforeach + if is_test + kwargs += { 'install_dir' : kwargs.get('install_dir') / dict.get('type', '') } + foreach key, val : test_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ] } + endforeach + endif + exe = executable( name, kwargs : kwargs, @@ -2516,20 +2571,34 @@ foreach dict : executables public_programs += exe endif endif + + if is_test + type = dict.get('type', '') + suite = dict.get('suite', '') + if suite == '' + suite = fs.name(fs.parent(dict.get('sources')[0])) + if suite.startswith('sd-') + suite = 'libsystemd' + endif + endif + + if type == 'manual' + message('@0@/@1@ is a manual test'.format(suite, name)) + elif type == 'unsafe' and want_tests != 'unsafe' + message('@0@/@1@ is an unsafe test'.format(suite, name)) + elif dict.get('build_by_default') + test(name, exe, + env : test_env, + timeout : dict.get('timeout', 30), + suite : suite, + is_parallel : dict.get('parallel', true)) + endif + endif endforeach ############################################################ -# only static linking apart from libdl, to make sure that the -# module is linked to all libraries that it uses. -test_dlopen = executable( - 'test-dlopen', - test_dlopen_c, - include_directories : includes, - link_with : [libbasic], - dependencies : [libdl, - userspace], - build_by_default : want_tests != 'false') +test_dlopen = executables_by_name.get('test-dlopen') foreach dict : modules name = dict.get('name') @@ -2606,152 +2675,6 @@ endif subdir('rules.d') subdir('test') -runtest_env = custom_target( - 'systemd-runtest.env', - output : 'systemd-runtest.env', - command : [sh, '-c', - '{ echo SYSTEMD_TEST_DATA=@0@; echo SYSTEMD_CATALOG_DIR=@1@; } >@OUTPUT@'.format( - project_source_root / 'test', - project_build_root / 'catalog')], - depends : catalogs, - build_by_default : true) - -test_cflags = ['-DTEST_CODE=1'] -# We intentionally do not do inline initializations with definitions for a -# bunch of _cleanup_ variables in tests, to ensure valgrind is triggered if we -# use the variable unexpectedly. This triggers a lot of maybe-uninitialized -# false positives when the combination of -O2 and -flto is used. Suppress them. -if '-O2' in c_args and '-flto=auto' in c_args - test_cflags += cc.first_supported_argument('-Wno-maybe-uninitialized') -endif - -foreach test : simple_tests - tests += { 'sources' : [test] } -endforeach - -TESTS = {} -foreach test : tests - sources = test.get('sources') - condition = test.get('condition', '') - type = test.get('type', '') - base = test.get('base', {}) - deps = [ - base.get('dependencies', []), - test.get('dependencies', []), - ] - - name = fs.name(sources[0]) - if name.endswith('.cc') - deps += [versiondep] - else - deps += [userspace] - endif - name = fs.stem(name) - - suite = fs.name(fs.parent(sources[0])).replace('sd-', '') - - if condition != '' and conf.get(condition) == 0 - message('Not compiling @0@ because @1@ is not true'.format(name, condition)) - continue - endif - - exe = executable( - name, - sources, - include_directories : [base.get('includes', []), test.get('includes', includes)], - link_with : [base.get('link_with', []), test.get('link_with', libshared)], - dependencies : deps, - c_args : [test_cflags, test.get('c_args', [])], - build_by_default : want_tests != 'false', - install_rpath : pkglibdir, - install : install_tests, - install_dir : unittestsdir / type, - link_depends : runtest_env) - - if type == 'manual' - message('@0@ is a manual test'.format(name)) - elif type == 'unsafe' and want_tests != 'unsafe' - message('@0@ is an unsafe test'.format(name)) - elif want_tests != 'false' - test(name, exe, - env : test_env, - timeout : test.get('timeout', 30), - suite : suite, - is_parallel : test.get('parallel', true)) - endif - - TESTS += { name : exe } -endforeach - -exe = executable( - 'test-libsystemd-sym', - test_libsystemd_sym_c, - include_directories : includes, - link_with : [libsystemd], - dependencies : userspace, - build_by_default : want_tests != 'false', - install : install_tests, - install_dir : unittestsdir) -if want_tests != 'false' - test('test-libsystemd-sym', exe) -endif - -exe = executable( - 'test-libsystemd-static-sym', - test_libsystemd_sym_c, - include_directories : includes, - link_with : [install_libsystemd_static], - dependencies : [ - # threads is already included in dependencies on the library, - # but does not seem to get propagated. Add here as a work-around. - threads, - userspace, - ], - build_by_default : want_tests != 'false' and static_libsystemd != 'false', - install : install_tests and static_libsystemd != 'false', - install_dir : unittestsdir) -if want_tests != 'false' and static_libsystemd != 'false' - test('test-libsystemd-static-sym', exe) -endif - -exe = executable( - 'test-libudev-sym', - test_libudev_sym_c, - include_directories : libudev_includes, - c_args : ['-Wno-deprecated-declarations'] + test_cflags, - link_with : [libudev], - dependencies : userspace, - build_by_default : want_tests != 'false', - install : install_tests, - install_dir : unittestsdir) -if want_tests != 'false' - test('test-libudev-sym', exe) -endif - -exe = executable( - 'test-libudev-static-sym', - test_libudev_sym_c, - include_directories : libudev_includes, - c_args : ['-Wno-deprecated-declarations'] + test_cflags, - link_with : [install_libudev_static], - dependencies : userspace, - build_by_default : want_tests != 'false' and static_libudev != 'false', - install : install_tests and static_libudev != 'false', - install_dir : unittestsdir) -if want_tests != 'false' and static_libudev != 'false' - test('test-libudev-static-sym', exe) -endif - -if want_tests != 'false' - exe = TESTS.get('test-udev-rule-runner') - test('test-udev', - test_udev_py, - args : ['-v'], - env : ['UDEV_RULE_RUNNER=' + exe.full_path()], - depends : exe, - timeout : 180) -endif - ############################################################ foreach fuzzer : simple_fuzzers diff --git a/src/analyze/meson.build b/src/analyze/meson.build index 2bbcf26d1c..1a9b68f6d2 100644 --- a/src/analyze/meson.build +++ b/src/analyze/meson.build @@ -46,14 +46,10 @@ executables += [ 'dependencies' : libseccomp, 'install' : conf.get('ENABLE_ANALYZE') == 1, }, -] - -tests += [ - { + core_test_template + { 'sources' : files( 'test-verify.c', 'analyze-verify-util.c', ), - 'base' : test_core_base, }, ] diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index b687537031..7adcc178a6 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -23,17 +23,16 @@ if efi_arch != '' libshared, ], } + efi_test_template = test_template + efitest_base - tests += [ - { + executables += [ + efi_test_template + { 'sources' : files('test-bcd.c'), 'dependencies' : libzstd, - 'condition' : 'HAVE_ZSTD', - 'base' : efitest_base, + 'conditions' : ['HAVE_ZSTD'], }, - { + efi_test_template + { 'sources' : files('test-efi-string.c'), - 'base' : efitest_base, }, ] fuzzers += [ diff --git a/src/busctl/meson.build b/src/busctl/meson.build index 012d58c3a8..6b3a479b21 100644 --- a/src/busctl/meson.build +++ b/src/busctl/meson.build @@ -11,10 +11,7 @@ executables += [ 'public' : true, 'sources' : busctl_sources, }, -] - -tests += [ - { + test_template + { 'sources' : files( 'test-busctl-introspect.c', 'busctl-introspect.c', diff --git a/src/core/meson.build b/src/core/meson.build index 9f04a9e019..a99136be0f 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -203,9 +203,13 @@ meson.add_install_script(meson_make_symlink, ############################################################ -test_core_base = { - 'link_with' : [libcore, libshared], - 'includes' : core_includes, +core_test_template = test_template + { + 'link_with' : [ + libcore, + libshared, + ], + 'include_directories' : core_includes, + 'suite' : 'core', } fuzzers += [ diff --git a/src/coredump/meson.build b/src/coredump/meson.build index 89468b1fbc..ba313ce42e 100644 --- a/src/coredump/meson.build +++ b/src/coredump/meson.build @@ -33,15 +33,7 @@ executables += [ 'link_with' : common_link_with, 'dependencies' : common_dependencies, }, -] - -if conf.get('ENABLE_COREDUMP') == 1 and install_sysconfdir_samples - install_data('coredump.conf', - install_dir : pkgsysconfdir) -endif - -tests += [ - { + test_template + { 'sources' : files( 'test-coredump-vacuum.c', 'coredump-vacuum.c', @@ -49,3 +41,8 @@ tests += [ 'type' : 'manual', }, ] + +if conf.get('ENABLE_COREDUMP') == 1 and install_sysconfdir_samples + install_data('coredump.conf', + install_dir : pkgsysconfdir) +endif diff --git a/src/import/meson.build b/src/import/meson.build index 9d63e613cf..3f0acf8358 100644 --- a/src/import/meson.build +++ b/src/import/meson.build @@ -100,6 +100,15 @@ executables += [ 'link_with' : common_libs, 'dependencies' : common_deps, }, + test_template + { + 'sources' : files( + 'test-qcow2.c', + 'qcow2-util.c', + ), + 'dependencies' : libz, + 'conditions' : ['HAVE_ZLIB'], + 'type' : 'manual', + }, ] if conf.get('ENABLE_IMPORTD') == 1 @@ -114,15 +123,3 @@ if conf.get('ENABLE_IMPORTD') == 1 install_dir : libexecdir) # TODO: shouldn't this be in pkgdatadir? endif - -tests += [ - { - 'sources' : files( - 'test-qcow2.c', - 'qcow2-util.c', - ), - 'dependencies' : libz, - 'condition' : 'HAVE_ZLIB', - 'type' : 'manual', - }, -] diff --git a/src/journal/meson.build b/src/journal/meson.build index 0c99684770..90170599a7 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -41,6 +41,13 @@ else ] endif +journal_test_template = test_template + { + 'link_with' : [ + libjournal_core, + libshared, + ], +} + executables += [ libexec_template + { 'name' : 'systemd-journald', @@ -80,6 +87,43 @@ executables += [ threads, ], }, + journal_test_template + { + 'sources' : files('test-journal-append.c'), + 'type' : 'manual', + }, + journal_test_template + { + 'sources' : files('test-journal-config.c'), + 'dependencies' : [ + liblz4, + libselinux, + libxz, + ], + }, + journal_test_template + { + 'sources' : files('test-journal-flush.c'), + }, + journal_test_template + { + 'sources' : files('test-journal-interleaving.c'), + }, + journal_test_template + { + 'sources' : files('test-journal-stream.c'), + }, + journal_test_template + { + 'sources' : files('test-journal-syslog.c'), + 'dependencies' : [ + liblz4, + libselinux, + libxz, + threads, + ], + }, + journal_test_template + { + 'sources' : files('test-journal-verify.c'), + 'timeout' : 90, + }, + journal_test_template + { + 'sources' : files('test-journal.c'), + }, ] if install_sysconfdir_samples @@ -109,58 +153,6 @@ endif ############################################################ -test_journal_base = { - 'link_with' : [libjournal_core, libshared], -} - -tests += [ - { - 'sources' : files('test-journal-config.c'), - 'dependencies' : [ - liblz4, - libselinux, - libxz, - ], - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-flush.c'), - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-interleaving.c'), - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-stream.c'), - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-syslog.c'), - 'dependencies' : [ - liblz4, - libselinux, - libxz, - threads, - ], - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-verify.c'), - 'base' : test_journal_base, - 'timeout' : 90, - }, - { - 'sources' : files('test-journal.c'), - 'base' : test_journal_base, - }, - { - 'sources' : files('test-journal-append.c'), - 'base' : test_journal_base, - 'type' : 'manual', - }, -] - fuzzer_journald_base = { 'link_with' : [libjournal_core, libshared], 'dependencies' : [libselinux], diff --git a/src/libsystemd-network/meson.build b/src/libsystemd-network/meson.build index ac4a15b474..74041f6abd 100644 --- a/src/libsystemd-network/meson.build +++ b/src/libsystemd-network/meson.build @@ -39,56 +39,49 @@ libsystemd_network_includes = [includes, include_directories('.')] ############################################################ -test_libsystemd_network_base = { - 'link_with' : [libshared, libsystemd_network], +network_test_template = test_template + { + 'link_with' : [ + libshared, + libsystemd_network, + ], + 'suite' : 'network', } -tests += [ - { +executables += [ + network_test_template + { 'sources' : files('test-acd.c'), - 'base' : test_libsystemd_network_base, 'type' : 'manual', }, - { + network_test_template + { 'sources' : files('test-dhcp-client.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-dhcp-option.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-dhcp-server.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-dhcp6-client.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-ipv4ll-manual.c'), - 'base' : test_libsystemd_network_base, 'type' : 'manual', }, - { + network_test_template + { 'sources' : files('test-ipv4ll.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-lldp-rx.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-ndisc-ra.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-ndisc-rs.c'), - 'base' : test_libsystemd_network_base, }, - { + network_test_template + { 'sources' : files('test-sd-dhcp-lease.c'), - 'base' : test_libsystemd_network_base, }, ] diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 8da73a131e..bcf8e1faf8 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -154,7 +154,7 @@ simple_tests += files( 'sd-journal/test-mmap-cache.c', ) -tests += [ +libsystemd_tests += [ { 'sources' : files('sd-journal/test-journal-enum.c'), 'timeout' : 360, @@ -176,7 +176,7 @@ simple_tests += files( 'sd-netlink/test-netlink.c', ) -tests += [ +libsystemd_tests += [ { 'sources' : files('sd-bus/test-bus-address.c'), 'dependencies' : threads diff --git a/src/libudev/meson.build b/src/libudev/meson.build index 3787602a6b..7f999197af 100644 --- a/src/libudev/meson.build +++ b/src/libudev/meson.build @@ -42,15 +42,3 @@ libudev_pc = custom_target( install : pkgconfiglibdir != 'no', install_tag : 'devel', install_dir : pkgconfiglibdir) - -############################################################ - -tests += [ - { - 'sources' : files('test-libudev.c'), - 'link_with' : [ - libshared, - libudev_basic, - ], - }, -] diff --git a/src/locale/meson.build b/src/locale/meson.build index e7e059a0ab..3d3aa589c3 100644 --- a/src/locale/meson.build +++ b/src/locale/meson.build @@ -33,6 +33,14 @@ executables += [ 'conditions' : ['ENABLE_LOCALED'], 'sources' : files('localectl.c'), }, + test_template + { + 'sources' : files( + 'test-localed-util.c', + 'localed-util.c', + 'xkbcommon-util.c', + ), + 'dependencies' : libxkbcommon_deps, + }, ] # If you know a way that allows the same variables to be used @@ -52,14 +60,3 @@ if conf.get('ENABLE_LOCALED') == 1 'language-fallback-map', install_dir : pkgdatadir) endif - -tests += [ - { - 'sources' : files( - 'test-localed-util.c', - 'localed-util.c', - 'xkbcommon-util.c', - ), - 'dependencies' : libxkbcommon_deps, - }, -] diff --git a/src/login/meson.build b/src/login/meson.build index c641cc700e..9804a36ce1 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -82,8 +82,28 @@ executables += [ 'conditions' : ['ENABLE_LOGIND'], 'sources' : files('user-runtime-dir.c'), }, + test_template + { + 'sources' : files('test-inhibit.c'), + 'type' : 'manual', + }, + test_template + { + 'sources' : files('test-login-tables.c'), + 'link_with' : [ + liblogind_core, + libshared, + ], + 'dependencies' : threads, + }, + test_template + { + 'sources' : files('test-session-properties.c'), + 'type' : 'manual', + }, ] +simple_tests += files( + 'test-login-shared.c' +) + modules += [ pam_template + { 'name' : 'pam_systemd', @@ -122,28 +142,3 @@ if enable_logind install_data('org.freedesktop.login1.policy', install_dir : polkitpolicydir) endif - -############################################################ - -simple_tests += files( - 'test-login-shared.c' -) - -tests += [ - { - 'sources' : files('test-inhibit.c'), - 'type' : 'manual', - }, - { - 'sources' : files('test-login-tables.c'), - 'link_with' : [ - liblogind_core, - libshared, - ], - 'dependencies' : threads, - }, - { - 'sources' : files('test-session-properties.c'), - 'type' : 'manual', - }, -] diff --git a/src/machine/meson.build b/src/machine/meson.build index 2adc1bd37b..b3a1ffce8f 100644 --- a/src/machine/meson.build +++ b/src/machine/meson.build @@ -41,6 +41,14 @@ executables += [ threads, ], }, + test_template + { + 'sources' : files('test-machine-tables.c'), + 'link_with': [ + libmachine_core, + libshared + ], + 'dependencies': threads, + }, ] if conf.get('ENABLE_MACHINED') == 1 @@ -51,14 +59,3 @@ if conf.get('ENABLE_MACHINED') == 1 install_data('org.freedesktop.machine1.policy', install_dir : polkitpolicydir) endif - -tests += [ - { - 'sources' : files('test-machine-tables.c'), - 'link_with': [ - libmachine_core, - libshared - ], - 'dependencies': threads, - }, -] diff --git a/src/network/meson.build b/src/network/meson.build index dc33f85a96..c5607a9b31 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -150,6 +150,14 @@ libnetworkd_core = static_library( link_with : networkd_link_with, build_by_default : false) +network_test_template = test_template + { + 'link_with' : [ + libnetworkd_core, + libsystemd_network, + ], + 'include_directories' : network_includes, +} + executables += [ libexec_template + { 'name' : 'systemd-networkd', @@ -187,6 +195,32 @@ executables += [ 'sources' : network_generator_sources, 'link_with' : networkd_link_with, }, + test_template + { + 'sources' : files( + 'generator/test-network-generator.c', + 'generator/network-generator.c', + ), + 'suite' : 'network', + }, + network_test_template + { + 'sources' : files('test-network-tables.c'), + 'dependencies' : threads, + }, + network_test_template + { + 'sources' : files('test-network.c'), + 'dependencies' : threads, + }, + network_test_template + { + 'sources' : files('test-networkd-address.c'), + 'dependencies' : libatomic, + }, + network_test_template + { + 'sources' : files('test-networkd-conf.c'), + 'dependencies' : libatomic, + }, + network_test_template + { + 'sources' : files('test-networkd-util.c'), + }, ] if conf.get('ENABLE_NETWORKD') == 1 @@ -227,41 +261,3 @@ fuzzers += [ 'base' : fuzzer_network_base, }, ] - -test_network_base = { - 'link_with' : [libnetworkd_core, libsystemd_network], - 'includes' : network_includes, -} - -tests += [ - { - 'sources' : files( - 'generator/test-network-generator.c', - 'generator/network-generator.c', - ) - }, - { - 'sources' : files('test-network-tables.c'), - 'dependencies' : threads, - 'base' : test_network_base, - }, - { - 'sources' : files('test-network.c'), - 'dependencies' : threads, - 'base' : test_network_base, - }, - { - 'sources' : files('test-networkd-address.c'), - 'dependencies' : libatomic, - 'base' : test_network_base, - }, - { - 'sources' : files('test-networkd-conf.c'), - 'dependencies' : libatomic, - 'base' : test_network_base, - }, - { - 'sources' : files('test-networkd-util.c'), - 'base' : test_network_base, - }, -] diff --git a/src/nspawn/meson.build b/src/nspawn/meson.build index 024a19a66b..b6628c6751 100644 --- a/src/nspawn/meson.build +++ b/src/nspawn/meson.build @@ -40,6 +40,12 @@ nspawn_libs = [ libshared, ] +nspawn_common_template = { + 'link_with' : nspawn_libs, + 'dependencies' : libseccomp, +} +nspawn_test_template = test_template + nspawn_common_template + executables += [ executable_template + { 'name' : 'systemd-nspawn', @@ -51,33 +57,15 @@ executables += [ libseccomp, ], }, -] - -############################################################ - -tests += [ - { + nspawn_test_template + { 'sources' : files('test-nspawn-tables.c'), - 'link_with' : [ - libnspawn_core, - libshared, - ], - 'dependencies' : libseccomp, }, - { + nspawn_test_template + { 'sources' : files('test-nspawn-util.c'), - 'link_with' : [ - libnspawn_core, - libshared, - ], - 'dependencies' : libseccomp, }, - { + test_template + { 'sources' : files('test-patch-uid.c'), - 'link_with' : [ - libnspawn_core, - libshared, - ], + 'link_with' : nspawn_libs, 'dependencies' : libacl, 'type' : 'manual', }, diff --git a/src/oom/meson.build b/src/oom/meson.build index b475fbf12c..d2f4c076e3 100644 --- a/src/oom/meson.build +++ b/src/oom/meson.build @@ -21,6 +21,13 @@ executables += [ 'conditions' : ['ENABLE_OOMD'], 'sources' : files('oomctl.c'), }, + test_template + { + 'sources' : files( + 'test-oomd-util.c', + 'oomd-util.c', + ), + 'dependencies' : libatomic, + }, ] if conf.get('ENABLE_OOMD') == 1 @@ -35,13 +42,3 @@ if conf.get('ENABLE_OOMD') == 1 install_dir : pkgsysconfdir) endif endif - -tests += [ - { - 'sources' : files( - 'test-oomd-util.c', - 'oomd-util.c', - ), - 'dependencies' : libatomic, - }, -] diff --git a/src/resolve/meson.build b/src/resolve/meson.build index 4cc2459b21..e8881fb3b3 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -123,6 +123,18 @@ link_with = [ libsystemd_resolve_core, ] +resolve_common_template = { + 'link_with' : [ + libshared, + libsystemd_resolve_core, + ], + 'dependencies' : [ + lib_openssl_or_gcrypt, + libm, + ], +} +resolve_test_template = test_template + resolve_common_template + executables += [ libexec_template + { 'name' : 'systemd-resolved', @@ -147,6 +159,42 @@ executables += [ threads, ], }, + resolve_test_template + { + 'sources' : files('test-resolve-tables.c'), + }, + resolve_test_template + { + 'sources' : files('test-dns-packet.c'), + }, + resolve_test_template + { + 'sources' : files( + 'test-resolved-etc-hosts.c', + 'resolved-etc-hosts.c', + ), + }, + resolve_test_template + { + 'sources' : files('test-resolved-packet.c'), + }, + resolve_test_template + { + 'sources' : files('test-dnssec.c'), + 'conditions' : ['HAVE_OPENSSL_OR_GCRYPT'], + }, + resolve_test_template + { + 'sources' : files('test-dnssec-complex.c'), + 'type' : 'manual', + }, + test_template + { + 'sources' : [ + files('test-resolved-stream.c'), + basic_dns_sources, + systemd_resolved_sources, + ], + 'dependencies' : [ + lib_openssl_or_gcrypt, + libm, + systemd_resolved_dependencies, + ], + 'include_directories' : resolve_includes, + }, ] if conf.get('ENABLE_RESOLVE') == 1 @@ -178,56 +226,6 @@ custom_target( ############################################################ -test_resolve_base = { - 'link_with' : [libsystemd_resolve_core, libshared], - 'dependencies' : [lib_openssl_or_gcrypt, libm], -} - -tests += [ - { - 'sources' : files('test-resolve-tables.c'), - 'base' : test_resolve_base, - }, - { - 'sources' : files('test-dns-packet.c'), - 'base' : test_resolve_base, - }, - { - 'sources' : files( - 'test-resolved-etc-hosts.c', - 'resolved-etc-hosts.c', - ), - 'base' : test_resolve_base, - }, - { - 'sources' : files('test-resolved-packet.c'), - 'base' : test_resolve_base, - }, - { - 'sources' : files('test-dnssec.c'), - 'base' : test_resolve_base, - 'condition' : 'HAVE_OPENSSL_OR_GCRYPT', - }, - { - 'sources' : files('test-dnssec-complex.c'), - 'base' : test_resolve_base, - 'type' : 'manual', - }, - { - 'sources' : [ - files('test-resolved-stream.c'), - basic_dns_sources, - systemd_resolved_sources, - ], - 'dependencies' : [ - lib_openssl_or_gcrypt, - libm, - systemd_resolved_dependencies, - ], - 'includes' : resolve_includes, - }, -] - fuzzer_resolve_base = { 'link_with' : [libsystemd_resolve_core, libshared], 'dependencies' : [lib_openssl_or_gcrypt, libm], diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index 0b16c431b4..219f9fd308 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -28,10 +28,7 @@ executables += [ 'build_by_default' : have_standalone_binaries, 'install' : have_standalone_binaries, }, -] - -tests += [ - { + test_template + { 'sources' : files( 'test-umount.c', 'detach-swap.c', diff --git a/src/test/meson.build b/src/test/meson.build index 0d4dfa7f7e..0f7dc8f9d2 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -39,8 +39,6 @@ test_libudev_sym_c = custom_target( capture : true, build_by_default : want_tests != 'false') -test_dlopen_c = files('test-dlopen.c') - ############################################################ simple_tests += files( @@ -195,49 +193,49 @@ common_test_dependencies = [ threads, ] -tests += [ - { +executables += [ + test_template + { 'sources' : files('test-acl-util.c'), - 'condition' : 'HAVE_ACL', + 'conditions' : ['HAVE_ACL'], }, - { + test_template + { 'sources' : files('test-af-list.c') + generated_gperf_headers, }, - { + test_template + { 'sources' : files('test-arphrd-util.c') + generated_gperf_headers, }, - { + test_template + { 'sources' : files('test-ask-password-api.c'), 'type' : 'manual', }, - { + test_template + { 'sources' : files('test-async.c'), 'timeout' : 120, }, - { + test_template + { 'sources' : files('test-boot-timestamps.c'), - 'condition' : 'ENABLE_EFI', + 'conditions' : ['ENABLE_EFI'], }, - { + test_template + { 'sources' : files('test-btrfs.c'), 'type' : 'manual', }, - { + test_template + { 'sources' : files('test-cap-list.c') + generated_gperf_headers, 'dependencies' : libcap, }, - { + test_template + { 'sources' : files('test-capability.c'), 'dependencies' : libcap, }, - { + test_template + { 'sources' : files('test-chase-manual.c'), 'type' : 'manual', }, - { + test_template + { 'sources' : files('test-compress-benchmark.c'), 'link_with' : [ libbasic_compress, @@ -245,144 +243,152 @@ tests += [ ], 'timeout' : 90, }, - { + test_template + { 'sources' : files('test-compress.c'), 'link_with' : [ libbasic_compress, libshared, ], }, - { + test_template + { 'sources' : files('test-cryptolib.c'), - 'link_with' : libshared, 'dependencies' : lib_openssl_or_gcrypt, - 'condition' : 'HAVE_OPENSSL_OR_GCRYPT', + 'conditions' : ['HAVE_OPENSSL_OR_GCRYPT'], }, - { + test_template + { 'sources' : files('test-dlopen-so.c'), 'dependencies' : libp11kit_cflags }, - { + test_template + { + # only static linking apart from libdl, to make sure that the + # module is linked to all libraries that it uses. + 'sources' : files('test-dlopen.c'), + 'link_with' : libbasic, + 'dependencies' : libdl, + 'install' : false, + 'type' : 'manual', + }, + test_template + { 'sources' : files('test-errno-list.c') + generated_gperf_headers, }, - { + test_template + { 'sources' : files('test-fd-util.c'), 'dependencies' : libseccomp, }, - { + test_template + { 'sources' : files( - 'test-hashmap.c', - 'test-hashmap-plain.c', - ) + [ - test_hashmap_ordered_c, - ], + 'test-hashmap.c', + 'test-hashmap-plain.c', + ) + [ + test_hashmap_ordered_c, + ], 'timeout' : 180, }, - { + test_template + { 'sources' : files('test-ip-protocol-list.c') + shared_generated_gperf_headers, }, - { + test_template + { 'sources' : files('test-ipcrm.c'), 'type' : 'unsafe', }, - { + test_template + { 'sources' : files('test-json.c'), 'dependencies' : libm, }, - { + test_template + { 'sources' : files('test-libcrypt-util.c'), 'dependencies' : libcrypt, 'timeout' : 120, }, - { + test_template + { 'sources' : files('test-libmount.c'), 'dependencies' : [ libmount, threads, ], }, - { + test_template + { 'sources' : files('test-loopback.c'), 'dependencies' : common_test_dependencies, }, - { + test_template + { 'sources' : files('test-math-util.c'), 'dependencies' : libm, }, - { + test_template + { 'sources' : files('test-mempress.c'), 'dependencies' : threads, }, - { + test_template + { 'sources' : files('test-mount-util.c'), 'dependencies' : libmount, }, - { + test_template + { 'sources' : files('test-netlink-manual.c'), 'dependencies' : libkmod, - 'condition' : 'HAVE_KMOD', + 'conditions' : ['HAVE_KMOD'], 'type' : 'manual', }, - { + test_template + { 'sources' : files('test-nscd-flush.c'), - 'condition' : 'ENABLE_NSCD', + 'conditions' : ['ENABLE_NSCD'], 'type' : 'manual', }, - { + test_template + { 'sources' : files( 'test-nss-hosts.c', 'nss-test-util.c', ), 'dependencies' : libdl, - 'condition' : 'ENABLE_NSS', + 'conditions' : ['ENABLE_NSS'], 'timeout' : 120, }, - { + test_template + { 'sources' : files( 'test-nss-users.c', 'nss-test-util.c', ), 'dependencies' : libdl, - 'condition' : 'ENABLE_NSS', + 'conditions' : ['ENABLE_NSS'], }, - { + test_template + { 'sources' : files('test-parse-util.c'), 'dependencies' : libm, }, - { + test_template + { 'sources' : files('test-process-util.c'), 'dependencies' : threads, }, - { + test_template + { 'sources' : files('test-qrcode-util.c'), 'dependencies' : libdl, }, - { + test_template + { 'sources' : files('test-random-util.c'), 'dependencies' : libm, 'timeout' : 120, }, - { + test_template + { 'sources' : files('test-sbat.c'), - 'condition' : 'ENABLE_BOOTLOADER', + 'conditions' : ['ENABLE_BOOTLOADER'], 'c_args' : '-I@0@'.format(efi_config_h_dir), }, - { + test_template + { 'sources' : files('test-seccomp.c'), 'dependencies' : libseccomp, - 'condition' : 'HAVE_SECCOMP', + 'conditions' : ['HAVE_SECCOMP'], }, - { + test_template + { 'sources' : files('test-set-disable-mempool.c'), 'dependencies' : threads, }, - { + test_template + { 'sources' : files('test-sizeof.c'), 'link_with' : libbasic, }, - { + test_template + { 'sources' : files('test-tables.c'), 'link_with' : [ libcore, @@ -399,175 +405,190 @@ tests += [ libxz, threads, ], - 'includes' : [ + 'include_directories' : [ core_includes, journal_includes, udev_includes, ], }, - { + test_template + { 'sources' : files('test-time-util.c'), 'timeout' : 120, }, - { + test_template + { 'sources' : files('test-utmp.c'), - 'condition' : 'ENABLE_UTMP', + 'conditions' : ['ENABLE_UTMP'], }, - { + test_template + { 'sources' : files('test-varlink.c'), 'dependencies' : threads, }, - { + test_template + { 'sources' : files('test-watchdog.c'), 'type' : 'unsafe', }, + # Symbol tests + test_template + { + 'name' : 'test-libsystemd-sym', + 'sources' : test_libsystemd_sym_c, + 'link_with' : libsystemd, + 'suite' : 'libsystemd', + }, + test_template + { + 'name' : 'test-libsystemd-static-sym', + 'sources' : test_libsystemd_sym_c, + 'link_with' : install_libsystemd_static, + 'build_by_default' : want_tests != 'false' and static_libsystemd != 'false', + 'install' : install_tests and static_libsystemd != 'false', + 'suite' : 'libsystemd', + }, + test_template + { + 'name' : 'test-libudev-sym', + 'sources' : test_libudev_sym_c, + 'include_directories' : libudev_includes, + 'c_args' : ['-Wno-deprecated-declarations'] + test_cflags, + 'link_with' : libudev, + 'suite' : 'libudev', + }, + test_template + { + 'name' : 'test-libudev-static-sym', + 'sources' : test_libudev_sym_c, + 'include_directories' : libudev_includes, + 'c_args' : ['-Wno-deprecated-declarations'] + test_cflags, + 'link_with' : install_libudev_static, + 'build_by_default' : want_tests != 'false' and static_libudev != 'false', + 'install' : install_tests and static_libudev != 'false', + 'suite' : 'libudev', + }, # Tests that link to libcore, i.e. tests for pid1 code. - { + core_test_template + { 'sources' : files('test-bpf-devices.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-bpf-firewall.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-bpf-foreign-programs.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-bpf-lsm.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-cgroup-cpu.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-cgroup-mask.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-cgroup-unit-default.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-chown-rec.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-core-unit.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-emergency-action.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-engine.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-execute.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, 'timeout' : 360, }, - { + core_test_template + { 'sources' : files('test-install.c'), - 'base' : test_core_base, 'type' : 'manual', }, - { + core_test_template + { 'sources' : files('test-job-type.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-load-fragment.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-loop-block.c'), 'dependencies' : [threads, libblkid], - 'base' : test_core_base, 'parallel' : false, }, - { + core_test_template + { 'sources' : files('test-manager.c'), - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-namespace.c'), 'dependencies' : [ libblkid, threads, ], - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-ns.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, 'type' : 'manual', }, - { + core_test_template + { 'sources' : files('test-path.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, 'timeout' : 120, }, - { + core_test_template + { 'sources' : files('test-sched-prio.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-socket-bind.c'), 'dependencies' : libdl, - 'condition' : 'BPF_FRAMEWORK', - 'base' : test_core_base, + 'conditions' : ['BPF_FRAMEWORK'], }, - { + core_test_template + { 'sources' : files('test-unit-name.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-unit-serialize.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, - { + core_test_template + { 'sources' : files('test-watch-pid.c'), 'dependencies' : common_test_dependencies, - 'base' : test_core_base, }, # Tests from other directories that have link_with deps that were not defined earlier - { + test_template + { 'sources' : files('../libsystemd/sd-bus/test-bus-error.c'), 'link_with' : [ libshared_static, libsystemd_static, ], }, - { + test_template + { 'sources' : files('../libsystemd/sd-device/test-sd-device-thread.c'), 'link_with' : libsystemd, 'dependencies' : threads, }, - { + test_template + { 'sources' : files('../libudev/test-udev-device-thread.c'), 'link_with' : libudev, 'dependencies' : threads, }, + test_template + { + 'sources' : files('../libudev/test-libudev.c'), + 'link_with' : [ + libshared, + libudev_basic, + ], + }, ] diff --git a/src/timesync/meson.build b/src/timesync/meson.build index 54ae6a9e73..27367e311e 100644 --- a/src/timesync/meson.build +++ b/src/timesync/meson.build @@ -50,6 +50,14 @@ executables += [ 'sources' : files('wait-sync.c'), 'link_with' : libtimesyncd_core, }, + test_template + { + 'sources' : files('test-timesync.c'), + 'link_with' : [ + libshared, + libtimesyncd_core, + ], + 'dependencies' : libm, + }, ] custom_target( @@ -70,16 +78,3 @@ if conf.get('ENABLE_TIMESYNCD') == 1 install_data('org.freedesktop.timesync1.policy', install_dir : polkitpolicydir) endif - -############################################################ - -tests += [ - { - 'sources' : files('test-timesync.c'), - 'link_with' : [ - libshared, - libtimesyncd_core, - ], - 'dependencies' : libm, - }, -] diff --git a/src/tmpfiles/meson.build b/src/tmpfiles/meson.build index 892c09b168..8a24a21a27 100644 --- a/src/tmpfiles/meson.build +++ b/src/tmpfiles/meson.build @@ -29,10 +29,7 @@ executables += [ 'build_by_default' : have_standalone_binaries, 'install' : have_standalone_binaries, }, -] - -tests += [ - { + test_template + { 'sources' : files( 'test-offline-passwd.c', 'offline-passwd.c', diff --git a/src/udev/meson.build b/src/udev/meson.build index 9807648592..b99e313722 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -116,6 +116,14 @@ libudevd_core = static_library( userspace], build_by_default : false) +udev_dependencies = [ + libacl, + libblkid, + libidn, + libkmod, + threads, +] + udev_plugin_template = executable_template + { 'public' : true, 'link_with' : udev_link_with, @@ -123,19 +131,25 @@ udev_plugin_template = executable_template + { 'install_dir' : udevlibexecdir, } +udev_common_template = { + 'link_with' : [ + libshared, + libudevd_core, + ], + 'dependencies' : [ + libacl, + threads, + ], +} +udev_test_template = test_template + udev_common_template + executables += [ executable_template + { 'name' : 'udevadm', 'public' : true, 'sources' : udevadm_sources, 'link_with' : [libudevd_core], - 'dependencies' : [ - libacl, - libblkid, - libidn, - libkmod, - threads, - ], + 'dependencies' : udev_dependencies, 'install_rpath' : udev_rpath, }, udev_plugin_template + { @@ -180,6 +194,38 @@ executables += [ 'name' : 'v4l_id', 'sources' : files('v4l_id/v4l_id.c'), }, + test_template + { + 'sources' : files( + 'fido_id/test-fido-id-desc.c', + 'fido_id/fido_id_desc.c', + ), + 'suite' : 'udev', + }, + udev_test_template + { + 'sources' : files('test-udev-builtin.c'), + }, + udev_test_template + { + 'sources' : files('test-udev-format.c'), + }, + udev_test_template + { + 'sources' : files('test-udev-manager.c'), + }, + udev_test_template + { + 'sources' : files('test-udev-node.c'), + }, + udev_test_template + { + 'sources' : files('test-udev-rule-runner.c'), + 'dependencies' : udev_dependencies + [ + libselinux, + ], + 'type' : 'manual', + }, + udev_test_template + { + 'sources' : files('test-udev-rules.c'), + }, + udev_test_template + { + 'sources' : files('test-udev-spawn.c'), + }, ] meson.add_install_script(meson_make_symlink, @@ -233,58 +279,3 @@ fuzzers += [ ), }, ] - -test_libudev_base = { - 'link_with' : [libudevd_core, libshared], - 'dependencies' : [threads, libacl], -} - -tests += [ - { - 'sources' : files( - 'fido_id/test-fido-id-desc.c', - 'fido_id/fido_id_desc.c', - ), - }, - { - 'sources' : files('test-udev-builtin.c'), - 'base' : test_libudev_base, - }, - { - 'sources' : files('test-udev-format.c'), - 'base' : test_libudev_base, - }, - { - 'sources' : files('test-udev-manager.c'), - 'base' : test_libudev_base, - }, - { - 'sources' : files('test-udev-node.c'), - 'base' : test_libudev_base, - }, - { - 'sources' : files('test-udev-rule-runner.c'), - 'link_with' : [ - libshared, - libudevd_core, - ], - 'dependencies' : [ - libacl, - libblkid, - libkmod, - librt, - libselinux, - threads, - ], - 'includes' : udev_includes, - 'type' : 'manual', - }, - { - 'sources' : files('test-udev-rules.c'), - 'base' : test_libudev_base, - }, - { - 'sources' : files('test-udev-spawn.c'), - 'base' : test_libudev_base, - }, -] diff --git a/src/xdg-autostart-generator/meson.build b/src/xdg-autostart-generator/meson.build index 8eea9322ae..238dde8fd0 100644 --- a/src/xdg-autostart-generator/meson.build +++ b/src/xdg-autostart-generator/meson.build @@ -17,10 +17,7 @@ executables += [ 'conditions' : ['ENABLE_XDG_AUTOSTART'], 'sources' : files('xdg-autostart-condition.c'), }, -] - -tests += [ - { + test_template + { 'sources' : files( 'test-xdg-autostart.c', 'xdg-autostart-service.c', diff --git a/test/meson.build b/test/meson.build index 99f50828a3..a5bcc128cc 100644 --- a/test/meson.build +++ b/test/meson.build @@ -229,7 +229,15 @@ endif sys_script_py = files('sys-script.py') test_udev_py = files('test-udev.py') - +if want_tests != 'false' + exe = executables_by_name.get('test-udev-rule-runner') + test('test-udev', + test_udev_py, + args : ['-v'], + env : ['UDEV_RULE_RUNNER=' + exe.full_path()], + depends : exe, + timeout : 180) +endif if install_tests install_data( sys_script_py, From cbc55c4cce7e8a076dbeb5bc7a9660e20338b7e6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 27 Jun 2023 01:07:25 +0900 Subject: [PATCH 7/8] meson: also merge declarations of fuzzers with other executables --- meson.build | 151 ++++++++++++------------ src/boot/efi/meson.build | 12 +- src/core/meson.build | 33 +++--- src/journal-remote/meson.build | 21 ++-- src/journal/meson.build | 96 +++++++-------- src/libsystemd-network/meson.build | 32 ++--- src/network/meson.build | 39 +++--- src/nspawn/meson.build | 15 +-- src/resolve/meson.build | 38 ++---- src/systemctl/meson.build | 19 ++- src/udev/meson.build | 48 ++++---- src/xdg-autostart-generator/meson.build | 5 +- test/fuzz/meson.build | 56 ++++----- test/meson.build | 4 - 14 files changed, 246 insertions(+), 323 deletions(-) diff --git a/meson.build b/meson.build index 320302f15d..cf217c1bf0 100644 --- a/meson.build +++ b/meson.build @@ -2174,12 +2174,12 @@ man_page_depends = [] simple_tests = [] libsystemd_tests = [] -fuzzers = [] simple_fuzzers = [] catalogs = [] modules = [] # nss, pam, and other plugins executables = [] executables_by_name = {} +fuzzer_exes = [] # binaries that have --help and are intended for use by humans, # usually, but not always, installed in /bin. @@ -2354,6 +2354,29 @@ test_additional_kwargs = { 'link_depends' : runtest_env, } +fuzz_template = executable_template + { + 'build_by_default' : fuzzer_build, + 'install' : false, +} + +if want_ossfuzz or (want_libfuzzer and fuzzing_engine.found()) + fuzz_additional_kwargs = { + 'dependencies' : fuzzing_engine, + } +elif want_libfuzzer and not fuzzing_engine.found() + fuzz_additional_kwargs = { + 'link_args' : ['-fsanitize=fuzzer'], + } +else + fuzz_additional_kwargs = { + 'sources' : files('src/fuzz/fuzz-main.c'), + } +endif +fuzz_additional_kwargs += { + 'include_directories' : include_directories('src/fuzz'), + 'c_args' : test_cflags, +} + nss_template = { 'version' : '2', 'include_directories' : includes, @@ -2502,6 +2525,7 @@ subdir('src/systemd') subdir('src/test') subdir('src/fuzz') subdir('src/ukify/test') # needs to be last for test_env variable +subdir('test/fuzz') alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc) @@ -2515,14 +2539,19 @@ foreach test : libsystemd_tests executables += test_template + test endforeach +foreach fuzzer : simple_fuzzers + executables += fuzz_template + { 'sources' : [fuzzer] } +endforeach + foreach dict : executables name = dict.get('name', '') if name == '' name = fs.stem(dict.get('sources')[0]) - assert(name.split('-')[0] == 'test') + assert(name.split('-')[0] in ['test', 'fuzz']) endif is_test = name.startswith('test-') + is_fuzz = name.startswith('fuzz-') build = true foreach cond : dict.get('conditions', []) @@ -2556,6 +2585,12 @@ foreach dict : executables endforeach endif + if is_fuzz + foreach key, val : fuzz_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ] } + endforeach + endif + exe = executable( name, kwargs : kwargs, @@ -2594,8 +2629,33 @@ foreach dict : executables is_parallel : dict.get('parallel', true)) endif endif + + if is_fuzz + fuzzer_exes += exe + + if want_tests != 'false' + # Run the fuzz regression tests without any sanitizers enabled. + # Additional invocations with sanitizers may be added below. + fuzz_ins = fuzz_regression_tests.get(name, {}) + foreach directive : fuzz_ins.get('directives', []) + test('@0@_@1@'.format(name, fs.name(directive.full_path())), + exe, + suite : 'fuzz', + args : directive.full_path(), + depends : directive) + endforeach + foreach file : fuzz_ins.get('files', []) + test('@0@_@1@'.format(name, fs.name(file)), + exe, + suite : 'fuzz', + args : file) + endforeach + endif + endif endforeach +alias_target('fuzzers', fuzzer_exes) + ############################################################ test_dlopen = executables_by_name.get('test-dlopen') @@ -2677,71 +2737,6 @@ subdir('test') ############################################################ -foreach fuzzer : simple_fuzzers - fuzzers += { 'sources' : [fuzzer] } -endforeach - -fuzzer_exes = [] - -foreach fuzzer : fuzzers - sources = fuzzer.get('sources') - base = fuzzer.get('base', {}) - dependencies = [base.get('dependencies', []), fuzzer.get('dependencies', [])] - link_args = [] - - if want_ossfuzz - dependencies += fuzzing_engine - elif want_libfuzzer - if fuzzing_engine.found() - dependencies += fuzzing_engine - else - link_args += ['-fsanitize=fuzzer'] - endif - else - sources += files('src/fuzz/fuzz-main.c') - endif - sources += fuzz_generated_directives - - name = fs.stem(sources[0]) - - exe = executable( - name, - sources, - include_directories : [ - base.get('includes', []), - fuzzer.get('includes', includes), - include_directories('src/fuzz'), - ], - link_with : [base.get('link_with', []), fuzzer.get('link_with', libshared)], - dependencies : [ - dependencies, - userspace, - ], - c_args : [test_cflags, fuzzer.get('c_args', [])], - link_args: link_args, - install : false, - build_by_default : fuzzer_build) - fuzzer_exes += exe - - 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 tuple : fuzz_regression_tests[name] - fuzz_dir = tuple[0] - fuzz_in = tuple[1] - test('@0@_@1@'.format(name, fuzz_in), - exe, - suite : 'fuzz', - args : [fuzz_dir != '' ? project_source_root / fuzz_dir / name / fuzz_in - : fuzz_generated_in_dir / '@0@_@1@'.format(name, fuzz_in)]) - endforeach - endif -endforeach - -alias_target('fuzzers', fuzzer_exes) - -############################################################ - subdir('docs/sysvinit') subdir('docs/var-log') subdir('hwdb.d') @@ -2841,24 +2836,28 @@ foreach tuple : fuzz_sanitizers exe = custom_target( name, output : name, - depends : [build] + fuzz_generated_directives, + depends : build, command : [ln, '-fs', build.full_path() / fuzzer, '@OUTPUT@'], build_by_default : true) - foreach tuple : fuzz_ins - fuzz_dir = tuple[0] - fuzz_in = tuple[1] - - test('@0@_@1@_@2@'.format(fuzzer, fuzz_in, sanitizer), + foreach directive : fuzz_ins.get('directives', []) + test('@0@_@1@_@2@'.format(fuzzer, fs.name(directive.full_path()), sanitizer), env, suite : 'fuzz+san', env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], timeout : 60, - args : [exe.full_path(), - fuzz_dir != '' ? project_source_root / fuzz_dir / fuzzer / fuzz_in - : fuzz_generated_in_dir / '@0@_@1@'.format(fuzzer, fuzz_in)]) + args : [exe.full_path(), directive.full_path()], + depends : directive) + endforeach + foreach file : fuzz_ins.get('files', []) + test('@0@_@1@_@2@'.format(fuzzer, fs.name(file), sanitizer), + env, + suite : 'fuzz+san', + env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'], + timeout : 60, + args : [exe.full_path(), file]) endforeach endforeach endif diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index 7adcc178a6..05997744df 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -24,6 +24,7 @@ if efi_arch != '' ], } efi_test_template = test_template + efitest_base + efi_fuzz_template = fuzz_template + efitest_base executables += [ efi_test_template + { @@ -34,19 +35,14 @@ if efi_arch != '' efi_test_template + { 'sources' : files('test-efi-string.c'), }, - ] - fuzzers += [ - { + efi_fuzz_template + { 'sources' : files('fuzz-bcd.c'), - 'base' : efitest_base, }, - { + efi_fuzz_template + { 'sources' : files('fuzz-efi-string.c'), - 'base' : efitest_base, }, - { + efi_fuzz_template + { 'sources' : files('fuzz-efi-printf.c'), - 'base' : efitest_base, }, ] endif diff --git a/src/core/meson.build b/src/core/meson.build index a99136be0f..395342d754 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -153,6 +153,21 @@ executables += [ ], 'dependencies' : libseccomp, }, + fuzz_template + { + 'sources' : files('fuzz-unit-file.c'), + 'link_with' : [ + libcore, + libshared + ], + 'dependencies' : libmount, + }, + fuzz_template + { + 'sources' : files('fuzz-manager-serialize.c'), + 'link_with' : [ + libcore, + libshared + ], + }, ] in_files = [['system.conf', pkgsysconfdir], @@ -211,21 +226,3 @@ core_test_template = test_template + { 'include_directories' : core_includes, 'suite' : 'core', } - -fuzzers += [ - { - 'sources' : files('fuzz-unit-file.c'), - 'link_with' : [ - libcore, - libshared - ], - 'dependencies' : libmount, - }, - { - 'sources' : files('fuzz-manager-serialize.c'), - 'link_with' : [ - libcore, - libshared - ], - }, -] diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 89419f1de1..e5a37466db 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -81,6 +81,14 @@ executables += [ 'sources' : systemd_journal_gatewayd_sources, 'dependencies' : common_deps + [libmicrohttpd], }, + fuzz_template + { + 'sources' : files('fuzz-journal-remote.c'), + 'link_with' : [ + libshared, + libsystemd_journal_remote, + ], + 'include_directories' : journal_includes, + }, ] in_files = [ @@ -112,16 +120,3 @@ if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 chmod 755 $DESTDIR/var/log/journal/remote || :''') endif endif - -############################################################ - -fuzzers += [ - { - 'sources' : files('fuzz-journal-remote.c'), - 'link_with' : [ - libshared, - libsystemd_journal_remote, - ], - 'includes' : journal_includes, - }, -] diff --git a/src/journal/meson.build b/src/journal/meson.build index 90170599a7..65adb2ccba 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -48,6 +48,14 @@ journal_test_template = test_template + { ], } +journal_fuzz_template = fuzz_template + { + 'link_with' : [ + libjournal_core, + libshared, + ], + 'dependencies' : libselinux, +} + executables += [ libexec_template + { 'name' : 'systemd-journald', @@ -124,6 +132,42 @@ executables += [ journal_test_template + { 'sources' : files('test-journal.c'), }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-audit.c', + 'fuzz-journald.c', + ), + }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-kmsg.c', + 'fuzz-journald.c', + ), + }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-native.c', + 'fuzz-journald.c', + ), + }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-native-fd.c', + 'fuzz-journald.c', + ), + }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-stream.c', + 'fuzz-journald.c', + ), + }, + journal_fuzz_template + { + 'sources' : files( + 'fuzz-journald-syslog.c', + 'fuzz-journald.c', + ), + }, ] if install_sysconfdir_samples @@ -150,55 +194,3 @@ if get_option('create-log-dirs') 'setfacl -nm g:wheel:rx,d:g:wheel:rx $DESTDIR/var/log/journal || :') endif endif - -############################################################ - -fuzzer_journald_base = { - 'link_with' : [libjournal_core, libshared], - 'dependencies' : [libselinux], -} - -fuzzers += [ - { - 'sources' : files( - 'fuzz-journald-audit.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, - { - 'sources' : files( - 'fuzz-journald-kmsg.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, - { - 'sources' : files( - 'fuzz-journald-native.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, - { - 'sources' : files( - 'fuzz-journald-native-fd.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, - { - 'sources' : files( - 'fuzz-journald-stream.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, - { - 'sources' : files( - 'fuzz-journald-syslog.c', - 'fuzz-journald.c', - ), - 'base' : fuzzer_journald_base, - }, -] diff --git a/src/libsystemd-network/meson.build b/src/libsystemd-network/meson.build index 74041f6abd..043d3bc254 100644 --- a/src/libsystemd-network/meson.build +++ b/src/libsystemd-network/meson.build @@ -47,6 +47,13 @@ network_test_template = test_template + { 'suite' : 'network', } +network_fuzz_template = fuzz_template + { + 'link_with' : [ + libshared, + libsystemd_network, + ], +} + executables += [ network_test_template + { 'sources' : files('test-acd.c'), @@ -83,35 +90,22 @@ executables += [ network_test_template + { 'sources' : files('test-sd-dhcp-lease.c'), }, -] - -fuzzer_network_base = { - 'link_with' : [libshared, libsystemd_network], -} - -fuzzers += [ - { + network_fuzz_template + { 'sources' : files('fuzz-dhcp-client.c'), - 'base' : fuzzer_network_base, }, - { + network_fuzz_template + { 'sources' : files('fuzz-dhcp6-client.c'), - 'base' : fuzzer_network_base, }, - { + network_fuzz_template + { 'sources' : files('fuzz-dhcp-server.c'), - 'base' : fuzzer_network_base, }, - { + network_fuzz_template + { 'sources' : files('fuzz-dhcp-server-relay.c'), - 'base' : fuzzer_network_base, }, - { + network_fuzz_template + { 'sources' : files('fuzz-lldp-rx.c'), - 'base' : fuzzer_network_base, }, - { + network_fuzz_template + { 'sources' : files('fuzz-ndisc-rs.c'), - 'base' : fuzzer_network_base, }, ] diff --git a/src/network/meson.build b/src/network/meson.build index c5607a9b31..7d0e5d6345 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -114,6 +114,9 @@ network_generator_sources = files( 'generator/network-generator.c', ) +networkd_network_gperf_gperf = files('networkd-network-gperf.gperf') +networkd_netdev_gperf_gperf = files('netdev/netdev-gperf.gperf') + sources += custom_target( 'networkd-gperf.c', input : 'networkd-gperf.gperf', @@ -122,13 +125,13 @@ sources += custom_target( sources += custom_target( 'networkd-network-gperf.c', - input : 'networkd-network-gperf.gperf', + input : networkd_network_gperf_gperf, output : 'networkd-network-gperf.c', command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) sources += custom_target( 'netdev-gperf.c', - input : 'netdev/netdev-gperf.gperf', + input : networkd_netdev_gperf_gperf, output : 'netdev-gperf.c', command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) @@ -158,6 +161,15 @@ network_test_template = test_template + { 'include_directories' : network_includes, } +network_fuzz_template = fuzz_template + { + 'link_with' : [ + libnetworkd_core, + libsystemd_network, + ], + 'dependencies' : threads, + 'include_directories' : network_includes, +} + executables += [ libexec_template + { 'name' : 'systemd-networkd', @@ -221,6 +233,12 @@ executables += [ network_test_template + { 'sources' : files('test-networkd-util.c'), }, + network_fuzz_template + { + 'sources' : files('fuzz-netdev-parser.c'), + }, + network_fuzz_template + { + 'sources' : files('fuzz-network-parser.c'), + }, ] if conf.get('ENABLE_NETWORKD') == 1 @@ -244,20 +262,3 @@ if conf.get('ENABLE_NETWORKD') == 1 install_dir : pkgsysconfdir) endif endif - -fuzzer_network_base = { - 'link_with' : [libnetworkd_core, libsystemd_network, networkd_link_with], - 'dependencies' : threads, - 'includes' : network_includes, -} - -fuzzers += [ - { - 'sources' : files('fuzz-netdev-parser.c'), - 'base' : fuzzer_network_base, - }, - { - 'sources' : files('fuzz-network-parser.c'), - 'base' : fuzzer_network_base, - }, -] diff --git a/src/nspawn/meson.build b/src/nspawn/meson.build index b6628c6751..e2605f895b 100644 --- a/src/nspawn/meson.build +++ b/src/nspawn/meson.build @@ -45,6 +45,7 @@ nspawn_common_template = { 'dependencies' : libseccomp, } nspawn_test_template = test_template + nspawn_common_template +nspawn_fuzz_template = fuzz_template + nspawn_common_template executables += [ executable_template + { @@ -69,20 +70,10 @@ executables += [ 'dependencies' : libacl, 'type' : 'manual', }, -] - -fuzzer_nspawn_base = { - 'link_with' : [libshared, libnspawn_core], - 'dependencies' : libseccomp -} - -fuzzers += [ - { + nspawn_fuzz_template + { 'sources' : files('fuzz-nspawn-settings.c'), - 'base' : fuzzer_nspawn_base, }, - { + nspawn_fuzz_template + { 'sources' : files('fuzz-nspawn-oci.c'), - 'base' : fuzzer_nspawn_base, }, ] diff --git a/src/resolve/meson.build b/src/resolve/meson.build index e8881fb3b3..5b4e583501 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -134,6 +134,7 @@ resolve_common_template = { ], } resolve_test_template = test_template + resolve_common_template +resolve_fuzz_template = fuzz_template + resolve_common_template executables += [ libexec_template + { @@ -195,6 +196,18 @@ executables += [ ], 'include_directories' : resolve_includes, }, + resolve_fuzz_template + { + 'sources' : files('fuzz-dns-packet.c'), + }, + resolve_fuzz_template + { + 'sources' : files( + 'fuzz-etc-hosts.c', + 'resolved-etc-hosts.c', + ), + }, + resolve_fuzz_template + { + 'sources' : files('fuzz-resource-record.c'), + }, ] if conf.get('ENABLE_RESOLVE') == 1 @@ -223,28 +236,3 @@ custom_target( command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], install : conf.get('ENABLE_RESOLVE') == 1 and install_sysconfdir_samples, install_dir : pkgsysconfdir) - -############################################################ - -fuzzer_resolve_base = { - 'link_with' : [libsystemd_resolve_core, libshared], - 'dependencies' : [lib_openssl_or_gcrypt, libm], -} - -fuzzers += [ - { - 'sources' : files('fuzz-dns-packet.c'), - 'base' : fuzzer_resolve_base, - }, - { - 'sources' : files( - 'fuzz-etc-hosts.c', - 'resolved-etc-hosts.c', - ), - 'base' : fuzzer_resolve_base, - }, - { - 'sources' : files('fuzz-resource-record.c'), - 'base' : fuzzer_resolve_base, - }, -] diff --git a/src/systemctl/meson.build b/src/systemctl/meson.build index e7e1a1964b..bc08b8672f 100644 --- a/src/systemctl/meson.build +++ b/src/systemctl/meson.build @@ -63,6 +63,14 @@ executables += [ threads, ], }, + fuzz_template + { + 'sources' : [ + files('fuzz-systemctl-parse-argv.c'), + systemctl_sources, + ], + 'link_with' : systemctl_link_with, + 'c_args' : ['-DFUZZ_SYSTEMCTL_PARSE_ARGV'], + }, ] foreach alias : (['halt', 'poweroff', 'reboot', 'shutdown'] + @@ -71,14 +79,3 @@ foreach alias : (['halt', 'poweroff', 'reboot', 'shutdown'] + bindir / 'systemctl', sbindir / alias) endforeach - -fuzzers += [ - { - 'sources' : [ - files('fuzz-systemctl-parse-argv.c'), - systemctl_sources, - ], - 'link_with' : systemctl_link_with, - 'c_args' : '-DFUZZ_SYSTEMCTL_PARSE_ARGV', - }, -] diff --git a/src/udev/meson.build b/src/udev/meson.build index b99e313722..200cc05546 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -84,9 +84,11 @@ keyboard_keys_from_name_h = custom_target( ############################################################ +udev_link_gperf_gperf = files('net/link-config-gperf.gperf') + link_config_gperf_c = custom_target( 'link-config-gperf.c', - input : 'net/link-config-gperf.gperf', + input : udev_link_gperf_gperf, output : 'link-config-gperf.c', command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@']) @@ -142,6 +144,7 @@ udev_common_template = { ], } udev_test_template = test_template + udev_common_template +udev_fuzz_template = fuzz_template + udev_common_template executables += [ executable_template + { @@ -226,6 +229,22 @@ executables += [ udev_test_template + { 'sources' : files('test-udev-spawn.c'), }, + fuzz_template + { + 'sources' : files( + 'fido_id/fuzz-fido-id-desc.c', + 'fido_id/fido_id_desc.c', + ), + }, + udev_fuzz_template + { + 'sources' : files('net/fuzz-link-parser.c'), + 'include_directories' : udev_includes, + }, + udev_fuzz_template + { + 'sources' : files('fuzz-udev-rule-parse-value.c'), + }, + udev_fuzz_template + { + 'sources' : files('fuzz-udev-rules.c'), + }, ] meson.add_install_script(meson_make_symlink, @@ -252,30 +271,3 @@ if install_sysconfdir meson.add_install_script('sh', '-c', mkdir_p.format(sysconfdir / 'udev/rules.d')) endif - -fuzzer_udev_base = { - 'link_with' : [libudevd_core, libshared], - 'dependencies' : [threads, libacl], -} - -fuzzers += [ - { - 'sources' : files('net/fuzz-link-parser.c'), - 'includes' : udev_includes, - 'base' : fuzzer_udev_base, - }, - { - 'sources' : files('fuzz-udev-rule-parse-value.c'), - 'base' : fuzzer_udev_base, - }, - { - 'sources' : files('fuzz-udev-rules.c'), - 'base' : fuzzer_udev_base, - }, - { - 'sources' : files( - 'fido_id/fuzz-fido-id-desc.c', - 'fido_id/fido_id_desc.c', - ), - }, -] diff --git a/src/xdg-autostart-generator/meson.build b/src/xdg-autostart-generator/meson.build index 238dde8fd0..c938932c62 100644 --- a/src/xdg-autostart-generator/meson.build +++ b/src/xdg-autostart-generator/meson.build @@ -23,10 +23,7 @@ executables += [ 'xdg-autostart-service.c', ), }, -] - -fuzzers += [ - { + fuzz_template + { 'sources' : files( 'fuzz-xdg-desktop.c', 'xdg-autostart-service.c', diff --git a/test/fuzz/meson.build b/test/fuzz/meson.build index 5e8481354c..11b91e30bb 100644 --- a/test/fuzz/meson.build +++ b/test/fuzz/meson.build @@ -1,32 +1,38 @@ # SPDX-License-Identifier: LGPL-2.1-or-later generate_directives_py = find_program('generate-directives.py') -fuzz_generated_in_dir = meson.current_build_dir() -fuzz_generated_directives = [] +fuzz_regression_tests = {} -directives = [['fuzz-network-parser_directives', 'src/network/networkd-network-gperf.gperf'], - ['fuzz-netdev-parser_directives.netdev', 'src/network/netdev/netdev-gperf.gperf'], - ['fuzz-link-parser_directives.link', 'src/udev/net/link-config-gperf.gperf'], +directives = [['fuzz-network-parser', 'directives.network', networkd_network_gperf_gperf], + ['fuzz-netdev-parser', 'directives.netdev', networkd_netdev_gperf_gperf], + ['fuzz-link-parser', 'directives.link', udev_link_gperf_gperf], ] foreach tuple : directives - fuzz_generated_directives += custom_target( - tuple[0], - output: tuple[0], - command: [generate_directives_py, files(project_source_root / tuple[1])], + directive = custom_target( + tuple[1], + output: tuple[1], + command: [generate_directives_py, tuple[2]], capture: true) + + dict = { 'directives' : [directive] } + fuzz_regression_tests += { tuple[0] : dict } endforeach +unit_directives = [] foreach section : ['Automount', 'Mount', 'Path', 'Scope', 'Service', 'Slice', 'Socket', 'Swap', 'Timer'] unit_type = section.to_lower() sec_rx = section == 'Service' ? '(Service|Unit|Install)' : section - fuzz_generated_directives += custom_target( - 'fuzz-unit-file_directives.@0@'.format(unit_type), - output: 'fuzz-unit-file_directives.@0@'.format(unit_type), + name = 'directives.@0@'.format(unit_type) + unit_directives += custom_target( + name, + output: name, command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type], capture: true) endforeach +dict = { 'directives' : unit_directives } +fuzz_regression_tests += { 'fuzz-unit-file' : dict } ############################################################ @@ -58,21 +64,6 @@ else out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(project_source_root, fuzz_testsdir), check: true) endif -# Fuzz inputs that we generate (see above fuzz_generated_directives) -fuzz_regression_tests = { - 'fuzz-link-parser': [['', 'directives.link']], - 'fuzz-netdev-parser': [['', 'directives.netdev']], - 'fuzz-network-parser': [['', 'directives']], - 'fuzz-unit-file': [['', 'directives.automount'], - ['', 'directives.mount'], - ['', 'directives.path'], - ['', 'directives.scope'], - ['', 'directives.service'], - ['', 'directives.slice'], - ['', 'directives.socket'], - ['', 'directives.swap'], - ['', 'directives.timer']]} - # Add crafted fuzz inputs we have in the repo foreach p : out.stdout().split() # Remove the last entry which is ''. @@ -84,11 +75,8 @@ foreach p : out.stdout().split() endif fuzzer = fs.name(fs.parent(p)) fuzz_in = fs.name(p) - 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_testsdir, fuzz_in]] - fuzz_regression_tests += {fuzzer: l} + + dict = fuzz_regression_tests.get(fuzzer, {}) + dict += { 'files' : dict.get('files', []) + files(fuzzer / fuzz_in) } + fuzz_regression_tests += { fuzzer : dict } endforeach diff --git a/test/meson.build b/test/meson.build index a5bcc128cc..59d9a63a11 100644 --- a/test/meson.build +++ b/test/meson.build @@ -309,7 +309,3 @@ if want_tests != 'false' and conf.get('ENABLE_KERNEL_INSTALL') == 1 args : args, depends : deps) endif - -############################################################ - -subdir('fuzz') From dc4a00555a95af155c9a7edf21d6cb2cb1b355a5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 27 Jun 2023 01:28:32 +0900 Subject: [PATCH 8/8] meson: set suite for all tests, and adjust suite for some tests --- meson.build | 6 ++++-- src/ukify/test/meson.build | 3 ++- test/meson.build | 40 +++++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index cf217c1bf0..9d10d76d9f 100644 --- a/meson.build +++ b/meson.build @@ -2712,7 +2712,8 @@ foreach dict : modules test_dlopen, # path to dlopen must include a slash args : lib.full_path(), - depends : lib) + depends : lib, + suite : is_nss ? 'nss' : 'pam') endif endforeach @@ -2888,7 +2889,8 @@ if git.found() test('check-includes', files('tools/check-includes.py'), args: all_files, - env : ['PROJECT_SOURCE_ROOT=@0@'.format(project_source_root)]) + env : ['PROJECT_SOURCE_ROOT=@0@'.format(project_source_root)], + suite : 'headers') endif endif diff --git a/src/ukify/test/meson.build b/src/ukify/test/meson.build index e78e76c673..5870ccc06c 100644 --- a/src/ukify/test/meson.build +++ b/src/ukify/test/meson.build @@ -15,5 +15,6 @@ if want_ukify and want_tests != 'false' test('test-ukify', files('test_ukify.py'), args: args, - env : test_env) + env : test_env, + suite : 'ukify') endif diff --git a/test/meson.build b/test/meson.build index 59d9a63a11..97ec7ee5c5 100644 --- a/test/meson.build +++ b/test/meson.build @@ -63,7 +63,8 @@ if conf.get('ENABLE_SYSUSERS') == 1 test_sysusers_sh, # https://github.com/mesonbuild/meson/issues/2681 args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'sysusers') if have_standalone_binaries exe = executables_by_name.get('systemd-sysusers.standalone') @@ -71,7 +72,8 @@ if conf.get('ENABLE_SYSUSERS') == 1 test_sysusers_sh, # https://github.com/mesonbuild/meson/issues/2681 args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'sysusers') endif endif @@ -108,7 +110,8 @@ if want_tests != 'false' # https://github.com/mesonbuild/meson/issues/2681 args : [systemctl.full_path(), systemd_id128.full_path()], - depends : [systemctl, systemd_id128]) + depends : [systemctl, systemd_id128], + suite : 'systemctl') endif ############################################################ @@ -118,7 +121,8 @@ if want_tests != 'false' and conf.get('HAVE_SYSV_COMPAT') == 1 exe = executables_by_name.get('systemd-sysv-generator') test('sysv-generator-test', sysv_generator_test_py, - depends : exe) + depends : exe, + suite : 'sysv') endif ############################################################ @@ -129,7 +133,8 @@ if want_tests != 'false' and conf.get('HAVE_BLKID') == 1 and conf.get('ENABLE_BO test('test-bootctl-json', test_bootctl_json_sh, args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'boot') endif ############################################################ @@ -140,14 +145,16 @@ if want_tests != 'false' and conf.get('ENABLE_TMPFILES') == 1 test('test-systemd-tmpfiles', test_systemd_tmpfiles_py, args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'tmpfiles') if have_standalone_binaries exe = executables_by_name.get('systemd-tmpfiles.standalone') test('test-systemd-tmpfiles.standalone', test_systemd_tmpfiles_py, args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'tmpfiles') endif endif @@ -159,7 +166,8 @@ if want_tests != 'false' test('test-compare-versions', test_compare_versions_sh, args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'test') endif if install_tests install_data(test_compare_versions_sh, @@ -178,7 +186,7 @@ if want_tests != 'false' exe = executables_by_name.get('udevadm') test('udev-rules-check', exe, - suite : 'dist', + suite : 'udev', args : ['verify', '--resolve-names=never', all_rules]) endif @@ -200,7 +208,8 @@ if want_tests != 'false' # https://github.com/mesonbuild/meson/issues/2681 args : exe.full_path(), env : test_env, - depends : exe) + depends : exe, + suite : 'fstab') endif if install_tests install_data('test-fstab-generator.sh', @@ -217,7 +226,8 @@ if want_tests != 'false' test_network_generator_conversion_sh, # https://github.com/mesonbuild/meson/issues/2681 args : exe.full_path(), - depends : exe) + depends : exe, + suite : 'network') endif if install_tests install_data('test-network-generator-conversion.sh', @@ -236,7 +246,8 @@ if want_tests != 'false' args : ['-v'], env : ['UDEV_RULE_RUNNER=' + exe.full_path()], depends : exe, - timeout : 180) + timeout : 180, + suite : 'udev') endif if install_tests install_data( @@ -284,7 +295,7 @@ if want_tests != 'false' and conf.get('HAVE_DMI') == 1 source = project_source_root / p test('dmidecode_' + fs.stem(p), udev_dmi_memory_id_test, - suite : 'dist', + suite : 'udev', args : [exe.full_path(), source, source + '.txt'], @@ -307,5 +318,6 @@ if want_tests != 'false' and conf.get('ENABLE_KERNEL_INSTALL') == 1 test_kernel_install_sh, env : test_env, args : args, - depends : deps) + depends : deps, + suite : 'kernel-install') endif