2
1

test_cpio.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import os
  2. import infra.basetest
  3. import subprocess
  4. CHECK_FS_CMD = "mount | grep 'rootfs on / type rootfs'"
  5. def boot_img(emulator, builddir):
  6. img = os.path.join(builddir, "images", "rootfs.cpio")
  7. emulator.boot(arch="armv7",
  8. kernel="builtin",
  9. options=["-initrd", "{}".format(img)])
  10. emulator.login()
  11. _, exit_code = emulator.run(CHECK_FS_CMD)
  12. return exit_code
  13. class TestCpioFull(infra.basetest.BRTest):
  14. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  15. """
  16. BR2_INIT_BUSYBOX=y
  17. BR2_TARGET_ROOTFS_CPIO=y
  18. # BR2_TARGET_ROOTFS_TAR is not set
  19. """
  20. def test_run(self):
  21. exit_code = boot_img(self.emulator,
  22. self.builddir)
  23. self.assertEqual(exit_code, 0)
  24. class TestCpioDracutBase(infra.basetest.BRTest):
  25. config = \
  26. """
  27. BR2_arm=y
  28. BR2_TOOLCHAIN_EXTERNAL=y
  29. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  30. BR2_INIT_BUSYBOX=y
  31. BR2_PACKAGE_CRAMFS=y
  32. BR2_PACKAGE_PV=y
  33. BR2_TARGET_ROOTFS_CPIO=y
  34. BR2_TARGET_ROOTFS_CPIO_DRACUT=y
  35. BR2_TARGET_ROOTFS_CPIO_DRACUT_MODULES="{}"
  36. BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILES="{}"
  37. # BR2_TARGET_ROOTFS_TAR is not set
  38. """.format("support/testing/tests/fs/test_cpio/modules",
  39. " ".join(["fs/cpio/dracut.conf",
  40. "support/testing/tests/fs/test_cpio/dracut-cramfs.conf"]))
  41. def check_dracut(self):
  42. out = subprocess.check_output(["cpio", "--list"],
  43. stdin=open(os.path.join(self.builddir, "images/rootfs.cpio")),
  44. stderr=open(os.devnull, "w"),
  45. cwd=self.builddir,
  46. env={"LANG": "C"},
  47. universal_newlines=True)
  48. # pv should *not* be included in cpio image
  49. self.assertEqual(out.find("bin/pv"), -1)
  50. # libz should be, because of cramfs
  51. self.assertNotEqual(out.find("usr/bin/mkcramfs"), -1)
  52. self.assertNotEqual(out.find("usr/bin/cramfsck"), -1)
  53. self.assertNotEqual(out.find("usr/lib/libz.so"), -1)
  54. exit_code = boot_img(self.emulator,
  55. self.builddir)
  56. self.assertEqual(exit_code, 0)
  57. class TestCpioDracutUclibc(TestCpioDracutBase):
  58. config = TestCpioDracutBase.config + \
  59. """
  60. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
  61. """
  62. def test_run(self):
  63. self.check_dracut()
  64. class TestCpioDracutGlibc(TestCpioDracutBase):
  65. config = TestCpioDracutBase.config + \
  66. """
  67. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
  68. """
  69. def test_run(self):
  70. self.check_dracut()
  71. class TestCpioDracutMusl(TestCpioDracutBase):
  72. config = TestCpioDracutBase.config + \
  73. """
  74. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
  75. """
  76. def test_run(self):
  77. self.check_dracut()
  78. class TestCpioDracutUclibcMergedUsr(TestCpioDracutBase):
  79. config = TestCpioDracutBase.config + \
  80. """
  81. BR2_ROOTFS_MERGED_USR=y
  82. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
  83. """
  84. def test_run(self):
  85. self.check_dracut()
  86. class TestCpioDracutGlibcMergedUsr(TestCpioDracutBase):
  87. config = TestCpioDracutBase.config + \
  88. """
  89. BR2_ROOTFS_MERGED_USR=y
  90. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
  91. """
  92. def test_run(self):
  93. self.check_dracut()
  94. class TestCpioDracutMuslMergedUsr(TestCpioDracutBase):
  95. config = TestCpioDracutBase.config + \
  96. """
  97. BR2_ROOTFS_MERGED_USR=y
  98. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
  99. """
  100. def test_run(self):
  101. self.check_dracut()