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