From 15358487751b4210d5f4da1c5cbf14ea57c82123 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 7 Mar 2023 03:31:49 +0100 Subject: [PATCH] [Tizen] Fix systemd services race when running tests (#25460) * [Tizen] Fix systemd services race when running tests On the Tizen QEMU image tests are launched by the serial-getty service after auto login to root. However, there is no explicit before/after ordering between serial-getty service and ISO image mounting service. On slow systems (e.g. CI) it might happen that the serial-getty is started before ISO image mount target. This results in tests being not launched... This commit adds explicit run ordering between serial-getty and multi-user target, which shall guarantee that tests will be launched after CHIP ISO image is mounted and all Tizen services are ready. * Do not run runner script in the interactive mode * Add libncurses5 (required by GDB) to Tizen docker image --- .../images/chip-build-tizen-qemu/Dockerfile | 45 ++++++++++++------- .../docker/images/chip-build-tizen/Dockerfile | 1 + integrations/docker/images/chip-build/version | 2 +- third_party/tizen/tizen_qemu.py | 20 ++++++++- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/integrations/docker/images/chip-build-tizen-qemu/Dockerfile b/integrations/docker/images/chip-build-tizen-qemu/Dockerfile index 1c0ae65f843da5..78922ba8054ce4 100644 --- a/integrations/docker/images/chip-build-tizen-qemu/Dockerfile +++ b/integrations/docker/images/chip-build-tizen-qemu/Dockerfile @@ -68,6 +68,7 @@ RUN set -x \ RUN set -x \ && mkdir -p /tmp/workdir && cd /tmp/workdir \ && SYSTEMD_SYSTEM=/usr/lib/systemd/system \ + && SYSTEMD_REQUIRES_LOCAL_FS=$SYSTEMD_SYSTEM/local-fs.target.requires \ # Download Tizen images && wget --progress=dot:giga -r -nd --no-parent -e robots=off -A 'tizen-*.tar.gz' \ http://download.tizen.org/snapshots/TIZEN/Tizen-$TIZEN_VERSION/Tizen-$TIZEN_VERSION-Unified/latest/images/standard/tizen-headless-armv7l/ \ @@ -80,7 +81,7 @@ RUN set -x \ && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -fy --no-install-recommends libguestfs-tools linux-image-generic \ # Add extra libraries to the root image - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda glob copy-in \ + && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda copy-in \ $TIZEN_SDK_TOOLCHAIN/arm-tizen-linux-gnueabi/lib/libasan.so.* \ $TIZEN_SDK_TOOLCHAIN/arm-tizen-linux-gnueabi/lib/libubsan.so.* \ $TIZEN_SDK_SYSROOT/usr/lib/libbluetooth-api.so.* \ @@ -89,17 +90,22 @@ RUN set -x \ $TIZEN_SDK_SYSROOT/usr/lib/libnsd-dns-sd.so.* \ /usr/lib/ \ # Disable failing systemd services - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda glob rm $SYSTEMD_SYSTEM/deviced.service \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda glob rm $SYSTEMD_SYSTEM/mnt-inform.mount \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda glob rm $SYSTEMD_SYSTEM/murphyd.service \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda glob rm $SYSTEMD_SYSTEM/pulseaudio.service \ + && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda \ + glob rm $SYSTEMD_SYSTEM/clone_partitions.service : \ + glob rm $SYSTEMD_SYSTEM/deviced.service : \ + glob rm $SYSTEMD_SYSTEM/mm-resource-managerd.service : \ + glob rm $SYSTEMD_SYSTEM/mnt-inform.mount : \ + glob rm $SYSTEMD_SYSTEM/muse-server.* : \ + glob rm $SYSTEMD_SYSTEM/murphyd.service : \ + glob rm $SYSTEMD_SYSTEM/pulseaudio.service \ # Mount Tizen system partition on /opt-ro instead of /opt && SYSTEMD_UNIT_OPT_RO_MOUNT=$SYSTEMD_SYSTEM/opt\\x2dro.mount \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda ln-sf $SYSTEMD_UNIT_OPT_RO_MOUNT $SYSTEMD_SYSTEM/local-fs.target.requires \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda mv $SYSTEMD_SYSTEM/opt.mount $SYSTEMD_UNIT_OPT_RO_MOUNT \ + && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda \ + mv $SYSTEMD_SYSTEM/opt.mount $SYSTEMD_UNIT_OPT_RO_MOUNT : \ + ln-sf $SYSTEMD_UNIT_OPT_RO_MOUNT $SYSTEMD_REQUIRES_LOCAL_FS : \ + mkdir /opt-ro \ && virt-edit $TIZEN_IOT_IMAGE_ROOT -e 's#/opt#/opt-ro#g' $SYSTEMD_UNIT_OPT_RO_MOUNT \ && virt-edit $TIZEN_IOT_IMAGE_ROOT -e 's#Options=#Options=ro,#' $SYSTEMD_UNIT_OPT_RO_MOUNT \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda mkdir /opt-ro \ # Create /tmp/.opt-upper and /tmp/.opt-work after /tmp is mounted && SYSTEMD_UNIT_OPT_PRE_MOUNT=$SYSTEMD_SYSTEM/opt.pre-mount.service \ && echo -n \ @@ -113,7 +119,6 @@ RUN set -x \ | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_OPT_PRE_MOUNT \ # Mount Tizen system partition as a tmp-based overlay && SYSTEMD_UNIT_OPT_MOUNT=$SYSTEMD_SYSTEM/opt.mount \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda ln-sf $SYSTEMD_UNIT_OPT_MOUNT $SYSTEMD_SYSTEM/local-fs.target.requires \ && echo -n \ "[Unit]\nConditionPathIsMountPoint=!/opt\n" \ "RequiresMountsFor=/opt-ro /tmp\n" \ @@ -124,10 +129,10 @@ RUN set -x \ "Where=/opt\n" \ "Type=overlay\n" \ "Options=lowerdir=/opt-ro,upperdir=/tmp/.opt-upper,workdir=/tmp/.opt-work\n" \ - | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_OPT_MOUNT \ + | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_OPT_MOUNT : \ + ln-sf $SYSTEMD_UNIT_OPT_MOUNT $SYSTEMD_REQUIRES_LOCAL_FS \ # Fix SMACK label for /tmp/.opt-work/work && SYSTEMD_UNIT_OPT_POST_MOUNT=$SYSTEMD_SYSTEM/opt.post-mount.service \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda ln-sf $SYSTEMD_UNIT_OPT_POST_MOUNT $SYSTEMD_SYSTEM/local-fs.target.requires \ && echo -n \ "[Unit]\n" \ "DefaultDependencies=no\n" \ @@ -136,10 +141,10 @@ RUN set -x \ "Type=oneshot\n" \ "ExecStart=chsmack -a * /tmp/.opt-work/work\n" \ "RemainAfterExit=yes\n" \ - | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_OPT_POST_MOUNT \ + | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_OPT_POST_MOUNT : \ + ln-sf $SYSTEMD_UNIT_OPT_POST_MOUNT $SYSTEMD_REQUIRES_LOCAL_FS \ # Mount Matter ISO image on startup && SYSTEMD_UNIT_CHIP_MOUNT=$SYSTEMD_SYSTEM/mnt-chip.mount \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda ln-sf $SYSTEMD_UNIT_CHIP_MOUNT $SYSTEMD_SYSTEM/local-fs.target.requires \ && echo -n \ "[Unit]\n" \ "ConditionPathIsMountPoint=!/mnt/chip\n" \ @@ -147,12 +152,18 @@ RUN set -x \ "What=/dev/disk/by-label/CHIP\n" \ "Where=/mnt/chip\n" \ "Options=nofail\n" \ - | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_CHIP_MOUNT \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda mkdir /mnt/chip \ + | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - $SYSTEMD_UNIT_CHIP_MOUNT : \ + ln-sf $SYSTEMD_UNIT_CHIP_MOUNT $SYSTEMD_REQUIRES_LOCAL_FS : \ + mkdir /mnt/chip \ # Setup auto-login for root user && SYSTEMD_UNIT_SERIAL_GETTY=$SYSTEMD_SYSTEM/serial-getty@.service \ && virt-edit $TIZEN_IOT_IMAGE_ROOT -e \ 's#^ExecStart=.*#ExecStart=-/sbin/agetty -o "-p -f root" --noclear -a root --keep-baud 115200 %I \$TERM#' $SYSTEMD_UNIT_SERIAL_GETTY \ + # Run serial-getty.service after multi-user.target + && SYSTEMD_WANTS_GRAPHICAL=$SYSTEMD_SYSTEM/graphical.target.wants \ + && SYSTEMD_WANTS_MULTI_USER=$SYSTEMD_SYSTEM/multi-user.target.wants \ + && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda mv $SYSTEMD_WANTS_MULTI_USER/getty.target $SYSTEMD_WANTS_GRAPHICAL \ + && virt-edit $TIZEN_IOT_IMAGE_ROOT -e 's#^After=#Before=serial-getty\@ttyAMA0.service\nAfter=#' $SYSTEMD_SYSTEM/multi-user.target \ # Execute launcher script after root login && echo -n \ "[ -x /launcher.sh ] && /launcher.sh\n" \ @@ -160,6 +171,7 @@ RUN set -x \ # Launcher script && echo -n \ "#!/bin/bash\n" \ + "grep -q 'rootshell' /proc/cmdline && exit\n" \ "if [[ -x /mnt/chip/runner.sh ]]; then\n" \ " echo '### RUNNER START ###'\n" \ " /mnt/chip/runner.sh\n" \ @@ -169,8 +181,7 @@ RUN set -x \ "fi\n" \ "echo 'Shutting down emulated system...'\n" \ "echo o > /proc/sysrq-trigger\n" \ - | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - /launcher.sh \ - && guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda chmod 0755 /launcher.sh \ + | guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - /launcher.sh : chmod 0755 /launcher.sh \ # Remove ALL previously installed packages && apt-get autopurge -fy $(tail -2 /var/log/apt/history.log | grep ^Install | cut -c 10- | sed 's/([^)]*),\?//g') \ && rm -rf /var/lib/apt/lists \ diff --git a/integrations/docker/images/chip-build-tizen/Dockerfile b/integrations/docker/images/chip-build-tizen/Dockerfile index dfa4ddfb37f915..a81b034526ff70 100644 --- a/integrations/docker/images/chip-build-tizen/Dockerfile +++ b/integrations/docker/images/chip-build-tizen/Dockerfile @@ -19,6 +19,7 @@ RUN set -x \ && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -fy --no-install-recommends \ cpio \ + libncurses5 \ obs-build \ openjdk-8-jre-headless \ wget \ diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index fb0739078dea26..ac1dabccaf9b43 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.6.48 Version bump reason: [android] Correct kotlinc path for vscode image +0.6.49 Version bump reason: Fix systemd services run race in Tizen QEMU image diff --git a/third_party/tizen/tizen_qemu.py b/third_party/tizen/tizen_qemu.py index 548cc7f85431f4..1e767d40c882cf 100755 --- a/third_party/tizen/tizen_qemu.py +++ b/third_party/tizen/tizen_qemu.py @@ -15,16 +15,24 @@ # limitations under the License. import argparse +import logging import os import re +import shlex import subprocess import sys # Absolute path to Tizen Studio CLI tool. tizen_sdk_root = os.environ["TIZEN_SDK_ROOT"] +# Setup basic logging capabilities. +logging.basicConfig(level=logging.DEBUG) + parser = argparse.ArgumentParser( description="Run Tizen on QEMU.") +parser.add_argument( + '-i', '--interactive', action='store_true', + help="run QEMU in interactive mode (no output redirection, no runner)") parser.add_argument( '--smp', metavar='NUM', type=int, default=2, help=("the number of CPUs available in QEMU; default: %(default)s")) @@ -94,14 +102,24 @@ '-drive', 'file=%s,id=virtio-blk1,if=none,format=raw,readonly=on' % args.image_root, ] +kernel_args = "console=ttyAMA0 earlyprintk earlycon root=/dev/vda" +if args.interactive: + # Run root shell instead of the runner script. + kernel_args += " rootshell" + qemu_args += [ '-kernel', args.kernel, - '-append', "console=ttyAMA0 earlyprintk earlycon root=/dev/vda", + '-append', kernel_args, ] +if args.interactive: + # Run QEMU in interactive mode. + sys.exit(subprocess.call(qemu_args)) + status = 0 # Run QEMU. with open(args.output, "wb") as output: + logging.info("run: %s", " ".join(map(shlex.quote, qemu_args))) with subprocess.Popen(qemu_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as proc: for line in iter(proc.stdout.readline, b''):