1import os
2
3import infra.basetest
4
5
6class TestLibJXL(infra.basetest.BRTest):
7    # infra.basetest.BASIC_TOOLCHAIN_CONFIG is not used as it is armv5
8    # and the image encoding would take too long (several minutes).
9    # We also add GraphicsMagick to generate and compare images for
10    # the test.
11    config = \
12        """
13        BR2_aarch64=y
14        BR2_TOOLCHAIN_EXTERNAL=y
15        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
16        BR2_LINUX_KERNEL=y
17        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
18        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.79"
19        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
20        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
21        BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
22        BR2_TARGET_ROOTFS_CPIO=y
23        BR2_TARGET_ROOTFS_CPIO_GZIP=y
24        # BR2_TARGET_ROOTFS_TAR is not set
25        BR2_PACKAGE_GRAPHICSMAGICK=y
26        BR2_PACKAGE_LIBJXL=y
27        """
28
29    def test_run(self):
30        img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
31        kern = os.path.join(self.builddir, "images", "Image")
32        self.emulator.boot(arch="aarch64",
33                           kernel=kern,
34                           kernel_cmdline=["console=ttyAMA0"],
35                           options=["-M", "virt", "-cpu", "cortex-a57", "-m", "256M", "-initrd", img])
36        self.emulator.login()
37
38        ref = "/var/tmp/reference.ppm"
39        jxl = "/var/tmp/encoded.jxl"
40        dec = "/var/tmp/decoded.ppm"
41
42        cmd = "gm convert IMAGE:LOGO {}".format(ref)
43        self.assertRunOk(cmd)
44
45        cmd = "cjxl {} {}".format(ref, jxl)
46        self.assertRunOk(cmd, timeout=30)
47
48        cmd = "djxl {} {}".format(jxl, dec)
49        self.assertRunOk(cmd)
50
51        cmd = "gm compare -metric mse -maximum-error 1e-3 {} {}".format(
52            ref, dec)
53        self.assertRunOk(cmd)
54