support/testing: add package/test_mender.py

Create a test to check Mender client at runtime.

The aim of this test is:
  - to check the correct execution of simple Mender commands,
    in a minimal environment;
  - to validate there is no missing dependencies for runtime.

This test is not a board integration test for Mender,
including well-configured bootloader, partitioning, ...

Check:
  - the daemon is started;
  - the current 'artifact name' (name of the image or update) of the active
    partition is read, without error.

For that, we need to fake (see the 'overlay' directory):
  - some bootloader environment variables;
  - the name of an update.

Signed-off-by: Mikael Bourhis-Cloarec <mikael.bourhis@smile.fr>
[Romain: remove single hyphen command (Mender 3.0.0)]
Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Mikael Bourhis-Cloarec 2022-01-06 17:13:01 +01:00 committed by Thomas Petazzoni
parent 97daba5781
commit bc91d35da7
3 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import os
import infra.basetest
class TestMender(infra.basetest.BRTest):
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_PACKAGE_MENDER=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_ROOTFS_OVERLAY="{}"
""".format(
# overlay to add a fake 'fw_printenv', used by Mender
infra.filepath("tests/package/test_mender/rootfs-overlay"))
def test_run(self):
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
self.emulator.boot(arch="armv5",
kernel="builtin",
options=["-initrd", cpio_file])
self.emulator.login()
# Check if the Daemon is running
self.assertRunOk("ls /var/run/mender.pid")
self.assertRunOk("ps aux | egrep [m]ender")
# Check if a simple Mender command is correctly executed
self.assertRunOk("mender -log-level debug show-artifact")
self.assertRunOk("mender -log-level debug show-artifact | grep 'RUNTIME_TEST_ARTIFACT_NAME'")
cmd = "mender show-artifact 2>&1 | grep -i 'err'" # Check if no 'error' among the traces
_, exit_code = self.emulator.run(cmd)
self.assertEqual(exit_code, 1)

View File

@ -0,0 +1 @@
artifact_name=RUNTIME_TEST_ARTIFACT_NAME

View File

@ -0,0 +1,6 @@
#!/bin/sh
# Fake 'fw_printenv' because UBoot is not installed: print some plausible 'key-value'
echo "bootcount=0"
echo "mender_boot_part=rootfs"
echo "upgrade_available=0"