blob: 93dfa339f56edb40e2cef9cfd0749988aba1e752 [file] [log] [blame]
#!/bin/bash -xe
###############################################################################
#
# This script is for starting QEMU against the input build and running the
# robot CI test suite against it.(ROBOT CI TEST CURRENTLY WIP)
#
###############################################################################
#
# Parameters used by the script:
# UPSTREAM_WORKSPACE = The directory from which the QEMU components are being
# imported from. Generally, this is the build directory
# that is generated by the OpenBMC build-setup.sh script
# when run with "target=qemu".
# Example: /home/builder/workspace/openbmc-build/build.
#
# Optional Variables:
#
# WORKSPACE = Path of the workspace directory where some intermediate
# files will be saved to.
# QEMU_RUN_TIMER = Defaults to 300, a timer for the QEMU container.
# QEMU_LOGIN_TIMER = Defaults to 180, a timer for the QEMU container to reach
# login.
# DOCKER_IMG_NAME = Defaults to openbmc/ubuntu-robot-qemu, the name the
# Docker image will be tagged with when built.
# OBMC_BUILD_DIR = Defaults to /tmp/openbmc/build, the path to the
# directory where the UPSTREAM_WORKSPACE build files will
# be mounted to. Since the build containers have been
# changed to use /tmp as the parent directory for their
# builds, move the mounting location to be the same to
# resolve issues with file links or referrals to exact
# paths in the original build directory. If the build
# directory was changed in the build-setup.sh run, this
# variable should also be changed. Otherwise, the default
# should be used.
# LAUNCH = Used to determine how to launch the qemu robot test
# containers. The options are "local", and "k8s". It will
# default to local which will launch a single container
# to do the runs. If specified k8s will launch a group of
# containers into a kubernetes cluster using the helper
# script.
# QEMU_BIN = Location of qemu-system-arm binary to use when starting
# QEMU relative to upstream workspace. Default is
# ./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm
# which is the default location when doing a bitbake
# of obmc-phosphor-image
#
# MACHINE = Machine to run test against. The options are "witherspoon",
# "palmetto", "romulus", or undefined (default). Default
# will use the versatilepb model.
###############################################################################
set -uo pipefail
QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300}
QEMU_LOGIN_TIMER=${QEMU_LOGIN_TIMER:-180}
WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu}
OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build}
UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}}
LAUNCH=${LAUNCH:-local}
DEFAULT_MACHINE=versatilepb
MACHINE=${MACHINE:-${DEFAULT_MACHINE}}
# The automated test suite needs a real machine type so
# if we're using versatilepb for our qemu start parameter
# then we need to just let our run-robot use the default
if [[ "$MACHINE" == "$DEFAULT_MACHINE" ]]; then
MACHINE_QEMU=
else
MACHINE_QEMU=${MACHINE}
fi
# Determine the architecture
ARCH=$(uname -m)
# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable
case ${ARCH} in
"ppc64le")
QEMU_ARCH="ppc64le-linux"
;;
"x86_64")
QEMU_ARCH="x86_64-linux"
;;
*)
echo "Unsupported system architecture(${ARCH}) found for docker image"
exit 1
esac
# Set the location of the qemu binary relative to UPSTREAM_WORKSPACE
QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
# Get the base directory of the openbmc-build-scripts repo so we can return
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Create the base Docker image for QEMU and Robot
# shellcheck source=scripts/build-qemu-robot-docker.sh
. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME"
# Copy the scripts to start and verify QEMU in the workspace
cp "$DIR"/scripts/boot-qemu* "${UPSTREAM_WORKSPACE}"
################################################################################
if [[ ${LAUNCH} == "local" ]]; then
# Start QEMU docker instance
# root in docker required to open up the https/ssh ports
obmc_qemu_docker=$(docker run --detach \
--rm \
--env HOME="${OBMC_BUILD_DIR}" \
--env QEMU_RUN_TIMER="${QEMU_RUN_TIMER}" \
--env QEMU_ARCH="${QEMU_ARCH}" \
--env QEMU_BIN="${QEMU_BIN}" \
--env MACHINE="${MACHINE}" \
--workdir "${OBMC_BUILD_DIR}" \
--volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \
--tty \
"${DOCKER_IMG_NAME}" "${OBMC_BUILD_DIR}"/boot-qemu-test.exp)
# We can use default ports because we're going to have the 2
# docker instances talk over their private network
DOCKER_SSH_PORT=22
DOCKER_HTTPS_PORT=443
# This docker command intermittently asserts a SIGPIPE which
# causes the whole script to fail. The IP address comes through
# fine on these errors so just ignore the SIGPIPE
trap '' PIPE
DOCKER_QEMU_IP_ADDR="$(docker inspect "$obmc_qemu_docker" | \
grep "IPAddress\":" | tail -n1 | cut -d '"' -f 4)"
#Now wait for the OpenBMC QEMU Docker instance to get to standby
delay=5
attempt=$(( QEMU_LOGIN_TIMER / delay ))
while [ $attempt -gt 0 ]; do
attempt=$(( attempt - 1 ))
echo "Waiting for qemu to get to standby (attempt: $attempt)..."
result=$(docker logs "$obmc_qemu_docker")
if grep -q 'OPENBMC-READY' <<< "$result" ; then
echo "QEMU is ready!"
# Give QEMU a few secs to stabilize
sleep $delay
break
fi
sleep $delay
done
if [ "$attempt" -eq 0 ]; then
echo "Timed out waiting for QEMU, exiting"
exit 1
fi
# Now run the Robot test (Tests commented out until they are working again)
# Timestamp for job
echo "Robot Test started, $(date)"
mkdir -p "${WORKSPACE}"
cd "${WORKSPACE}"
# Copy in the script which will execute the Robot tests
cp "$DIR"/scripts/run-robot.sh "${WORKSPACE}"
# Run the Docker container to execute the Robot test cases
# The test results will be put in ${WORKSPACE}
docker run --rm \
--env HOME="${HOME}" \
--env IP_ADDR="${DOCKER_QEMU_IP_ADDR}" \
--env SSH_PORT="${DOCKER_SSH_PORT}" \
--env HTTPS_PORT="${DOCKER_HTTPS_PORT}" \
--env MACHINE="${MACHINE_QEMU}" \
--workdir "${HOME}" \
--volume "${WORKSPACE}":"${HOME}" \
--tty \
"${DOCKER_IMG_NAME}" "${HOME}"/run-robot.sh
# Now stop the QEMU Docker image
docker stop "$obmc_qemu_docker"
else
echo "LAUNCH variable invalid, Exiting"
exit 1
fi