test_systemd.py 5.3 KB

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