]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/tests/init/test_systemd.py
support/tests: enhance the runtime systemd tests
[coffee/buildroot.git] / support / testing / tests / init / test_systemd.py
1 import infra.basetest
2 from tests.init.base import InitSystemBase as InitSystemBase
3
4
5 class InitSystemSystemdBase(InitSystemBase):
6     config = \
7         """
8         BR2_arm=y
9         BR2_TOOLCHAIN_EXTERNAL=y
10         BR2_INIT_SYSTEMD=y
11         BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
12         BR2_LINUX_KERNEL=y
13         BR2_LINUX_KERNEL_CUSTOM_VERSION=y
14         BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.11.3"
15         BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
16         BR2_LINUX_KERNEL_DTS_SUPPORT=y
17         BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
18         # BR2_TARGET_ROOTFS_TAR is not set
19         """
20
21     def check_init(self):
22         super(InitSystemSystemdBase, self).check_init("/lib/systemd/systemd")
23
24         # Test all units are OK
25         output, _ = self.emulator.run("systemctl --no-pager --failed --no-legend")
26         self.assertEqual(len(output), 0)
27
28         # Test we can reach the DBus daemon
29         _, exit_code = self.emulator.run("busctl --no-pager")
30         self.assertEqual(exit_code, 0)
31
32         # Test we can read at least one line from the journal
33         output, _ = self.emulator.run("journalctl --no-pager --lines 1 --quiet")
34         self.assertEqual(len(output), 1)
35
36
37 class TestInitSystemSystemdRoNetworkd(InitSystemSystemdBase):
38     config = InitSystemSystemdBase.config + \
39         """
40         BR2_SYSTEM_DHCP="eth0"
41         # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
42         BR2_ROOTFS_OVERLAY="{}"
43         BR2_TARGET_ROOTFS_SQUASHFS=y
44         """.format(infra.filepath("tests/init/systemd-factory"))
45
46     def test_run(self):
47         self.start_emulator("squashfs", "zImage", "vexpress-v2p-ca9")
48         self.check_init()
49         self.check_network("eth0")
50
51         # This one must be executed on the target, to check that
52         # the factory feature works as expected
53         out, exit_code = self.emulator.run("cat /var/foo/bar")
54         self.assertEqual(exit_code, 0)
55         self.assertEqual(out[0], "foobar")
56
57
58 class TestInitSystemSystemdRwNetworkd(InitSystemSystemdBase):
59     config = InitSystemSystemdBase.config + \
60         """
61         BR2_SYSTEM_DHCP="eth0"
62         BR2_TARGET_ROOTFS_EXT2=y
63         """
64
65     def test_run(self):
66         self.start_emulator("ext2", "zImage", "vexpress-v2p-ca9")
67         self.check_init()
68         self.check_network("eth0")
69
70
71 class TestInitSystemSystemdRoIfupdown(InitSystemSystemdBase):
72     config = InitSystemSystemdBase.config + \
73         """
74         BR2_SYSTEM_DHCP="eth0"
75         # BR2_PACKAGE_SYSTEMD_NETWORKD is not set
76         # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
77         BR2_TARGET_ROOTFS_SQUASHFS=y
78         """
79
80     def test_run(self):
81         self.start_emulator("squashfs", "zImage", "vexpress-v2p-ca9")
82         self.check_init()
83         self.check_network("eth0")
84
85
86 class TestInitSystemSystemdRwIfupdown(InitSystemSystemdBase):
87     config = InitSystemSystemdBase.config + \
88         """
89         BR2_SYSTEM_DHCP="eth0"
90         # BR2_PACKAGE_SYSTEMD_NETWORKD is not set
91         # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
92         BR2_TARGET_ROOTFS_EXT2=y
93         """
94
95     def test_run(self):
96         self.start_emulator("ext2", "zImage", "vexpress-v2p-ca9")
97         self.check_init()
98         self.check_network("eth0")
99
100
101 class TestInitSystemSystemdRoFull(InitSystemSystemdBase):
102     config = InitSystemSystemdBase.config + \
103         """
104         BR2_SYSTEM_DHCP="eth0"
105         # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
106         BR2_PACKAGE_SYSTEMD_JOURNAL_GATEWAY=y
107         BR2_PACKAGE_SYSTEMD_BACKLIGHT=y
108         BR2_PACKAGE_SYSTEMD_BINFMT=y
109         BR2_PACKAGE_SYSTEMD_COREDUMP=y
110         BR2_PACKAGE_SYSTEMD_FIRSTBOOT=y
111         BR2_PACKAGE_SYSTEMD_HIBERNATE=y
112         BR2_PACKAGE_SYSTEMD_IMPORTD=y
113         BR2_PACKAGE_SYSTEMD_LOCALED=y
114         BR2_PACKAGE_SYSTEMD_LOGIND=y
115         BR2_PACKAGE_SYSTEMD_MACHINED=y
116         BR2_PACKAGE_SYSTEMD_POLKIT=y
117         BR2_PACKAGE_SYSTEMD_QUOTACHECK=y
118         BR2_PACKAGE_SYSTEMD_RANDOMSEED=y
119         BR2_PACKAGE_SYSTEMD_RFKILL=y
120         BR2_PACKAGE_SYSTEMD_SMACK_SUPPORT=y
121         BR2_PACKAGE_SYSTEMD_SYSUSERS=y
122         BR2_PACKAGE_SYSTEMD_VCONSOLE=y
123         BR2_TARGET_ROOTFS_SQUASHFS=y
124         """
125
126     def test_run(self):
127         self.start_emulator("squashfs", "zImage", "vexpress-v2p-ca9")
128         self.check_init()
129         self.check_network("eth0")
130
131
132 class TestInitSystemSystemdRwFull(InitSystemSystemdBase):
133     config = InitSystemSystemdBase.config + \
134         """
135         BR2_SYSTEM_DHCP="eth0"
136         BR2_PACKAGE_SYSTEMD_JOURNAL_GATEWAY=y
137         BR2_PACKAGE_SYSTEMD_BACKLIGHT=y
138         BR2_PACKAGE_SYSTEMD_BINFMT=y
139         BR2_PACKAGE_SYSTEMD_COREDUMP=y
140         BR2_PACKAGE_SYSTEMD_FIRSTBOOT=y
141         BR2_PACKAGE_SYSTEMD_HIBERNATE=y
142         BR2_PACKAGE_SYSTEMD_IMPORTD=y
143         BR2_PACKAGE_SYSTEMD_LOCALED=y
144         BR2_PACKAGE_SYSTEMD_LOGIND=y
145         BR2_PACKAGE_SYSTEMD_MACHINED=y
146         BR2_PACKAGE_SYSTEMD_POLKIT=y
147         BR2_PACKAGE_SYSTEMD_QUOTACHECK=y
148         BR2_PACKAGE_SYSTEMD_RANDOMSEED=y
149         BR2_PACKAGE_SYSTEMD_RFKILL=y
150         BR2_PACKAGE_SYSTEMD_SMACK_SUPPORT=y
151         BR2_PACKAGE_SYSTEMD_SYSUSERS=y
152         BR2_PACKAGE_SYSTEMD_VCONSOLE=y
153         BR2_TARGET_ROOTFS_EXT2=y
154         """
155
156     def test_run(self):
157         self.start_emulator("ext2", "zImage", "vexpress-v2p-ca9")
158         self.check_init()
159         self.check_network("eth0")