2
1

test_grub.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import os
  2. import infra.basetest
  3. class TestGrubi386BIOS(infra.basetest.BRTest):
  4. config = \
  5. """
  6. BR2_x86_core2=y
  7. BR2_TOOLCHAIN_EXTERNAL=y
  8. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y
  9. BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}"
  10. BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
  11. BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg"
  12. BR2_LINUX_KERNEL=y
  13. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  14. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204"
  15. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  16. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config"
  17. BR2_LINUX_KERNEL_INSTALL_TARGET=y
  18. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  19. BR2_TARGET_ROOTFS_EXT2=y
  20. BR2_TARGET_GRUB2=y
  21. BR2_TARGET_GRUB2_I386_PC=y
  22. BR2_TARGET_GRUB2_INSTALL_TOOLS=y
  23. BR2_PACKAGE_HOST_GENIMAGE=y
  24. """.format(infra.filepath("tests/boot/test_grub/post-build.sh"))
  25. def test_run(self):
  26. hda = os.path.join(self.builddir, "images", "disk.img")
  27. self.emulator.boot(arch="i386", options=["-hda", hda])
  28. self.emulator.login()
  29. class TestGrubi386EFI(infra.basetest.BRTest):
  30. config = \
  31. """
  32. BR2_x86_core2=y
  33. BR2_TOOLCHAIN_EXTERNAL=y
  34. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y
  35. BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}"
  36. BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh"
  37. BR2_LINUX_KERNEL=y
  38. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  39. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204"
  40. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  41. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config"
  42. BR2_LINUX_KERNEL_INSTALL_TARGET=y
  43. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  44. BR2_PACKAGE_EFIVAR=y
  45. BR2_TARGET_ROOTFS_EXT2=y
  46. BR2_TARGET_EDK2=y
  47. BR2_TARGET_GRUB2=y
  48. BR2_TARGET_GRUB2_I386_EFI=y
  49. BR2_TARGET_GRUB2_INSTALL_TOOLS=y
  50. BR2_PACKAGE_HOST_GENIMAGE=y
  51. BR2_PACKAGE_HOST_MTOOLS=y
  52. BR2_PACKAGE_HOST_DOSFSTOOLS=y
  53. """.format(infra.filepath("tests/boot/test_grub/post-build.sh"))
  54. def __init__(self, names):
  55. """Setup common test variables."""
  56. super(TestGrubi386EFI, self).__init__(names)
  57. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  58. anymore due to a missing git submodule as reported by [1].
  59. Usually Buildroot fall-back using https://sources.buildroot.net
  60. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  61. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  62. value while generating the .config used by TestGrubi386EFI.
  63. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  64. to continue testing EDK2 package using the usual backup site.
  65. To be removed with the next EDK2 version bump using this commit
  66. [2].
  67. [1] https://github.com/tianocore/edk2/issues/6398
  68. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  69. """
  70. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  71. def test_run(self):
  72. hda = os.path.join(self.builddir, "images", "disk.img")
  73. bios = os.path.join(self.builddir, "images", "OVMF.fd")
  74. # In QEMU v5.1.0 up to v7.2.0, the CPU hotplug register block misbehaves.
  75. # EDK2 hang if the bug is detected in Qemu after printing errors to IO port 0x402
  76. # (requires BR2_TARGET_EDK2_OVMF_DEBUG_ON_SERIAL to see them)
  77. # The Docker image used by the Buildroot gitlab-ci uses Qemu 5.2.0, the workaround
  78. # can be removed as soon as the Docker image is updated to provided Qemu >= 8.0.0.
  79. # https://github.com/tianocore/edk2/commit/bf5678b5802685e07583e3c7ec56d883cbdd5da3
  80. # http://lists.busybox.net/pipermail/buildroot/2023-July/670825.html
  81. qemu_fw_cfg = "name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes"
  82. self.emulator.boot(arch="i386", options=["-bios", bios, "-hda", hda, "-fw_cfg", qemu_fw_cfg])
  83. self.emulator.login()
  84. cmd = "modprobe efivarfs"
  85. self.assertRunOk(cmd)
  86. cmd = "mount -t efivarfs none /sys/firmware/efi/efivars"
  87. self.assertRunOk(cmd)
  88. cmd = "efivar -l"
  89. self.assertRunOk(cmd)
  90. class TestGrubX8664EFI(infra.basetest.BRTest):
  91. config = \
  92. """
  93. BR2_x86_64=y
  94. BR2_x86_corei7=y
  95. BR2_TOOLCHAIN_EXTERNAL=y
  96. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_UCLIBC_STABLE=y
  97. BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}"
  98. BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh"
  99. BR2_LINUX_KERNEL=y
  100. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  101. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204"
  102. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  103. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config"
  104. BR2_LINUX_KERNEL_INSTALL_TARGET=y
  105. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  106. BR2_PACKAGE_EFIVAR=y
  107. BR2_TARGET_ROOTFS_EXT2=y
  108. BR2_TARGET_EDK2=y
  109. BR2_TARGET_GRUB2=y
  110. BR2_TARGET_GRUB2_X86_64_EFI=y
  111. BR2_TARGET_GRUB2_INSTALL_TOOLS=y
  112. BR2_PACKAGE_HOST_GENIMAGE=y
  113. BR2_PACKAGE_HOST_MTOOLS=y
  114. BR2_PACKAGE_HOST_DOSFSTOOLS=y
  115. """.format(infra.filepath("tests/boot/test_grub/post-build.sh"))
  116. def __init__(self, names):
  117. """Setup common test variables."""
  118. super(TestGrubX8664EFI, self).__init__(names)
  119. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  120. anymore due to a missing git submodule as reported by [1].
  121. Usually Buildroot fall-back using https://sources.buildroot.net
  122. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  123. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  124. value while generating the .config used by TestGrubX8664EFI.
  125. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  126. to continue testing EDK2 package using the usual backup site.
  127. To be removed with the next EDK2 version bump using this commit
  128. [2].
  129. [1] https://github.com/tianocore/edk2/issues/6398
  130. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  131. """
  132. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  133. def test_run(self):
  134. hda = os.path.join(self.builddir, "images", "disk.img")
  135. bios = os.path.join(self.builddir, "images", "OVMF.fd")
  136. # In QEMU v5.1.0 up to v7.2.0, the CPU hotplug register block misbehaves.
  137. # EDK2 hang if the bug is detected in Qemu after printing errors to IO port 0x402
  138. # (requires BR2_TARGET_EDK2_OVMF_DEBUG_ON_SERIAL to see them)
  139. # The Docker image used by the Buildroot gitlab-ci uses Qemu 5.2.0, the workaround
  140. # can be removed as soon as the Docker image is updated to provided Qemu >= 8.0.0.
  141. # https://github.com/tianocore/edk2/commit/bf5678b5802685e07583e3c7ec56d883cbdd5da3
  142. # http://lists.busybox.net/pipermail/buildroot/2023-July/670825.html
  143. qemu_fw_cfg = "name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes"
  144. self.emulator.boot(arch="x86_64", options=["-bios", bios, "-cpu", "Nehalem", "-hda", hda, "-fw_cfg", qemu_fw_cfg])
  145. self.emulator.login()
  146. cmd = "modprobe efivarfs"
  147. self.assertRunOk(cmd)
  148. cmd = "mount -t efivarfs none /sys/firmware/efi/efivars"
  149. self.assertRunOk(cmd)
  150. cmd = "efivar -l"
  151. self.assertRunOk(cmd)
  152. class TestGrubAArch64EFI(infra.basetest.BRTest):
  153. config = \
  154. """
  155. BR2_aarch64=y
  156. BR2_TOOLCHAIN_EXTERNAL=y
  157. BR2_ROOTFS_POST_IMAGE_SCRIPT="{post_image}"
  158. BR2_LINUX_KERNEL=y
  159. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  160. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.18"
  161. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  162. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  163. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{linux_fragment}"
  164. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  165. BR2_PACKAGE_EFIVAR=y
  166. BR2_TARGET_ROOTFS_EXT2=y
  167. BR2_TARGET_EDK2=y
  168. BR2_TARGET_GRUB2=y
  169. BR2_PACKAGE_HOST_GENIMAGE=y
  170. BR2_PACKAGE_HOST_MTOOLS=y
  171. BR2_PACKAGE_HOST_DOSFSTOOLS=y
  172. BR2_PACKAGE_HOST_QEMU=y
  173. BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
  174. """.format(post_image=infra.filepath("tests/boot/test_grub/post-image-aarch64-efi.sh"),
  175. linux_fragment=infra.filepath("tests/boot/test_grub/linux-aarch64-efi.config"))
  176. def __init__(self, names):
  177. """Setup common test variables."""
  178. super(TestGrubAArch64EFI, self).__init__(names)
  179. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  180. anymore due to a missing git submodule as reported by [1].
  181. Usually Buildroot fall-back using https://sources.buildroot.net
  182. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  183. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  184. value while generating the .config used by TestGrubAArch64EFI.
  185. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  186. to continue testing EDK2 package using the usual backup site.
  187. To be removed with the next EDK2 version bump using this commit
  188. [2].
  189. [1] https://github.com/tianocore/edk2/issues/6398
  190. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  191. """
  192. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  193. def test_run(self):
  194. hda = os.path.join(self.builddir, "images", "disk.img")
  195. bios = os.path.join(self.builddir, "images", "QEMU_EFI.fd")
  196. self.emulator.boot(arch="aarch64", options=["-M", "virt", "-cpu", "cortex-a53", "-bios", bios, "-hda", hda])
  197. self.emulator.login()
  198. cmd = "modprobe efivarfs"
  199. self.assertRunOk(cmd)
  200. cmd = "mount -t efivarfs none /sys/firmware/efi/efivars"
  201. self.assertRunOk(cmd)
  202. cmd = "efivar -l"
  203. self.assertRunOk(cmd)
  204. class TestGrubRiscV64EFI(infra.basetest.BRTest):
  205. scripts = [
  206. "board/qemu/post-image.sh",
  207. "board/qemu/riscv64-virt-efi/assemble-flash-images",
  208. "support/scripts/genimage.sh"
  209. ]
  210. post_image_script = " ".join(scripts)
  211. config = \
  212. f"""
  213. BR2_riscv=y
  214. BR2_TOOLCHAIN_EXTERNAL=y
  215. BR2_ROOTFS_POST_IMAGE_SCRIPT="{post_image_script}"
  216. BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/qemu/riscv64-virt-efi/genimage.cfg"
  217. BR2_LINUX_KERNEL=y
  218. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  219. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.6.59"
  220. BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
  221. BR2_PACKAGE_EFIVAR=y
  222. BR2_TARGET_ROOTFS_EXT2=y
  223. # BR2_TARGET_ROOTFS_TAR is not set
  224. BR2_TARGET_EDK2=y
  225. BR2_TARGET_GRUB2=y
  226. BR2_TARGET_GRUB2_RISCV64_EFI=y
  227. BR2_PACKAGE_HOST_DOSFSTOOLS=y
  228. BR2_PACKAGE_HOST_GENIMAGE=y
  229. BR2_PACKAGE_HOST_MTOOLS=y
  230. BR2_PACKAGE_HOST_QEMU=y
  231. BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
  232. """
  233. def __init__(self, names):
  234. """Setup common test variables."""
  235. super(TestGrubRiscV64EFI, self).__init__(names)
  236. """All EDK2 releases <= edk2-stable202408 can't be fetched from git
  237. anymore due to a missing git submodule as reported by [1].
  238. Usually Buildroot fall-back using https://sources.buildroot.net
  239. thanks to BR2_BACKUP_SITE where a backup of the generated archive
  240. is available. But the BRConfigTest remove BR2_BACKUP_SITE default
  241. value while generating the .config used by TestGrubAArch64EFI.
  242. Replace the BR2_BACKUP_SITE override from BRConfigTest in order
  243. to continue testing EDK2 package using the usual backup site.
  244. To be removed with the next EDK2 version bump using this commit
  245. [2].
  246. [1] https://github.com/tianocore/edk2/issues/6398
  247. [2] https://github.com/tianocore/edk2/commit/95d8a1c255cfb8e063d679930d08ca6426eb5701
  248. """
  249. self.config = self.config.replace('BR2_BACKUP_SITE=""\n', '')
  250. def test_run(self):
  251. disk = os.path.join(self.builddir, "images", "disk.img")
  252. flash0 = os.path.join(self.builddir, "images", "RISCV_VIRT_CODE.fd")
  253. flash1 = os.path.join(self.builddir, "images", "RISCV_VIRT_VARS.fd")
  254. qemu_opts = [
  255. "-M", "virt,pflash0=pflash0,pflash1=pflash1,acpi=off",
  256. "-blockdev", f"node-name=pflash0,driver=file,read-only=on,filename={flash0}",
  257. "-blockdev", f"node-name=pflash1,driver=file,filename={flash1}",
  258. "-drive", f"file={disk},format=raw,if=virtio"
  259. ]
  260. self.emulator.boot(arch="riscv64", options=qemu_opts)
  261. self.emulator.login()
  262. cmd = "mount -t efivarfs none /sys/firmware/efi/efivars"
  263. self.assertRunOk(cmd)
  264. cmd = "efivar -l"
  265. self.assertRunOk(cmd)