test_cpio.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_CONF_FILES="{}"
  36. # BR2_TARGET_ROOTFS_TAR is not set
  37. """.format(" ".join(["fs/cpio/dracut.conf",
  38. "support/testing/tests/fs/test_cpio/dracut-cramfs.conf"]))
  39. def check_dracut(self):
  40. out = subprocess.check_output(["cpio", "--list"],
  41. stdin=open(os.path.join(self.builddir, "images/rootfs.cpio")),
  42. stderr=open(os.devnull, "w"),
  43. cwd=self.builddir,
  44. env={"LANG": "C"},
  45. universal_newlines=True)
  46. # pv should *not* be included in cpio image
  47. self.assertEqual(out.find("bin/pv"), -1)
  48. # libz should be, because of cramfs
  49. self.assertNotEqual(out.find("usr/bin/mkcramfs"), -1)
  50. self.assertNotEqual(out.find("usr/lib/libz.so"), -1)
  51. exit_code = boot_img(self.emulator,
  52. self.builddir)
  53. self.assertEqual(exit_code, 0)
  54. class TestCpioDracutUclibc(TestCpioDracutBase):
  55. config = TestCpioDracutBase.config + \
  56. """
  57. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
  58. """
  59. def test_run(self):
  60. self.check_dracut()
  61. class TestCpioDracutGlibc(TestCpioDracutBase):
  62. config = TestCpioDracutBase.config + \
  63. """
  64. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
  65. """
  66. def test_run(self):
  67. self.check_dracut()
  68. class TestCpioDracutMusl(TestCpioDracutBase):
  69. config = TestCpioDracutBase.config + \
  70. """
  71. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
  72. """
  73. def test_run(self):
  74. self.check_dracut()
  75. class TestCpioDracutUclibcMergedUsr(TestCpioDracutBase):
  76. config = TestCpioDracutBase.config + \
  77. """
  78. BR2_ROOTFS_MERGED_USR=y
  79. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
  80. """
  81. def test_run(self):
  82. self.check_dracut()
  83. class TestCpioDracutGlibcMergedUsr(TestCpioDracutBase):
  84. config = TestCpioDracutBase.config + \
  85. """
  86. BR2_ROOTFS_MERGED_USR=y
  87. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
  88. """
  89. def test_run(self):
  90. self.check_dracut()
  91. class TestCpioDracutMuslMergedUsr(TestCpioDracutBase):
  92. config = TestCpioDracutBase.config + \
  93. """
  94. BR2_ROOTFS_MERGED_USR=y
  95. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
  96. """
  97. def test_run(self):
  98. self.check_dracut()