update TODO
[systemd.io.git] / test / meson.build
blob92f184e3f576769fbb9c1306a536d431dbfb7044
1 # SPDX-License-Identifier: LGPL-2.1-or-later
3 if conf.get('ENABLE_SYSUSERS') == 1
4         test_sysusers_sh = configure_file(
5                 input : 'test-sysusers.sh.in',
6                 output : 'test-sysusers.sh',
7                 configuration : conf)
9         if want_tests != 'false'
10                 exe = executables_by_name.get('systemd-sysusers')
11                 test('test-sysusers',
12                      test_sysusers_sh,
13                      # https://github.com/mesonbuild/meson/issues/2681
14                      args : exe.full_path(),
15                      depends : exe,
16                      suite : 'sysusers')
18                 if have_standalone_binaries
19                         exe = executables_by_name.get('systemd-sysusers.standalone')
20                         test('test-sysusers.standalone',
21                              test_sysusers_sh,
22                              # https://github.com/mesonbuild/meson/issues/2681
23                              args : exe.full_path(),
24                              depends : exe,
25                              suite : 'sysusers')
26                 endif
27         endif
29         if install_tests
30                 install_data(test_sysusers_sh,
31                              install_dir : unittestsdir)
32                 install_subdir('test-sysusers',
33                                exclude_files : '.gitattributes',
34                                install_dir : testdata_dir)
35         endif
36 endif
38 ############################################################
40 if want_tests != 'false' and conf.get('ENABLE_HWDB') == 1
41         hwdb_test_sh = find_program('hwdb-test.sh')
42         exe = executables_by_name.get('systemd-hwdb')
43         test('hwdb-test',
44              hwdb_test_sh,
45              suite : 'dist',
46              args : exe.full_path(),
47              depends : exe,
48              timeout : 90)
49 endif
51 ############################################################
53 if want_tests != 'false'
54         test_systemctl_enable_sh = find_program('test-systemctl-enable.sh')
55         systemctl = executables_by_name.get('systemctl')
56         systemd_id128 = executables_by_name.get('systemd-id128')
57         test('test-systemctl-enable',
58              test_systemctl_enable_sh,
59              # https://github.com/mesonbuild/meson/issues/2681
60              args : [systemctl.full_path(),
61                      systemd_id128.full_path()],
62              depends : [systemctl, systemd_id128],
63              suite : 'systemctl')
64 endif
66 ############################################################
68 if want_tests != 'false' and conf.get('HAVE_SYSV_COMPAT') == 1
69         sysv_generator_test_py = find_program('sysv-generator-test.py')
70         exe = executables_by_name.get('systemd-sysv-generator')
71         test('sysv-generator-test',
72              sysv_generator_test_py,
73              depends : exe,
74              suite : 'sysv')
75 endif
77 ############################################################
79 if want_tests != 'false' and conf.get('HAVE_BLKID') == 1
80         test_bootctl_json_sh = find_program('test-bootctl-json.sh')
81         exe = executables_by_name.get('bootctl')
82         test('test-bootctl-json',
83              test_bootctl_json_sh,
84              args : exe.full_path(),
85              depends : exe,
86              suite : 'boot')
87 endif
89 ############################################################
91 if want_tests != 'false' and conf.get('ENABLE_TMPFILES') == 1
92         test_systemd_tmpfiles_py = find_program('test-systemd-tmpfiles.py')
93         exe = executables_by_name.get('systemd-tmpfiles')
94         test('test-systemd-tmpfiles',
95              test_systemd_tmpfiles_py,
96              args : exe.full_path(),
97              depends : exe,
98              suite : 'tmpfiles')
100         if have_standalone_binaries
101                 exe = executables_by_name.get('systemd-tmpfiles.standalone')
102                 test('test-systemd-tmpfiles.standalone',
103                      test_systemd_tmpfiles_py,
104                      args : exe.full_path(),
105                      depends : exe,
106                      suite : 'tmpfiles')
107         endif
108 endif
110 ############################################################
112 test_compare_versions_sh = files('test-compare-versions.sh')
113 if want_tests != 'false'
114         exe = executables_by_name.get('systemd-analyze')
115         test('test-compare-versions',
116              test_compare_versions_sh,
117              args : exe.full_path(),
118              depends : exe,
119              suite : 'test')
120 endif
121 if install_tests
122         install_data(test_compare_versions_sh,
123                      install_dir : unittestsdir)
124 endif
126 ############################################################
128 rule_syntax_check_py = find_program('rule-syntax-check.py')
129 if want_tests != 'false'
130         test('rule-syntax-check',
131              rule_syntax_check_py,
132              suite : 'dist',
133              args : all_rules)
135         exe = executables_by_name.get('udevadm')
136         test('udev-rules-check',
137              exe,
138              suite : 'udev',
139              args : ['verify', '--resolve-names=never', all_rules])
140 endif
142 ############################################################
144 if install_tests
145         install_data('run-unit-tests.py',
146                      install_mode : 'rwxr-xr-x',
147                      install_dir : testsdir)
149         install_data('integration-test-setup.sh',
150                      install_mode : 'rwxr-xr-x',
151                      install_dir : testdata_dir)
152 endif
154 ############################################################
156 test_fstab_generator_sh = find_program('test-fstab-generator.sh')
157 if want_tests != 'false'
158         exe = executables_by_name.get('systemd-fstab-generator')
159         test('test-fstab-generator',
160              test_fstab_generator_sh,
161              # https://github.com/mesonbuild/meson/issues/2681
162              args : exe.full_path(),
163              env : test_env,
164              depends : exe,
165              suite : 'fstab')
166 endif
167 if install_tests
168         install_data('test-fstab-generator.sh',
169                      install_mode : 'rwxr-xr-x',
170                      install_dir : unittestsdir)
171 endif
173 ############################################################
175 test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh')
176 if want_tests != 'false'
177         exe = executables_by_name.get('systemd-network-generator')
178         test('test-network-generator-conversion',
179              test_network_generator_conversion_sh,
180              # https://github.com/mesonbuild/meson/issues/2681
181              args : exe.full_path(),
182              depends : exe,
183              suite : 'network')
184 endif
185 if install_tests
186         install_data('test-network-generator-conversion.sh',
187                      install_mode : 'rwxr-xr-x',
188                      install_dir : unittestsdir)
189 endif
191 ############################################################
193 sys_script_py = files('sys-script.py')
194 test_udev_py = files('test-udev.py')
195 if want_tests != 'false'
196         exe = executables_by_name.get('test-udev-rule-runner')
197         test('test-udev',
198              test_udev_py,
199              args : ['-v'],
200              env : ['UDEV_RULE_RUNNER=' + exe.full_path()],
201              depends : exe,
202              timeout : 180,
203              suite : 'udev')
204 endif
205 if install_tests
206         install_data(
207                 sys_script_py,
208                 test_udev_py,
209                 install_dir : unittestsdir)
210 endif
212 ############################################################
214 rpm = find_program('rpm', required : false)
215 rpmspec = find_program('rpmspec', required : false)
216 test_rpm_macros = find_program('test-rpm-macros.sh')
218 if rpm.found() and rpmspec.found()
219         if want_tests != 'false'
220                 test('test-rpm-macros',
221                      test_rpm_macros,
222                      suite : 'dist',
223                      args : [project_build_root])
224         endif
225 else
226       message('Skipping test-rpm-macros since rpm and/or rpmspec are not available')
227 endif
229 ############################################################
231 if want_tests != 'false' and conf.get('HAVE_DMI') == 1
232         udev_dmi_memory_id_test = find_program('udev-dmi-memory-id-test.sh')
233         exe = executables_by_name.get('dmi_memory_id')
235         if git.found() and fs.is_dir(project_source_root / '.git')
236                 out = run_command(
237                         env, '-u', 'GIT_WORK_TREE',
238                         git, '--git-dir=@0@/.git'.format(project_source_root),
239                         'ls-files', ':/test/dmidecode-dumps/*.bin',
240                         check: true)
241         else
242                 out = run_command(
243                         sh, '-c', 'cd "$1"; echo test/dmidecode-dumps/*.bin', '_', project_source_root,
244                         check: true)
245         endif
247         foreach p : out.stdout().split()
248                 source = project_source_root / p
249                 test('dmidecode_' + fs.stem(p),
250                      udev_dmi_memory_id_test,
251                      suite : 'udev',
252                      args : [exe.full_path(),
253                              source,
254                              source + '.txt'],
255                      depends : exe)
256         endforeach
257 endif
259 ############################################################
261 if want_tests != 'false' and conf.get('ENABLE_KERNEL_INSTALL') == 1
262         kernel_install = executables_by_name.get('kernel-install')
263         args = [kernel_install.full_path(), loaderentry_install.full_path(), uki_copy_install]
264         deps = [kernel_install, loaderentry_install]
265         if want_ukify and boot_stubs.length() > 0
266                 args += [ukify.full_path(), ukify_install.full_path(), boot_stubs[0]]
267                 deps += [ukify, ukify_install, boot_stubs[0]]
268         endif
270         test('test-kernel-install',
271              test_kernel_install_sh,
272              env : test_env,
273              args : args,
274              depends : deps,
275              suite : 'kernel-install')
276 endif
278 ############################################################
280 integration_test_wrapper = find_program('integration-test-wrapper.py')
281 integration_tests = []
282 integration_test_template = {
283         'mkosi-args' : [],
284         'timeout' : 1800,
285         'storage' : 'volatile',
286         'priority' : 0,
287         'firmware' : 'linux',
288         'enabled' : true,
289         'configuration' : {
290                 'memory-accounting' : 'no',
291                 'command' : testdata_dir / 'units/%N.sh',
292                 'wants' : 'multi-user.target user@4711.service',
293                 'after' : 'user@4711.service',
294         },
295         'cmdline' : [],
296         'credentials' : [],
297         'qemu-args' : [],
298         'exit-code' : 123,
299         'vm' : false,
300         'coredump-exclude-regex' : '',
301         'sanitizer-exclude-regex' : '',
303 testdata_subdirs = [
304         'auxv',
305         'journal-data',
306         'knot-data',
307         'test-journals',
308         'units',
309         'test-execute',
310         'test-fstab-generator',
311         'test-path',
312         'test-path-util',
313         'test-umount',
314         'test-network',
315         'test-network-generator-conversion',
318 foreach dirname : [
319         'TEST-01-BASIC',
320         'TEST-02-UNITTESTS',
321         'TEST-03-JOBS',
322         'TEST-04-JOURNAL',
323         'TEST-05-RLIMITS',
324         'TEST-06-SELINUX',
325         'TEST-07-PID1',
326         'TEST-08-INITRD',
327         'TEST-09-REBOOT',
328         'TEST-13-NSPAWN',
329         'TEST-15-DROPIN',
330         'TEST-16-EXTEND-TIMEOUT',
331         'TEST-17-UDEV',
332         'TEST-18-FAILUREACTION',
333         'TEST-19-CGROUP',
334         'TEST-21-DFUZZER',
335         'TEST-22-TMPFILES',
336         'TEST-23-UNIT-FILE',
337         'TEST-24-CRYPTSETUP',
338         'TEST-25-IMPORT',
339         'TEST-26-SYSTEMCTL',
340         'TEST-29-PORTABLE',
341         'TEST-30-ONCLOCKCHANGE',
342         'TEST-31-DEVICE-ENUMERATION',
343         'TEST-32-OOMPOLICY',
344         'TEST-34-DYNAMICUSERMIGRATE',
345         'TEST-35-LOGIN',
346         'TEST-36-NUMAPOLICY',
347         'TEST-38-FREEZER',
348         'TEST-43-PRIVATEUSER-UNPRIV',
349         'TEST-44-LOG-NAMESPACE',
350         'TEST-45-TIMEDATE',
351         'TEST-46-HOMED',
352         'TEST-50-DISSECT',
353         'TEST-52-HONORFIRSTSHUTDOWN',
354         'TEST-53-ISSUE-16347',
355         'TEST-54-CREDS',
356         'TEST-55-OOMD',
357         'TEST-58-REPART',
358         'TEST-59-RELOADING-RESTART',
359         'TEST-60-MOUNT-RATELIMIT',
360         'TEST-62-RESTRICT-IFACES',
361         'TEST-63-PATH',
362         'TEST-64-UDEV-STORAGE',
363         'TEST-65-ANALYZE',
364         'TEST-66-DEVICE-ISOLATION',
365         'TEST-67-INTEGRITY',
366         'TEST-68-PROPAGATE-EXIT-STATUS',
367         'TEST-69-SHUTDOWN',
368         'TEST-70-TPM2',
369         'TEST-71-HOSTNAME',
370         'TEST-72-SYSUPDATE',
371         'TEST-73-LOCALE',
372         'TEST-74-AUX-UTILS',
373         'TEST-75-RESOLVED',
374         'TEST-76-SYSCTL',
375         'TEST-78-SIGQUEUE',
376         'TEST-79-MEMPRESS',
377         'TEST-80-NOTIFYACCESS',
378         'TEST-81-GENERATORS',
379         'TEST-82-SOFTREBOOT',
380         'TEST-83-BTRFS',
381         'TEST-84-STORAGETM',
382         'TEST-85-NETWORK',
383         'TEST-86-MULTI-PROFILE-UKI',
384         'TEST-87-AUX-UTILS-VM',
386         subdir(dirname)
387 endforeach
389 foreach integration_test : integration_tests
390         integration_test_args = [
391                 '--meson-source-dir', meson.project_source_root(),
392                 '--meson-build-dir', meson.project_build_root(),
393                 '--name', integration_test['name'],
394                 '--storage', integration_test['storage'],
395                 '--firmware', integration_test['firmware'],
396                 '--exit-code', integration_test['exit-code'].to_string(),
397                 '--coredump-exclude-regex', integration_test['coredump-exclude-regex'],
398                 '--sanitizer-exclude-regex', integration_test['sanitizer-exclude-regex'],
399         ]
401         if 'unit' in integration_test
402                 integration_test_unit = integration_test['unit']
403         else
404                 integration_test_unit = configure_file(
405                         input : 'test.service.in',
406                         output : '@0@.service'.format(integration_test['name']),
407                         configuration : integration_test['configuration'],
408                 )
409         endif
411         integration_test_args += ['--unit', fs.name(integration_test_unit)]
412         if install_tests
413                 install_data(integration_test_unit, install_dir : testdata_dir / 'units')
414         endif
416         if integration_test['vm']
417                 integration_test_args += ['--vm']
418         endif
420         if not mkosi.found()
421                 continue
422         endif
424         integration_test_args += ['--mkosi', mkosi.full_path(), '--']
426         if integration_test['cmdline'].length() > 0
427                 integration_test_args += [
428                         '--kernel-command-line-extra=@0@'.format(' '.join(integration_test['cmdline']))
429                 ]
430         endif
432         foreach credential : integration_test['credentials']
433                 integration_test_args += ['--credential', credential]
434         endforeach
436         if integration_test['qemu-args'].length() > 0
437                 integration_test_args += ['--qemu-args=@0@'.format(' '.join(integration_test['qemu-args']))]
438         endif
440         integration_test_args += integration_test['mkosi-args']
442         integration_test_env = {}
444         if want_integration_tests
445                 integration_test_env += {'SYSTEMD_INTEGRATION_TESTS': '1'}
446         endif
448         if not integration_test['enabled']
449                 continue
450         endif
452         # We don't explicitly depend on the "mkosi" target because that means the image is rebuilt on every
453         # "ninja -C build". Instead, the mkosi target has to be rebuilt manually before running the
454         # integration tests with mkosi.
455         test(
456                 integration_test['name'],
457                 integration_test_wrapper,
458                 env : integration_test_env,
459                 args : integration_test_args,
460                 timeout : integration_test['timeout'],
461                 priority : integration_test['priority'],
462                 suite : 'integration-tests',
463         )
464 endforeach
466 if install_tests
467         foreach subdir : testdata_subdirs
468                 # install_subdir() before meson 1.3.0 does not handle symlinks correctly (it follows them
469                 # instead of copying the symlink) so we use rsync instead.
470                 if meson.version().version_compare('<1.3.0')
471                         if not rsync.found()
472                                 error('rsync is required to install the integration test data')
473                         endif
475                         rsync_r = rsync.full_path() + ' -rlpt --exclude .gitattributes --exclude 25-default.link -- "@0@" "${DESTDIR:-}@1@"'
476                         meson.add_install_script(sh, '-c',
477                                                  rsync_r.format(meson.current_source_dir() / subdir, testdata_dir))
478                 else
479                         install_subdir(subdir,
480                                        exclude_files : ['.gitattributes', '25-default.link'],
481                                        install_dir : testdata_dir,
482                                        follow_symlinks : false)
483                 endif
484         endforeach
486         # test-network/conf/25-default.link is a local symlink that becomes dangling when installed, so we
487         # exclude it and create the correct symlink here.
488         meson.add_install_script(sh, '-c', ln_s.format(networkdir / '99-default.link',
489                                                        testdata_dir / 'test-network/conf/25-default.link'))
491         install_data(kbd_model_map,
492                      install_dir : testdata_dir + '/test-keymap-util')
494         if conf.get('HAVE_ZSTD') == 1 and efi_arch != ''
495                 install_subdir('test-bcd',
496                                exclude_files : '.gitattributes',
497                                install_dir : testdata_dir)
498         endif
499         if conf.get('ENABLE_RESOLVE') == 1
500                 install_subdir('test-resolve',
501                                exclude_files : '.gitattributes',
502                                install_dir : testdata_dir)
503         endif
505         # The unit tests implemented as shell scripts expect to find testdata/
506         # in the directory where they are stored.
507         meson.add_install_script(sh, '-c', ln_s.format(testdata_dir,
508                                                        unittestsdir / 'testdata'))
509 endif