test_systemd.py 6.0 KB

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