test_iso9660.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import os
  2. import infra.basetest
  3. BASIC_CONFIG = \
  4. """
  5. BR2_x86_pentium4=y
  6. BR2_TOOLCHAIN_EXTERNAL=y
  7. BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
  8. BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
  9. BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-i386-pentium4-full-2017.05-1078-g95b1dae.tar.bz2"
  10. BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
  11. BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_2=y
  12. BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
  13. # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
  14. BR2_TOOLCHAIN_EXTERNAL_CXX=y
  15. BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
  16. BR2_TARGET_GENERIC_GETTY_BAUDRATE_115200=y
  17. BR2_LINUX_KERNEL=y
  18. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  19. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204"
  20. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  21. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="{}"
  22. # BR2_TARGET_ROOTFS_TAR is not set
  23. """.format(infra.filepath("conf/minimal-x86-qemu-kernel.config"))
  24. def test_mount_internal_external(emulator, builddir, internal=True, efi=False):
  25. img = os.path.join(builddir, "images", "rootfs.iso9660")
  26. if efi:
  27. efi_img = os.path.join(builddir, "images", "OVMF.fd")
  28. # In QEMU v5.1.0 up to v7.2.0, the CPU hotplug register block misbehaves.
  29. # EDK2 hang if the bug is detected in Qemu after printing errors to IO port 0x402
  30. # (requires BR2_TARGET_EDK2_OVMF_DEBUG_ON_SERIAL to see them)
  31. # The Docker image used by the Buildroot gitlab-ci uses Qemu 5.2.0, the workaround
  32. # can be removed as soon as the Docker image is updated to provided Qemu >= 8.0.0.
  33. # This workaround is needed only when efi=True since it imply EDK2 is used.
  34. # https://github.com/tianocore/edk2/commit/bf5678b5802685e07583e3c7ec56d883cbdd5da3
  35. # http://lists.busybox.net/pipermail/buildroot/2023-July/670825.html
  36. qemu_fw_cfg = "name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes"
  37. emulator.boot(arch="i386", options=["-cdrom", img, "-bios", efi_img, "-fw_cfg", qemu_fw_cfg])
  38. else:
  39. emulator.boot(arch="i386", options=["-cdrom", img])
  40. emulator.login()
  41. if internal:
  42. cmd = "mount | grep 'rootfs on / type rootfs'"
  43. else:
  44. cmd = "mount | grep '/dev/root on / type iso9660'"
  45. _, exit_code = emulator.run(cmd)
  46. return exit_code
  47. def test_touch_file(emulator):
  48. _, exit_code = emulator.run("touch test")
  49. return exit_code
  50. #
  51. # Grub 2
  52. class TestIso9660Grub2External(infra.basetest.BRTest):
  53. config = BASIC_CONFIG + \
  54. """
  55. BR2_TARGET_ROOTFS_ISO9660=y
  56. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  57. BR2_TARGET_GRUB2=y
  58. BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
  59. BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660"
  60. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  61. """.format(infra.filepath("conf/grub2.cfg"))
  62. def test_run(self):
  63. exit_code = test_mount_internal_external(self.emulator,
  64. self.builddir, internal=False)
  65. self.assertEqual(exit_code, 0)
  66. exit_code = test_touch_file(self.emulator)
  67. self.assertEqual(exit_code, 1)
  68. class TestIso9660Grub2ExternalCompress(infra.basetest.BRTest):
  69. config = BASIC_CONFIG + \
  70. """
  71. BR2_TARGET_ROOTFS_ISO9660=y
  72. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  73. BR2_TARGET_ROOTFS_ISO9660_TRANSPARENT_COMPRESSION=y
  74. BR2_TARGET_GRUB2=y
  75. BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
  76. BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660"
  77. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  78. """.format(infra.filepath("conf/grub2.cfg"))
  79. def test_run(self):
  80. exit_code = test_mount_internal_external(self.emulator,
  81. self.builddir, internal=False)
  82. self.assertEqual(exit_code, 0)
  83. exit_code = test_touch_file(self.emulator)
  84. self.assertEqual(exit_code, 1)
  85. class TestIso9660Grub2Internal(infra.basetest.BRTest):
  86. config = BASIC_CONFIG + \
  87. """
  88. BR2_TARGET_ROOTFS_ISO9660=y
  89. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  90. BR2_TARGET_GRUB2=y
  91. BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
  92. BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660"
  93. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  94. """.format(infra.filepath("conf/grub2.cfg"))
  95. def test_run(self):
  96. exit_code = test_mount_internal_external(self.emulator,
  97. self.builddir, internal=True)
  98. self.assertEqual(exit_code, 0)
  99. exit_code = test_touch_file(self.emulator)
  100. self.assertEqual(exit_code, 0)
  101. class TestIso9660Grub2EFI(infra.basetest.BRTest):
  102. config = BASIC_CONFIG + \
  103. """
  104. BR2_TARGET_ROOTFS_ISO9660=y
  105. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  106. BR2_TARGET_GRUB2=y
  107. BR2_TARGET_GRUB2_I386_EFI=y
  108. BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat part_msdos part_gpt normal iso9660"
  109. BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="{}"
  110. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  111. BR2_TARGET_EDK2=y
  112. """.format(infra.filepath("conf/grub2-efi.cfg"),
  113. infra.filepath("conf/grub2.cfg"))
  114. def test_run(self):
  115. exit_code = test_mount_internal_external(self.emulator,
  116. self.builddir, internal=True,
  117. efi=True)
  118. self.assertEqual(exit_code, 0)
  119. exit_code = test_touch_file(self.emulator)
  120. self.assertEqual(exit_code, 0)
  121. class TestIso9660Grub2Hybrid(infra.basetest.BRTest):
  122. config = BASIC_CONFIG + \
  123. """
  124. BR2_TARGET_ROOTFS_ISO9660=y
  125. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  126. BR2_TARGET_GRUB2=y
  127. BR2_TARGET_GRUB2_I386_PC=y
  128. BR2_TARGET_GRUB2_I386_EFI=y
  129. BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
  130. BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 biosdisk"
  131. BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC=""
  132. BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 efi_gop"
  133. BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="{}"
  134. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  135. BR2_TARGET_EDK2=y
  136. """.format(infra.filepath("conf/grub2-efi.cfg"),
  137. infra.filepath("conf/grub2.cfg"))
  138. def test_run(self):
  139. exit_code = test_mount_internal_external(self.emulator,
  140. self.builddir, internal=True,
  141. efi=False)
  142. self.assertEqual(exit_code, 0)
  143. exit_code = test_touch_file(self.emulator)
  144. self.assertEqual(exit_code, 0)
  145. self.emulator.stop()
  146. exit_code = test_mount_internal_external(self.emulator,
  147. self.builddir, internal=True,
  148. efi=True)
  149. self.assertEqual(exit_code, 0)
  150. exit_code = test_touch_file(self.emulator)
  151. self.assertEqual(exit_code, 0)
  152. #
  153. # Syslinux
  154. class TestIso9660SyslinuxExternal(infra.basetest.BRTest):
  155. config = BASIC_CONFIG + \
  156. """
  157. BR2_TARGET_ROOTFS_ISO9660=y
  158. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  159. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  160. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  161. BR2_TARGET_SYSLINUX=y
  162. """.format(infra.filepath("conf/isolinux.cfg"))
  163. def test_run(self):
  164. exit_code = test_mount_internal_external(self.emulator,
  165. self.builddir, internal=False)
  166. self.assertEqual(exit_code, 0)
  167. exit_code = test_touch_file(self.emulator)
  168. self.assertEqual(exit_code, 1)
  169. class TestIso9660SyslinuxExternalCompress(infra.basetest.BRTest):
  170. config = BASIC_CONFIG + \
  171. """
  172. BR2_TARGET_ROOTFS_ISO9660=y
  173. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  174. BR2_TARGET_ROOTFS_ISO9660_TRANSPARENT_COMPRESSION=y
  175. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  176. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  177. BR2_TARGET_SYSLINUX=y
  178. """.format(infra.filepath("conf/isolinux.cfg"))
  179. def test_run(self):
  180. exit_code = test_mount_internal_external(self.emulator,
  181. self.builddir, internal=False)
  182. self.assertEqual(exit_code, 0)
  183. exit_code = test_touch_file(self.emulator)
  184. self.assertEqual(exit_code, 1)
  185. class TestIso9660SyslinuxInternal(infra.basetest.BRTest):
  186. config = BASIC_CONFIG + \
  187. """
  188. BR2_TARGET_ROOTFS_ISO9660=y
  189. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  190. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  191. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  192. BR2_TARGET_SYSLINUX=y
  193. """.format(infra.filepath("conf/isolinux.cfg"))
  194. def test_run(self):
  195. exit_code = test_mount_internal_external(self.emulator,
  196. self.builddir, internal=True)
  197. self.assertEqual(exit_code, 0)
  198. exit_code = test_touch_file(self.emulator)
  199. self.assertEqual(exit_code, 0)