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