test_iso9660.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 __init__(self, names):
  115. """Setup common test variables."""
  116. super(TestIso9660Grub2EFI, self).__init__(names)
  117. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  118. anymore due to a missing git submodule as reported by [1].
  119. Usually Buildroot fall-back using https://sources.buildroot.net
  120. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  121. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  122. value while generating the .config used by TestIso9660Grub2EFI.
  123. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  124. to continue testing EDK2 package using the usual backup site.
  125. To be removed with the next EDK2 version bump using this commit
  126. [2].
  127. [1] https://github.com/tianocore/edk2/issues/6398
  128. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  129. """
  130. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  131. def test_run(self):
  132. exit_code = test_mount_internal_external(self.emulator,
  133. self.builddir, internal=True,
  134. efi=True)
  135. self.assertEqual(exit_code, 0)
  136. exit_code = test_touch_file(self.emulator)
  137. self.assertEqual(exit_code, 0)
  138. class TestIso9660Grub2Hybrid(infra.basetest.BRTest):
  139. config = BASIC_CONFIG + \
  140. """
  141. BR2_TARGET_ROOTFS_ISO9660=y
  142. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  143. BR2_TARGET_GRUB2=y
  144. BR2_TARGET_GRUB2_I386_PC=y
  145. BR2_TARGET_GRUB2_I386_EFI=y
  146. BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
  147. BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 biosdisk"
  148. BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC=""
  149. BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 efi_gop"
  150. BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="{}"
  151. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  152. BR2_TARGET_EDK2=y
  153. """.format(infra.filepath("conf/grub2-efi.cfg"),
  154. infra.filepath("conf/grub2.cfg"))
  155. def __init__(self, names):
  156. """Setup common test variables."""
  157. super(TestIso9660Grub2Hybrid, self).__init__(names)
  158. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  159. anymore due to a missing git submodule as reported by [1].
  160. Usually Buildroot fall-back using https://sources.buildroot.net
  161. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  162. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  163. value while generating the .config used by TestIso9660Grub2Hybrid.
  164. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  165. to continue testing EDK2 package using the usual backup site.
  166. To be removed with the next EDK2 version bump using this commit
  167. [2].
  168. [1] https://github.com/tianocore/edk2/issues/6398
  169. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  170. """
  171. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  172. def test_run(self):
  173. exit_code = test_mount_internal_external(self.emulator,
  174. self.builddir, internal=True,
  175. efi=False)
  176. self.assertEqual(exit_code, 0)
  177. exit_code = test_touch_file(self.emulator)
  178. self.assertEqual(exit_code, 0)
  179. self.emulator.stop()
  180. exit_code = test_mount_internal_external(self.emulator,
  181. self.builddir, internal=True,
  182. efi=True)
  183. self.assertEqual(exit_code, 0)
  184. exit_code = test_touch_file(self.emulator)
  185. self.assertEqual(exit_code, 0)
  186. #
  187. # Syslinux
  188. class TestIso9660SyslinuxExternal(infra.basetest.BRTest):
  189. config = BASIC_CONFIG + \
  190. """
  191. BR2_TARGET_ROOTFS_ISO9660=y
  192. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  193. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  194. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  195. BR2_TARGET_SYSLINUX=y
  196. """.format(infra.filepath("conf/isolinux.cfg"))
  197. def test_run(self):
  198. exit_code = test_mount_internal_external(self.emulator,
  199. self.builddir, internal=False)
  200. self.assertEqual(exit_code, 0)
  201. exit_code = test_touch_file(self.emulator)
  202. self.assertEqual(exit_code, 1)
  203. class TestIso9660SyslinuxExternalCompress(infra.basetest.BRTest):
  204. config = BASIC_CONFIG + \
  205. """
  206. BR2_TARGET_ROOTFS_ISO9660=y
  207. # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set
  208. BR2_TARGET_ROOTFS_ISO9660_TRANSPARENT_COMPRESSION=y
  209. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  210. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  211. BR2_TARGET_SYSLINUX=y
  212. """.format(infra.filepath("conf/isolinux.cfg"))
  213. def test_run(self):
  214. exit_code = test_mount_internal_external(self.emulator,
  215. self.builddir, internal=False)
  216. self.assertEqual(exit_code, 0)
  217. exit_code = test_touch_file(self.emulator)
  218. self.assertEqual(exit_code, 1)
  219. class TestIso9660SyslinuxInternal(infra.basetest.BRTest):
  220. config = BASIC_CONFIG + \
  221. """
  222. BR2_TARGET_ROOTFS_ISO9660=y
  223. BR2_TARGET_ROOTFS_ISO9660_INITRD=y
  224. BR2_TARGET_ROOTFS_ISO9660_HYBRID=y
  225. BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}"
  226. BR2_TARGET_SYSLINUX=y
  227. """.format(infra.filepath("conf/isolinux.cfg"))
  228. def test_run(self):
  229. exit_code = test_mount_internal_external(self.emulator,
  230. self.builddir, internal=True)
  231. self.assertEqual(exit_code, 0)
  232. exit_code = test_touch_file(self.emulator)
  233. self.assertEqual(exit_code, 0)