test_lxc.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import infra.basetest
  3. import pexpect
  4. class TestLxc(infra.basetest.BRTest):
  5. config = \
  6. """
  7. BR2_arm=y
  8. BR2_TOOLCHAIN_EXTERNAL=y
  9. BR2_LINUX_KERNEL=y
  10. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  11. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.79"
  12. BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
  13. BR2_LINUX_KERNEL_DTS_SUPPORT=y
  14. BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
  15. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{}"
  16. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  17. BR2_INIT_SYSTEMD=y
  18. BR2_PACKAGE_LXC=y
  19. BR2_PACKAGE_TINI=y
  20. BR2_PACKAGE_IPERF3=y
  21. BR2_ROOTFS_OVERLAY="{}"
  22. BR2_TARGET_ROOTFS_CPIO=y
  23. """.format(
  24. infra.filepath("tests/package/test_lxc/lxc-kernel.config"),
  25. infra.filepath("tests/package/test_lxc/rootfs-overlay"))
  26. def run_ok(self, cmd):
  27. self.assertRunOk(cmd, 120)
  28. def wait_boot(self):
  29. #the complete boot with systemd takes more time than what the default multipler permits
  30. self.emulator.timeout_multiplier *= 10
  31. self.emulator.login()
  32. def setup_run_test_container(self):
  33. self.run_ok("lxc-create -n lxc_iperf3 -t none -f /usr/share/lxc/config/minimal-iperf3.conf")
  34. self.run_ok("lxc-start -l trace -n lxc_iperf3 -o /tmp/lxc.log -L /tmp/lxc.console.log")
  35. #need to wait for the container to be fully started
  36. self.run_ok("sleep 2")
  37. self.run_ok("iperf3 -c 192.168.1.2 -t 2")
  38. #if the test fails, just cat /tmp/*.log
  39. def test_run(self):
  40. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  41. kernel_file = os.path.join(self.builddir, "images", "zImage")
  42. dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
  43. self.emulator.boot(arch="armv7", kernel=kernel_file,
  44. kernel_cmdline=[
  45. "console=ttyAMA0,115200"],
  46. options=["-initrd", cpio_file,
  47. "-dtb", dtb_file,
  48. "-M", "vexpress-a9"])
  49. self.wait_boot()
  50. self.setup_run_test_container()