Skip to content

Commit

Permalink
[Tizen] Fix systemd services race when running tests (#25460)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
arkq authored and pull[bot] committed Aug 26, 2023
1 parent 12d2d4c commit 5318968
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
45 changes: 28 additions & 17 deletions integrations/docker/images/chip-build-tizen-qemu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/ \
Expand All @@ -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.* \
Expand All @@ -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 \
Expand All @@ -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" \
Expand All @@ -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" \
Expand All @@ -136,30 +141,37 @@ 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" \
"[Mount]\n" \
"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/[email protected] \
&& 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" \
| guestfish --rw -a $TIZEN_IOT_IMAGE_ROOT -m /dev/sda upload - /root/.profile \
# 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" \
Expand All @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-tizen/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion third_party/tizen/tizen_qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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''):

Expand Down

0 comments on commit 5318968

Please sign in to comment.