1import os
2
3import infra.basetest
4
5
6class TestZfsBase(infra.basetest.BRTest):
7    timeout = 60 * 3
8    config = \
9        """
10        BR2_x86_64=y
11        BR2_x86_corei7=y
12        BR2_TOOLCHAIN_EXTERNAL=y
13        BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
14        BR2_LINUX_KERNEL=y
15        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
16        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.35"
17        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
18        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86_64/linux.config"
19        BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF=y
20        BR2_PACKAGE_ZFS=y
21        BR2_PACKAGE_PYTHON3=y
22        BR2_PACKAGE_PYTHON_CFFI=y
23        BR2_PACKAGE_PYTHON_SETUPTOOLS=y
24        BR2_PACKAGE_ZLIB_NG=y
25        BR2_PACKAGE_LIBRESSL=y
26        BR2_TARGET_ROOTFS_CPIO=y
27        # BR2_TARGET_ROOTFS_TAR is not set
28        """
29
30    def base_test_run(self):
31        kernel = os.path.join(self.builddir, "images", "bzImage")
32        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
33        self.emulator.boot(
34            arch="x86_64",
35            kernel=kernel,
36            kernel_cmdline=["console=ttyS0"],
37            options=["-cpu", "Nehalem", "-m", "320", "-initrd", cpio_file],
38        )
39        self.emulator.login()
40
41        cmds = [
42            # Init
43            "modprobe zfs && sleep 2",
44            "mount -o remount,size=132M /tmp",
45            "fallocate -l 64M /tmp/container1.raw",
46            "fallocate -l 64M /tmp/container2.raw",
47            "zpool create pool raidz /tmp/container1.raw /tmp/container2.raw",
48            "dd if=/dev/urandom bs=1M count=8 of=/pool/urandom",
49            "sha256sum /pool/urandom > /tmp/urandom.sha256",
50            # Check ZFS
51            "zpool export pool",
52            "zpool import pool -d /tmp/container1.raw -d /tmp/container2.raw",
53            "dd conv=notrunc bs=1M count=32 seek=16 if=/dev/urandom of=/tmp/container1.raw",
54            "zpool scrub -w pool",
55            "sha256sum -c /tmp/urandom.sha256",
56            "zpool status -v",
57            # Check PyZFS
58            "arc_summary",
59        ]
60        for cmd in cmds:
61            self.assertRunOk(cmd, timeout=self.timeout)
62
63
64class TestZfsGlibc(TestZfsBase):
65    config = TestZfsBase.config + \
66        """
67        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_CORE_I7_GLIBC_STABLE=y
68        """
69
70    def test_run(self):
71        TestZfsBase.base_test_run(self)
72
73
74class TestZfsUclibc(TestZfsBase):
75    config = TestZfsBase.config + \
76        """
77        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_CORE_I7_UCLIBC_STABLE=y
78        """
79
80    def test_run(self):
81        TestZfsBase.base_test_run(self)
82
83
84class TestZfsMusl(TestZfsBase):
85    config = TestZfsBase.config + \
86        """
87        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_MUSL_STABLE=y
88        """
89
90    def test_run(self):
91        TestZfsBase.base_test_run(self)
92