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