1import os
2
3import infra.basetest
4
5
6class TestFluidsynth(infra.basetest.BRTest):
7    # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it is
8    # armv5 and based on qemu versatilepb which is limited to 256MB of
9    # RAM.  The test needs 1GB of RAM (larger initrd and soundfont is
10    # loaded in memory).
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.86"
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_PACKAGE_AUBIO=y
23        BR2_PACKAGE_FLUIDSYNTH=y
24        BR2_PACKAGE_FLUIDSYNTH_LIBSNDFILE=y
25        BR2_PACKAGE_FLUID_SOUNDFONT=y
26        BR2_PACKAGE_PYTHON3=y
27        BR2_PACKAGE_PYTHON_MIDIUTIL=y
28        BR2_ROOTFS_OVERLAY="{}"
29        BR2_TARGET_ROOTFS_CPIO=y
30        # BR2_TARGET_ROOTFS_TAR is not set
31        """.format(
32           # overlay to add helper test scripts
33           infra.filepath("tests/package/test_fluidsynth/rootfs-overlay"))
34
35    def test_run(self):
36        img = os.path.join(self.builddir, "images", "rootfs.cpio")
37        kern = os.path.join(self.builddir, "images", "Image")
38        self.emulator.boot(arch="aarch64",
39                           kernel=kern,
40                           kernel_cmdline=["console=ttyAMA0"],
41                           options=["-M", "virt", "-cpu", "cortex-a57", "-m", "1G", "-initrd", img])
42        self.emulator.login()
43
44        # Test the binary executes
45        self.assertRunOk("fluidsynth --version")
46
47        # Create a simple MIDI file programmatically
48        self.assertRunOk("/root/gen_midi_file.py /tmp/output.mid")
49
50        # Convert the MIDI file to a WAV file
51        cmd = "fluidsynth"
52        cmd += " -F /tmp/output.wav"
53        cmd += " /usr/share/soundfonts/FluidR3_GM.sf2"
54        cmd += " /tmp/output.mid"
55        self.assertRunOk(cmd)
56
57        # Extract notes in the WAV file with Aubio
58        self.assertRunOk("aubionotes /tmp/output.wav > /tmp/notes.txt")
59
60        # Check the extracted notes are the expected ones
61        self.assertRunOk("/root/check_notes.py < /tmp/notes.txt")
62