1import os
2
3import infra.basetest
4
5
6class TestOpenBLAS(infra.basetest.BRTest):
7    config = \
8        """
9        BR2_aarch64=y
10        BR2_TOOLCHAIN_EXTERNAL=y
11        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
12        BR2_LINUX_KERNEL=y
13        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
14        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.27"
15        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
16        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
17        BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
18        BR2_TARGET_ROOTFS_CPIO=y
19        BR2_TARGET_ROOTFS_CPIO_GZIP=y
20        # BR2_TARGET_ROOTFS_TAR is not set
21        BR2_PACKAGE_OPENBLAS=y
22        BR2_PACKAGE_OPENBLAS_INSTALL_TESTS=y
23        """
24
25    def test_run(self):
26        img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
27        kern = os.path.join(self.builddir, "images", "Image")
28        self.emulator.boot(arch="aarch64",
29                           kernel=kern,
30                           kernel_cmdline=["console=ttyAMA0"],
31                           options=["-M", "virt", "-cpu", "cortex-a57", "-smp", "2", "-m", "512M", "-initrd", img])
32        self.emulator.login()
33
34        test_prefix = "/usr/libexec/openblas/tests"
35
36        # BLAS data types:
37        blas_data_types = [
38            "s",  # Single precision (32bit) float
39            "d",  # Double precision (64bit) double
40            "c",  # Single precision (32bit) complex
41            "z"   # Double precision (64bit) complex
42        ]
43
44        # BLAS routine levels:
45        # Level 1: Vector operations,
46        # Level 2: Matrix-Vector operations,
47        # Level 3: Matrix-Matrix operations.
48        for blas_level in range(1, 4):
49            for blas_data_type in blas_data_types:
50                test_name = f"x{blas_data_type}cblat{blas_level}"
51                cmd = test_prefix + "/" + test_name
52
53                if blas_level > 1:
54                    cmd += f" < {test_prefix}/{blas_data_type}in{blas_level}"
55
56                self.assertRunOk(cmd, timeout=30)
57