test_cpio.py 3.3 KB

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