diff mbox series

[5/5] support/testing: add test for openmpi

Message ID 20230207220941.58066-5-ju.o@free.fr
State Changes Requested
Headers show
Series [1/5] DEVELOPERS: add Julien Olivain for package/openmpi | expand

Commit Message

Julien Olivain Feb. 7, 2023, 10:09 p.m. UTC
This openmpi runtime test attempt to run the "hello_c" example program
on a 8 cpu Aarch64 system. It expects the same amount of "Hello, world"
messages.

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Tested on branch master at commit 4fbd2f6 with commands:

    make check-package
    ...
    0 warnings generated

    python3 -m flake8 support/testing/tests/package/test_openmpi.py
    [no-output]

    support/testing/run-tests \
        -d dl -o output_folder \
        tests.package.test_openmpi
    ...
    OK
---
 DEVELOPERS                                    |  1 +
 support/testing/tests/package/test_openmpi.py | 53 +++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 support/testing/tests/package/test_openmpi.py
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 3d1c3a2a83..c6587b10e1 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1715,6 +1715,7 @@  F:	support/testing/tests/package/test_ncdu.py
 F:	support/testing/tests/package/test_octave.py
 F:	support/testing/tests/package/test_ola.py
 F:	support/testing/tests/package/test_ola/
+F:	support/testing/tests/package/test_openmpi.py
 F:	support/testing/tests/package/test_perftest.py
 F:	support/testing/tests/package/test_python_distro.py
 F:	support/testing/tests/package/test_python_hkdf.py
diff --git a/support/testing/tests/package/test_openmpi.py b/support/testing/tests/package/test_openmpi.py
new file mode 100644
index 0000000000..86a42a0145
--- /dev/null
+++ b/support/testing/tests/package/test_openmpi.py
@@ -0,0 +1,53 @@ 
+import os
+
+import infra.basetest
+
+
+class TestOpenMPI(infra.basetest.BRTest):
+    # We use a "virt" Aarch64 machine to have smp and 512M of memory
+    config = \
+        """
+        BR2_aarch64=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+        BR2_LINUX_KERNEL=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.92"
+        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
+        BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_TARGET_ROOTFS_CPIO_GZIP=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        BR2_PACKAGE_OPENMPI_EXAMPLES=y
+        """
+
+    def test_run(self):
+        num_cpu = 8
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
+        kern_file = os.path.join(self.builddir, "images", "Image")
+        self.emulator.boot(arch="aarch64",
+                           kernel=kern_file,
+                           kernel_cmdline=["console=ttyAMA0"],
+                           options=["-M", "virt", "-smp", str(num_cpu), "-cpu", "cortex-a57", "-m", "512M", "-initrd", cpio_file])
+        self.emulator.login()
+
+        self.assertRunOk("ompi_info --all")
+
+        # "--allow-run-as-root" option is needed because mpirun
+        # normally refuse to start as root, as a security mechanism.
+        # "--mca plm_rsh_agent /bin/true" is needed because openmpi
+        # silently fails if the "rsh" binary is not present in the
+        # system, even if it's not used. We define it as "/bin/true",
+        # as a workaround.
+        # The hello_c example will spawn one job per cpu. We expect
+        # the same number of "Hello, world," output as the number of
+        # cpus.
+        cmd = "mpirun" \
+            " --allow-run-as-root" \
+            " --mca plm_rsh_agent /bin/true" \
+            " /usr/bin/ompi_hello_c"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        all_output = ''.join(output)
+        self.assertEqual(all_output.count('Hello, world,'), num_cpu)