# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright 2017 Zbigniew Jędrzejewski-Szmek
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# systemd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.

test_data_files = '''
        a.service
        b.service
        basic.target
        c.service
        d.service
        daughter.service
        e.service
        end.service
        f.service
        g.service
        grandchild.service
        h.service
        hello-after-sleep.target
        hello.service
        hwdb/10-bad.hwdb
        journal-data/journal-1.txt
        journal-data/journal-2.txt
        parent-deep.slice
        parent.slice
        sched_idle_bad.service
        sched_idle_ok.service
        sched_rr_bad.service
        sched_rr_change.service
        sched_rr_ok.service
        shutdown.target
        sleep.service
        sockets.target
        son.service
        sysinit.target
        test-execute/exec-bindpaths.service
        test-execute/exec-capabilityambientset-merge-nfsnobody.service
        test-execute/exec-capabilityambientset-merge.service
        test-execute/exec-capabilityambientset-nfsnobody.service
        test-execute/exec-capabilityambientset.service
        test-execute/exec-capabilityboundingset-invert.service
        test-execute/exec-capabilityboundingset-merge.service
        test-execute/exec-capabilityboundingset-reset.service
        test-execute/exec-capabilityboundingset-simple.service
        test-execute/exec-cpuaffinity1.service
        test-execute/exec-cpuaffinity2.service
        test-execute/exec-cpuaffinity3.service
        test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service
        test-execute/exec-dynamicuser-fixeduser.service
        test-execute/exec-dynamicuser-statedir-migrate-step1.service
        test-execute/exec-dynamicuser-statedir-migrate-step2.service
        test-execute/exec-dynamicuser-statedir.service
        test-execute/exec-dynamicuser-supplementarygroups.service
        test-execute/exec-environment-empty.service
        test-execute/exec-environment-multiple.service
        test-execute/exec-environment.service
        test-execute/exec-environmentfile.service
        test-execute/exec-group-nfsnobody.service
        test-execute/exec-group-nogroup.service
        test-execute/exec-group.service
        test-execute/exec-ignoresigpipe-no.service
        test-execute/exec-ignoresigpipe-yes.service
        test-execute/exec-inaccessiblepaths-mount-propagation.service
        test-execute/exec-inaccessiblepaths-proc.service
        test-execute/exec-ioschedulingclass-best-effort.service
        test-execute/exec-ioschedulingclass-idle.service
        test-execute/exec-ioschedulingclass-none.service
        test-execute/exec-ioschedulingclass-realtime.service
        test-execute/exec-oomscoreadjust-negative.service
        test-execute/exec-oomscoreadjust-positive.service
        test-execute/exec-passenvironment-absent.service
        test-execute/exec-passenvironment-empty.service
        test-execute/exec-passenvironment-repeated.service
        test-execute/exec-passenvironment.service
        test-execute/exec-personality-aarch64.service
        test-execute/exec-personality-ppc64.service
        test-execute/exec-personality-ppc64le.service
        test-execute/exec-personality-s390.service
        test-execute/exec-personality-x86-64.service
        test-execute/exec-personality-x86.service
        test-execute/exec-privatedevices-no-capability-mknod.service
        test-execute/exec-privatedevices-no-capability-sys-rawio.service
        test-execute/exec-privatedevices-no.service
        test-execute/exec-privatedevices-yes-capability-mknod.service
        test-execute/exec-privatedevices-yes-capability-sys-rawio.service
        test-execute/exec-privatedevices-yes.service
        test-execute/exec-privatenetwork-yes.service
        test-execute/exec-privatetmp-no.service
        test-execute/exec-privatetmp-yes.service
        test-execute/exec-protectkernelmodules-no-capabilities.service
        test-execute/exec-protectkernelmodules-yes-capabilities.service
        test-execute/exec-protectkernelmodules-yes-mount-propagation.service
        test-execute/exec-readonlypaths-mount-propagation.service
        test-execute/exec-readonlypaths-simple.service
        test-execute/exec-readonlypaths-with-bindpaths.service
        test-execute/exec-readonlypaths.service
        test-execute/exec-readwritepaths-mount-propagation.service
        test-execute/exec-restrictnamespaces-mnt-blacklist.service
        test-execute/exec-restrictnamespaces-mnt.service
        test-execute/exec-restrictnamespaces-no.service
        test-execute/exec-restrictnamespaces-yes.service
        test-execute/exec-runtimedirectory-mode.service
        test-execute/exec-runtimedirectory-owner-nfsnobody.service
        test-execute/exec-runtimedirectory-owner.service
        test-execute/exec-runtimedirectory.service
        test-execute/exec-specifier-interpolation.service
        test-execute/exec-specifier.service
        test-execute/exec-specifier@.service
        test-execute/exec-standardinput-data.service
        test-execute/exec-standardinput-file.service
        test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service
        test-execute/exec-supplementarygroups-multiple-groups-withgid.service
        test-execute/exec-supplementarygroups-multiple-groups-withuid.service
        test-execute/exec-supplementarygroups-single-group-user.service
        test-execute/exec-supplementarygroups-single-group.service
        test-execute/exec-supplementarygroups.service
        test-execute/exec-systemcallerrornumber-name.service
        test-execute/exec-systemcallerrornumber-number.service
        test-execute/exec-systemcallfilter-failing.service
        test-execute/exec-systemcallfilter-failing2.service
        test-execute/exec-systemcallfilter-not-failing.service
        test-execute/exec-systemcallfilter-not-failing2.service
        test-execute/exec-systemcallfilter-system-user-nfsnobody.service
        test-execute/exec-systemcallfilter-system-user.service
        test-execute/exec-systemcallfilter-with-errno-name.service
        test-execute/exec-systemcallfilter-with-errno-number.service
        test-execute/exec-umask-0177.service
        test-execute/exec-umask-default.service
        test-execute/exec-unsetenvironment.service
        test-execute/exec-user-nfsnobody.service
        test-execute/exec-user.service
        test-execute/exec-workingdirectory.service
        test-path/basic.target
        test-path/path-changed.path
        test-path/path-changed.service
        test-path/path-directorynotempty.path
        test-path/path-directorynotempty.service
        test-path/path-exists.path
        test-path/path-exists.service
        test-path/path-existsglob.path
        test-path/path-existsglob.service
        test-path/path-makedirectory.path
        test-path/path-makedirectory.service
        test-path/path-modified.path
        test-path/path-modified.service
        test-path/path-mycustomunit.service
        test-path/path-service.service
        test-path/path-unit.path
        test-path/paths.target
        test-path/sysinit.target
        testsuite.target
        timers.target
        unstoppable.service
'''.split()

