diff options
author | Michael Biebl <biebl@debian.org> | 2017-07-12 21:26:31 +0200 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2017-07-12 21:26:31 +0200 |
commit | 81c583552ee1c3355cdef1b11a33737dd98e6971 (patch) | |
tree | 5c5f87a4d03456a5b32d63b0d4305440f73ab462 /test | |
parent | 2897b343851c95927e26f45bea8c40da605dbed1 (diff) | |
download | systemd-81c583552ee1c3355cdef1b11a33737dd98e6971.tar.gz |
New upstream version 234
Diffstat (limited to 'test')
-rw-r--r-- | test/README.testsuite | 2 | ||||
-rwxr-xr-x | test/TEST-12-ISSUE-3171/test.sh | 8 | ||||
-rwxr-xr-x | test/create-sys-script.py | 4 | ||||
-rw-r--r-- | test/meson.build | 167 | ||||
-rwxr-xr-x | test/networkd-test.py | 78 | ||||
-rwxr-xr-x | test/rule-syntax-check.py | 2 | ||||
-rwxr-xr-x | test/sys-script.py | 2 | ||||
-rwxr-xr-x | test/sysv-generator-test.py | 2 | ||||
-rwxr-xr-x | test/test-efi-create-disk.sh | 32 | ||||
-rwxr-xr-x | test/test-exec-deserialization.py | 192 | ||||
-rw-r--r-- | test/test-execute/exec-inaccessiblepaths-mount-propagation.service | 2 | ||||
-rw-r--r-- | test/test-execute/exec-inaccessiblepaths-proc.service | 7 | ||||
-rw-r--r-- | test/test-execute/exec-protectkernelmodules-yes-mount-propagation.service | 2 | ||||
-rw-r--r-- | test/test-execute/exec-readonlypaths-mount-propagation.service | 2 | ||||
-rw-r--r-- | test/test-execute/exec-readwritepaths-mount-propagation.service | 2 | ||||
-rw-r--r-- | test/test-functions | 32 |
16 files changed, 506 insertions, 30 deletions
diff --git a/test/README.testsuite b/test/README.testsuite index fa7e73ce3a..58f67f50fd 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -3,7 +3,7 @@ subdirectories named "test/TEST-??-*", which are run one by one. To run the extended testsuite do the following: -$ make all +$ make all # Avoid the "sudo make" below building anything as root $ cd test $ sudo make clean check ... diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh index e20f470143..c252bdfbad 100755 --- a/test/TEST-12-ISSUE-3171/test.sh +++ b/test/TEST-12-ISSUE-3171/test.sh @@ -67,23 +67,23 @@ EOL systemctl start test.socket systemctl is-active test.socket [[ "$(stat --format='%G' /run/test.socket)" == adm ]] -echo A | nc -U /run/test.socket +echo A | nc -w1 -U /run/test.socket mv $U ${U}.disabled systemctl daemon-reload systemctl is-active test.socket [[ "$(stat --format='%G' /run/test.socket)" == adm ]] -echo B | nc -U /run/test.socket && exit 1 +echo B | nc -w1 -U /run/test.socket && exit 1 mv ${U}.disabled $U systemctl daemon-reload systemctl is-active test.socket -echo C | nc -U /run/test.socket && exit 1 +echo C | nc -w1 -U /run/test.socket && exit 1 [[ "$(stat --format='%G' /run/test.socket)" == adm ]] systemctl restart test.socket systemctl is-active test.socket -echo D | nc -U /run/test.socket +echo D | nc -w1 -U /run/test.socket [[ "$(stat --format='%G' /run/test.socket)" == adm ]] diff --git a/test/create-sys-script.py b/test/create-sys-script.py index 4b7abd24ae..402b4f83ab 100755 --- a/test/create-sys-script.py +++ b/test/create-sys-script.py @@ -1,6 +1,6 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 -OUTFILE_HEADER = """#!/usr/bin/python3 +OUTFILE_HEADER = """#!/usr/bin/env python3 # # create-sys-script.py # diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000000..55e693ac72 --- /dev/null +++ b/test/meson.build @@ -0,0 +1,167 @@ +test_data_files = ''' + a.service + basic.target + b.service + c.service + daughter.service + d.service + end.service + e.service + f.service + grandchild.service + g.service + hello-after-sleep.target + hello.service + h.service + 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 + testsuite.target + timers.target + unstoppable.service + test-path/paths.target + test-path/basic.target + test-path/sysinit.target + test-path/path-changed.service + test-path/path-directorynotempty.service + test-path/path-existsglob.service + test-path/path-exists.service + test-path/path-makedirectory.service + test-path/path-modified.service + test-path/path-mycustomunit.service + test-path/path-service.service + test-path/path-changed.path + test-path/path-directorynotempty.path + test-path/path-existsglob.path + test-path/path-exists.path + test-path/path-makedirectory.path + test-path/path-modified.path + test-path/path-unit.path + test-execute/exec-environment-empty.service + test-execute/exec-environment-multiple.service + test-execute/exec-environment.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-group.service + test-execute/exec-group-nfsnobody.service + test-execute/exec-supplementarygroups.service + test-execute/exec-supplementarygroups-single-group.service + test-execute/exec-supplementarygroups-single-group-user.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-dynamicuser-fixeduser.service + test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service + test-execute/exec-dynamicuser-supplementarygroups.service + test-execute/exec-ignoresigpipe-no.service + test-execute/exec-ignoresigpipe-yes.service + test-execute/exec-personality-x86-64.service + test-execute/exec-personality-x86.service + test-execute/exec-personality-s390.service + test-execute/exec-personality-ppc64.service + test-execute/exec-personality-ppc64le.service + test-execute/exec-personality-aarch64.service + test-execute/exec-privatedevices-no.service + test-execute/exec-privatedevices-yes.service + test-execute/exec-privatedevices-no-capability-mknod.service + test-execute/exec-privatedevices-yes-capability-mknod.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-privatetmp-no.service + test-execute/exec-privatetmp-yes.service + test-execute/exec-readonlypaths.service + test-execute/exec-readonlypaths-mount-propagation.service + test-execute/exec-readwritepaths-mount-propagation.service + test-execute/exec-inaccessiblepaths-mount-propagation.service + test-execute/exec-inaccessiblepaths-proc.service + test-execute/exec-spec-interpolation.service + test-execute/exec-systemcallerrornumber.service + test-execute/exec-systemcallfilter-failing2.service + test-execute/exec-systemcallfilter-failing.service + test-execute/exec-systemcallfilter-not-failing2.service + test-execute/exec-systemcallfilter-not-failing.service + test-execute/exec-systemcallfilter-system-user.service + test-execute/exec-systemcallfilter-system-user-nfsnobody.service + test-execute/exec-user.service + test-execute/exec-user-nfsnobody.service + test-execute/exec-workingdirectory.service + test-execute/exec-umask-0177.service + test-execute/exec-umask-default.service + test-execute/exec-privatenetwork-yes.service + test-execute/exec-environmentfile.service + test-execute/exec-oomscoreadjust-positive.service + test-execute/exec-oomscoreadjust-negative.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-capabilityboundingset-invert.service + test-execute/exec-capabilityboundingset-merge.service + test-execute/exec-capabilityboundingset-reset.service + test-execute/exec-capabilityboundingset-simple.service + test-execute/exec-capabilityambientset.service + test-execute/exec-capabilityambientset-nfsnobody.service + test-execute/exec-capabilityambientset-merge.service + test-execute/exec-capabilityambientset-merge-nfsnobody.service + test-execute/exec-runtimedirectory.service + test-execute/exec-runtimedirectory-mode.service + test-execute/exec-runtimedirectory-owner.service + test-execute/exec-runtimedirectory-owner-nfsnobody.service + test-execute/exec-restrict-namespaces-no.service + test-execute/exec-restrict-namespaces-yes.service + test-execute/exec-restrict-namespaces-mnt.service + test-execute/exec-restrict-namespaces-mnt-blacklist.service + test-execute/exec-read-only-path-succeed.service + test-execute/exec-privatedevices-yes-capability-sys-rawio.service + test-execute/exec-privatedevices-no-capability-sys-rawio.service + bus-policy/hello.conf + bus-policy/methods.conf + bus-policy/ownerships.conf + bus-policy/signals.conf + bus-policy/check-own-rules.conf + bus-policy/many-rules.conf + bus-policy/test.conf + hwdb/10-bad.hwdb + journal-data/journal-1.txt + journal-data/journal-2.txt +'''.split() + +if conf.get('ENABLE_RESOLVED', false) + 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 diff --git a/test/networkd-test.py b/test/networkd-test.py index e0dddeb053..eee8b65ec0 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -96,10 +96,20 @@ class NetworkdTestingUtilities: dropin_path = os.path.join(dropin_dir, "%s.conf" % dropin_name) os.makedirs(dropin_dir, exist_ok=True) + self.addCleanup(os.rmdir, dropin_dir) with open(dropin_path, 'w') as dropin: dropin.write(contents) self.addCleanup(os.remove, dropin_path) + def read_attr(self, link, attribute): + """Read a link attributed from the sysfs.""" + # Note we we don't want to check if interface `link' is managed, we + # want to evaluate link variable and pass the value of the link to + # assert_link_states e.g. eth0=managed. + self.assert_link_states(**{link:'managed'}) + with open(os.path.join('/sys/class/net', link, attribute)) as f: + return f.readline().strip() + def assert_link_states(self, **kwargs): """Match networkctl link states to the given ones. @@ -140,6 +150,74 @@ class NetworkdTestingUtilities: self.fail("Missing links in status output: %s" % interfaces) +class BridgeTest(NetworkdTestingUtilities, unittest.TestCase): + """Provide common methods for testing networkd against servers.""" + + def setUp(self): + self.write_network('port1.netdev', '''\ +[NetDev] +Name=port1 +Kind=dummy +MACAddress=12:34:56:78:9a:bc''') + self.write_network('port2.netdev', '''\ +[NetDev] +Name=port2 +Kind=dummy +MACAddress=12:34:56:78:9a:bd''') + self.write_network('mybridge.netdev', '''\ +[NetDev] +Name=mybridge +Kind=bridge''') + self.write_network('port1.network', '''\ +[Match] +Name=port1 +[Network] +Bridge=mybridge''') + self.write_network('port2.network', '''\ +[Match] +Name=port2 +[Network] +Bridge=mybridge''') + self.write_network('mybridge.network', '''\ +[Match] +Name=mybridge +[Network] +DNS=192.168.250.1 +Address=192.168.250.33/24 +Gateway=192.168.250.1''') + subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) + + def tearDown(self): + subprocess.check_call(['systemctl', 'stop', 'systemd-networkd']) + subprocess.check_call(['ip', 'link', 'del', 'mybridge']) + subprocess.check_call(['ip', 'link', 'del', 'port1']) + subprocess.check_call(['ip', 'link', 'del', 'port2']) + + def test_bridge_init(self): + self.assert_link_states( + port1='managed', + port2='managed', + mybridge='managed') + + def test_bridge_port_priority(self): + self.assertEqual(self.read_attr('port1', 'brport/priority'), '32') + self.write_network_dropin('port1.network', 'priority', '''\ +[Bridge] +Priority=28 +''') + subprocess.check_call(['systemctl', 'restart', 'systemd-networkd']) + self.assertEqual(self.read_attr('port1', 'brport/priority'), '28') + + def test_bridge_port_priority_set_zero(self): + """It should be possible to set the bridge port priority to 0""" + self.assertEqual(self.read_attr('port2', 'brport/priority'), '32') + self.write_network_dropin('port2.network', 'priority', '''\ +[Bridge] +Priority=0 +''') + subprocess.check_call(['systemctl', 'restart', 'systemd-networkd']) + self.assertEqual(self.read_attr('port2', 'brport/priority'), '0') + class ClientTestBase(NetworkdTestingUtilities): """Provide common methods for testing networkd against servers.""" diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py index dab01f1d8a..14739df493 100755 --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # Simple udev rules syntax checker # # (C) 2010 Canonical Ltd. diff --git a/test/sys-script.py b/test/sys-script.py index a9c0046667..6c9ee5ff83 100755 --- a/test/sys-script.py +++ b/test/sys-script.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # # sys-script.py # diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py index 16ea65690a..d116fffe38 100755 --- a/test/sysv-generator-test.py +++ b/test/sysv-generator-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # # systemd-sysv-generator integration test # diff --git a/test/test-efi-create-disk.sh b/test/test-efi-create-disk.sh index cd4699dc18..0216c83c12 100755 --- a/test/test-efi-create-disk.sh +++ b/test/test-efi-create-disk.sh @@ -1,30 +1,38 @@ #!/bin/bash -e +out="$1" +systemd_efi="$2" +boot_stub="$3" +splash_bmp="$4" +if [ -z "$out" -o -z "$systemd_efi" -o -z "$boot_stub" -o -z "$splash_bmp" ]; then + exit 1 +fi + # create GPT table with EFI System Partition -rm -f test-efi-disk.img -dd if=/dev/null of=test-efi-disk.img bs=1M seek=512 count=1 -parted --script test-efi-disk.img "mklabel gpt" "mkpart ESP fat32 1MiB 511MiB" "set 1 boot on" +rm -f "$out" +dd if=/dev/null of="$out" bs=1M seek=512 count=1 status=none +parted --script "$out" "mklabel gpt" "mkpart ESP fat32 1MiB 511MiB" "set 1 boot on" # create FAT32 file system -LOOP=$(losetup --show -f -P test-efi-disk.img) +LOOP=$(losetup --show -f -P "$out") mkfs.vfat -F32 ${LOOP}p1 mkdir -p mnt mount ${LOOP}p1 mnt mkdir -p mnt/EFI/{BOOT,systemd} -cp systemd-bootx64.efi mnt/EFI/BOOT/BOOTX64.efi +cp "$systemd_efi" mnt/EFI/BOOT/BOOTX64.efi [ -e /boot/shellx64.efi ] && cp /boot/shellx64.efi mnt/ mkdir mnt/EFI/Linux -echo -n "foo=yes bar=no root=/dev/fakeroot debug rd.break=initqueue" > mnt/cmdline.txt +echo -n "foo=yes bar=no root=/dev/fakeroot debug rd.break=initqueue" >mnt/cmdline.txt objcopy \ - --add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \ - --add-section .cmdline=mnt/cmdline.txt --change-section-vma .cmdline=0x30000 \ - --add-section .splash=test/splash.bmp --change-section-vma .splash=0x40000 \ - --add-section .linux=/boot/$(cat /etc/machine-id)/$(uname -r)/linux --change-section-vma .linux=0x2000000 \ - --add-section .initrd=/boot/$(cat /etc/machine-id)/$(uname -r)/initrd --change-section-vma .initrd=0x3000000 \ - linuxx64.efi.stub mnt/EFI/Linux/linux-test.efi + --add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \ + --add-section .cmdline=mnt/cmdline.txt --change-section-vma .cmdline=0x30000 \ + --add-section .splash="$splash_bmp" --change-section-vma .splash=0x40000 \ + --add-section .linux=/boot/$(cat /etc/machine-id)/$(uname -r)/linux --change-section-vma .linux=0x2000000 \ + --add-section .initrd=/boot/$(cat /etc/machine-id)/$(uname -r)/initrd --change-section-vma .initrd=0x3000000 \ + "$boot_stub" mnt/EFI/Linux/linux-test.efi # install entries mkdir -p mnt/loader/entries diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py new file mode 100755 index 0000000000..39a9e62e15 --- /dev/null +++ b/test/test-exec-deserialization.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 + +# +# Copyright 2017 Michal Sekletar <msekleta@redhat.com> +# +# 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/>. + +# ATTENTION: This uses the *installed* systemd, not the one from the built +# source tree. + +import unittest +import time +import os +import tempfile +import subprocess + +from enum import Enum + +class UnitFileChange(Enum): + NO_CHANGE = 0 + LINES_SWAPPED = 1 + COMMAND_ADDED_BEFORE = 2 + COMMAND_ADDED_AFTER = 3 + COMMAND_INTERLEAVED = 4 + REMOVAL = 5 + +class ExecutionResumeTest(unittest.TestCase): + def setUp(self): + self.unit = 'test-issue-518.service' + self.unitfile_path = '/run/systemd/system/{0}'.format(self.unit) + self.output_file = tempfile.mktemp() + self.unit_files = {} + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/sleep 2 + ExecStart=/bin/bash -c "echo foo >> {0}" + '''.format(self.output_file) + self.unit_files[UnitFileChange.NO_CHANGE] = unit_file_content + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/bash -c "echo foo >> {0}" + ExecStart=/bin/sleep 2 + '''.format(self.output_file) + self.unit_files[UnitFileChange.LINES_SWAPPED] = unit_file_content + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/bash -c "echo bar >> {0}" + ExecStart=/bin/sleep 2 + ExecStart=/bin/bash -c "echo foo >> {0}" + '''.format(self.output_file) + self.unit_files[UnitFileChange.COMMAND_ADDED_BEFORE] = unit_file_content + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/sleep 2 + ExecStart=/bin/bash -c "echo foo >> {0}" + ExecStart=/bin/bash -c "echo bar >> {0}" + '''.format(self.output_file) + self.unit_files[UnitFileChange.COMMAND_ADDED_AFTER] = unit_file_content + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/bash -c "echo baz >> {0}" + ExecStart=/bin/sleep 2 + ExecStart=/bin/bash -c "echo foo >> {0}" + ExecStart=/bin/bash -c "echo bar >> {0}" + '''.format(self.output_file) + self.unit_files[UnitFileChange.COMMAND_INTERLEAVED] = unit_file_content + + unit_file_content = ''' + [Service] + Type=oneshot + ExecStart=/bin/bash -c "echo bar >> {0}" + ExecStart=/bin/bash -c "echo baz >> {0}" + '''.format(self.output_file) + self.unit_files[UnitFileChange.REMOVAL] = unit_file_content + + def reload(self): + subprocess.check_call(['systemctl', 'daemon-reload']) + + def write_unit_file(self, unit_file_change): + if not isinstance(unit_file_change, UnitFileChange): + raise ValueError('Unknown unit file change') + + content = self.unit_files[unit_file_change] + + with open(self.unitfile_path, 'w') as f: + f.write(content) + + self.reload() + + def check_output(self, expected_output): + try: + with open(self.output_file, 'r') as log: + output = log.read() + except IOError: + self.fail() + + self.assertEqual(output, expected_output) + + def setup_unit(self): + self.write_unit_file(UnitFileChange.NO_CHANGE) + subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', self.unit]) + + def test_no_change(self): + expected_output = 'foo\n' + + self.setup_unit() + self.reload() + time.sleep(4) + + self.check_output(expected_output) + + def test_swapped(self): + expected_output = '' + + self.setup_unit() + self.write_unit_file(UnitFileChange.LINES_SWAPPED) + self.reload() + time.sleep(4) + + self.assertTrue(not os.path.exists(self.output_file)) + + def test_added_before(self): + expected_output = 'foo\n' + + self.setup_unit() + self.write_unit_file(UnitFileChange.COMMAND_ADDED_BEFORE) + self.reload() + time.sleep(4) + + self.check_output(expected_output) + + def test_added_after(self): + expected_output = 'foo\nbar\n' + + self.setup_unit() + self.write_unit_file(UnitFileChange.COMMAND_ADDED_AFTER) + self.reload() + time.sleep(4) + + self.check_output(expected_output) + + def test_interleaved(self): + expected_output = 'foo\nbar\n' + + self.setup_unit() + self.write_unit_file(UnitFileChange.COMMAND_INTERLEAVED) + self.reload() + time.sleep(4) + + self.check_output(expected_output) + + def test_removal(self): + self.setup_unit() + self.write_unit_file(UnitFileChange.REMOVAL) + self.reload() + time.sleep(4) + + self.assertTrue(not os.path.exists(self.output_file)) + + def tearDown(self): + for f in [self.output_file, self.unitfile_path]: + try: + os.remove(f) + except OSError: + # ignore error if log file doesn't exist + pass + + self.reload() + +if __name__ == '__main__': + unittest.main() diff --git a/test/test-execute/exec-inaccessiblepaths-mount-propagation.service b/test/test-execute/exec-inaccessiblepaths-mount-propagation.service index 23c6ff3f93..430a6b78c2 100644 --- a/test/test-execute/exec-inaccessiblepaths-mount-propagation.service +++ b/test/test-execute/exec-inaccessiblepaths-mount-propagation.service @@ -3,5 +3,5 @@ Description=Test to make sure that InaccessiblePaths= disconnect mount propagati [Service] InaccessiblePaths=-/i-dont-exist -ExecStart=/bin/sh -x -c 'mkdir -p /TEST; mount -t tmpfs tmpfs /TEST; grep TEST /proc/self/mountinfo && ! grep TEST /proc/$${PPID}/mountinfo && ! grep TEST /proc/1/mountinfo' +ExecStart=/bin/sh -x -c 'd=$$(mktemp -d -p /tmp); trap "umount \'$$d\' && rmdir \'$$d\'" EXIT; mount -t tmpfs tmpfs "$$d"; grep "$$d" /proc/self/mountinfo && ! grep "$$d" /proc/$${PPID}/mountinfo && ! grep "$$d" /proc/1/mountinfo' Type=oneshot diff --git a/test/test-execute/exec-inaccessiblepaths-proc.service b/test/test-execute/exec-inaccessiblepaths-proc.service new file mode 100644 index 0000000000..ebdb4843d1 --- /dev/null +++ b/test/test-execute/exec-inaccessiblepaths-proc.service @@ -0,0 +1,7 @@ +[Unit] +Description=Test to make sure that mount namespace setup works properly with the 'InaccessiblePaths=/proc' option + +[Service] +InaccessiblePaths=/proc +ExecStart=/bin/sh -x -c 'test "$$(stat -c %%a /proc)" = "0"' +Type=oneshot diff --git a/test/test-execute/exec-protectkernelmodules-yes-mount-propagation.service b/test/test-execute/exec-protectkernelmodules-yes-mount-propagation.service index e438783df3..07758121cd 100644 --- a/test/test-execute/exec-protectkernelmodules-yes-mount-propagation.service +++ b/test/test-execute/exec-protectkernelmodules-yes-mount-propagation.service @@ -3,5 +3,5 @@ Description=Test to make sure that passing ProtectKernelModules=yes disconnect m [Service] ProtectKernelModules=yes -ExecStart=/bin/sh -x -c 'mkdir -p /TEST; mount -t tmpfs tmpfs /TEST; grep TEST /proc/self/mountinfo && ! grep TEST /proc/$${PPID}/mountinfo && ! grep TEST /proc/1/mountinfo' +ExecStart=/bin/sh -x -c 'd=$$(mktemp -d -p /tmp); trap "umount \'$$d\' && rmdir \'$$d\'" EXIT; mount -t tmpfs tmpfs "$$d"; grep "$$d" /proc/self/mountinfo && ! grep "$$d" /proc/$${PPID}/mountinfo && ! grep "$$d" /proc/1/mountinfo' Type=oneshot diff --git a/test/test-execute/exec-readonlypaths-mount-propagation.service b/test/test-execute/exec-readonlypaths-mount-propagation.service index 237cbb2efb..7edb0daa36 100644 --- a/test/test-execute/exec-readonlypaths-mount-propagation.service +++ b/test/test-execute/exec-readonlypaths-mount-propagation.service @@ -3,5 +3,5 @@ Description=Test to make sure that passing ReadOnlyPaths= disconnect mount propa [Service] ReadOnlyPaths=-/i-dont-exist -ExecStart=/bin/sh -x -c 'mkdir -p /TEST; mount -t tmpfs tmpfs /TEST; grep TEST /proc/self/mountinfo && ! grep TEST /proc/$${PPID}/mountinfo && ! grep TEST /proc/1/mountinfo' +ExecStart=/bin/sh -x -c 'd=$$(mktemp -d -p /tmp); trap "umount \'$$d\' && rmdir \'$$d\'" EXIT; mount -t tmpfs tmpfs "$$d"; grep "$$d" /proc/self/mountinfo && ! grep "$$d" /proc/$${PPID}/mountinfo && ! grep "$$d" /proc/1/mountinfo' Type=oneshot diff --git a/test/test-execute/exec-readwritepaths-mount-propagation.service b/test/test-execute/exec-readwritepaths-mount-propagation.service index 466ce6c747..b38978df42 100644 --- a/test/test-execute/exec-readwritepaths-mount-propagation.service +++ b/test/test-execute/exec-readwritepaths-mount-propagation.service @@ -3,5 +3,5 @@ Description=Test to make sure that passing ReadWritePaths= disconnect mount prop [Service] ReadWritePaths=-/i-dont-exist -ExecStart=/bin/sh -x -c 'mkdir -p /TEST; mount -t tmpfs tmpfs /TEST; grep TEST /proc/self/mountinfo && ! grep TEST /proc/$${PPID}/mountinfo && ! grep TEST /proc/1/mountinfo' +ExecStart=/bin/sh -x -c 'd=$$(mktemp -d -p /tmp); trap "umount \'$$d\' && rmdir \'$$d\'" EXIT; mount -t tmpfs tmpfs "$$d"; grep "$$d" /proc/self/mountinfo && ! grep "$$d" /proc/$${PPID}/mountinfo && ! grep "$$d" /proc/1/mountinfo' Type=oneshot diff --git a/test/test-functions b/test/test-functions index fd7c198166..ea4f700841 100644 --- a/test/test-functions +++ b/test/test-functions @@ -6,12 +6,13 @@ export PATH LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes) LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes) +LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes) KERNEL_VER=${KERNEL_VER-$(uname -r)} KERNEL_MODS="/lib/modules/$KERNEL_VER/" QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}" NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-infinity}" TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out -FSTYPE="${FSTYPE:-ext3}" +[[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext3}" UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}" if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then @@ -73,6 +74,7 @@ run_qemu() { default_fedora_initrd=/boot/initramfs-${KERNEL_VER}.img default_debian_initrd=/boot/initrd.img-${KERNEL_VER} default_arch_initrd=/boot/initramfs-linux.img + default_suse_initrd=/boot/initrd-${KERNEL_VER} if [[ ! "$INITRD" ]]; then if [[ -e "$default_fedora_initrd" ]]; then INITRD="$default_fedora_initrd" @@ -80,6 +82,8 @@ run_qemu() { INITRD="$default_debian_initrd" elif [[ "$LOOKS_LIKE_ARCH" && -e "$default_arch_initrd" ]]; then INITRD="$default_arch_initrd" + elif [[ "$LOOKS_LIKE_SUSE" && -e "$default_suse_initrd" ]]; then + INITRD="$default_suse_initrd" fi fi @@ -99,11 +103,17 @@ run_qemu() { exit 1 fi - KERNEL_APPEND="root=/dev/sda1 \ +if [[ "$LOOKS_LIKE_SUSE" ]]; then + PARAMS+="rd.hostonly=0" +else + PARAMS+="ro" +fi + +KERNEL_APPEND="$PARAMS \ +root=/dev/sda1 \ raid=noautodetect \ loglevel=2 \ init=$ROOTLIBDIR/systemd \ -ro \ console=ttyS0 \ selinux=0 \ $_cgroup_args \ @@ -314,6 +324,8 @@ install_systemd() { # and it could fill the available space strip_binaries + [[ "$LOOKS_LIKE_SUSE" ]] && setup_suse + # enable debug logging in PID1 echo LogLevel=debug >> $initdir/etc/systemd/system.conf } @@ -442,8 +454,14 @@ install_config_files() { # set the hostname echo systemd-testsuite > $initdir/etc/hostname # fstab + if [[ "$LOOKS_LIKE_SUSE" ]]; then + ROOTMOUNT="/dev/sda1 / ${FSTYPE} rw 0 1" + else + ROOTMOUNT="LABEL=systemd / ${FSTYPE} rw 0 1" + fi + cat >$initdir/etc/fstab <<EOF -LABEL=systemd / ${FSTYPE} rw 0 1 +$ROOTMOUNT EOF } @@ -1336,6 +1354,12 @@ inst_libdir_file() { fi } +setup_suse() { + ln -s ../usr/bin/systemctl $initdir/bin/systemctl + ln -s ../usr/lib/systemd $initdir/lib/systemd + inst_simple "/usr/lib/systemd/system/haveged.service" +} + do_test() { if [[ $UID != "0" ]]; then echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2 |