test_jailhouse.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import os
  2. import time
  3. import infra.basetest
  4. class TestJailhouse(infra.basetest.BRTest):
  5. # This test uses a specific configuration, mainly for matching the
  6. # requirements of the Jailhouse Qemu inmate demo. We also use the
  7. # Linux kernel from Siemens, which includes patches for
  8. # Jailhouse. Finally, we use the kernel config from
  9. # board/qemu/aarch64-virt rather than the Kernel defconfig, for
  10. # faster build (as it enable less components, but includes
  11. # everything needed for this test).
  12. kernel_ver = "eb6927f7eea77f823b96c0c22ad9d4a2d7ffdfce"
  13. kernel_url = \
  14. f"$(call github,siemens,linux,{kernel_ver})/linux-{kernel_ver}.tar.gz"
  15. config = \
  16. f"""
  17. BR2_aarch64=y
  18. BR2_TOOLCHAIN_EXTERNAL=y
  19. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  20. BR2_LINUX_KERNEL=y
  21. BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
  22. BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="{kernel_url}"
  23. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  24. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  25. BR2_PACKAGE_JAILHOUSE=y
  26. BR2_TARGET_ROOTFS_EXT2=y
  27. BR2_TARGET_ROOTFS_EXT2_4=y
  28. # BR2_TARGET_ROOTFS_TAR is not set
  29. """
  30. def test_run(self):
  31. drive = os.path.join(self.builddir, "images", "rootfs.ext4")
  32. kern = os.path.join(self.builddir, "images", "Image")
  33. # Qemu option and Kernel args are taken from Jailhouse demo. See:
  34. # https://github.com/siemens/jailhouse/blob/master/README.md
  35. # We also add oops=panic to improve the test coverage.
  36. self.emulator.boot(arch="aarch64",
  37. kernel=kern,
  38. kernel_cmdline=["root=/dev/vda console=ttyAMA0 mem=768M oops=panic"],
  39. options=["-M", "virt,gic-version=3,virtualization=on,its=off",
  40. "-cpu", "cortex-a57",
  41. "-m", "1G",
  42. "-smp", "16",
  43. "-drive", f"file={drive},if=none,format=raw,id=hd0",
  44. "-device", "virtio-blk-device,drive=hd0"])
  45. self.emulator.login()
  46. # Check the program can execute.
  47. self.assertRunOk("jailhouse --version")
  48. # Load the kernel module.
  49. self.assertRunOk("modprobe jailhouse")
  50. # Check the device is present.
  51. self.assertRunOk("ls -al /dev/jailhouse")
  52. # Load the cell config this this qemu test.
  53. self.assertRunOk("jailhouse enable /etc/jailhouse/qemu-arm64.cell")
  54. # Dump the jailhouse console, and check we see its
  55. # initialization string.
  56. out, ret = self.emulator.run("jailhouse console")
  57. self.assertEqual(ret, 0)
  58. self.assertIn("Initializing Jailhouse hypervisor", "\n".join(out))
  59. # Create the cell.
  60. cell_cfg = "/etc/jailhouse/qemu-arm64-inmate-demo.cell"
  61. cmd = f"jailhouse cell create {cell_cfg}"
  62. self.assertRunOk(cmd)
  63. # Load the demo image.
  64. cell_name = "inmate-demo"
  65. img = "/usr/libexec/jailhouse/demos/gic-demo.bin"
  66. cmd = f"jailhouse cell load {cell_name} {img}"
  67. self.assertRunOk(cmd)
  68. # List Jailhouse cells and check we see the one we loaded.
  69. out, ret = self.emulator.run("jailhouse cell list")
  70. self.assertEqual(ret, 0)
  71. self.assertIn(cell_name, "\n".join(out))
  72. # We should also see our cell in sysfs.
  73. cmd = "cat /sys/devices/jailhouse/cells/1/name"
  74. out, ret = self.emulator.run(cmd)
  75. self.assertEqual(ret, 0)
  76. self.assertEqual(out[0], cell_name)
  77. # Start the cell.
  78. self.assertRunOk(f"jailhouse cell start {cell_name}")
  79. # Let the demo cell run for few seconds...
  80. time.sleep(3)
  81. # Stop and unload the cell.
  82. self.assertRunOk(f"jailhouse cell shutdown {cell_name}")
  83. self.assertRunOk(f"jailhouse cell destroy {cell_name}")
  84. # Stop and unload jailhouse.
  85. self.assertRunOk("jailhouse disable")
  86. self.assertRunOk("modprobe -r jailhouse")