if conf.get('ENABLE_RESOLVE') == 1
        test_data_files += '''
                test-resolve/_openpgpkey.fedoraproject.org.pkts
                test-resolve/fedoraproject.org.pkts
                test-resolve/gandi.net.pkts
                test-resolve/google.com.pkts
                test-resolve/root.pkts
                test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts
                test-resolve/teamits.com.pkts
                test-resolve/zbyszek@fedoraproject.org.pkts
                test-resolve/_443._tcp.fedoraproject.org.pkts
                test-resolve/kyhwana.org.pkts
                test-resolve/fake-caa.pkts
        '''.split()
endif

if install_tests
        foreach file : test_data_files
                subdir = file.split('/')[0]
                if subdir == file
                        subdir = ''
                endif

                install_data(file,
                             install_dir : testsdir + '/testdata/' + subdir)
        endforeach
endif

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

rule_syntax_check_py = find_program('rule-syntax-check.py')
test('rule-syntax-check',
     rule_syntax_check_py,
     args : all_rules)

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

if conf.get('HAVE_SYSV_COMPAT') == 1
        sysv_generator_test_py = find_program('sysv-generator-test.py')
        test('sysv-generator-test',
             sysv_generator_test_py)
endif

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

# prepare test/sys tree
sys_script_py = find_program('sys-script.py')
custom_target(
        'sys',
        command : [sys_script_py, meson.current_build_dir()],
        output : 'sys',
        build_by_default : true)

udev_test_pl = find_program('udev-test.pl')
test('udev-test',
     udev_test_pl)

if conf.get('ENABLE_HWDB') == 1
        hwdb_test_sh = find_program('hwdb-test.sh')
        test('hwdb-test',
             hwdb_test_sh,
             timeout : 90)
endif

subdir('fuzz-regressions')
