blob: e40dd4a437d3cbcfaf09ee966c784e72a7f7947e [file] [log] [blame]
Andrew Geissler0205e8d2016-08-10 07:46:19 -05001#!/bin/bash -xe
Alanny Lopez74d2aba2017-07-27 10:23:47 -05002###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -05003#
Alanny Lopez74d2aba2017-07-27 10:23:47 -05004# This script is for starting QEMU against the input build and running the
5# robot CI test suite against it.(ROBOT CI TEST CURRENTLY WIP)
6#
7###############################################################################
8#
9# Parameters used by the script:
10# UPSTREAM_WORKSPACE = The directory from which the QEMU components are being
11# imported from. Generally, this is the build directory
12# that is generated by the OpenBMC build-setup.sh script
Nan Zhoue080fe82022-01-28 20:04:20 +000013# when run with "target=qemuarm".
Alanny Lopez74d2aba2017-07-27 10:23:47 -050014# Example: /home/builder/workspace/openbmc-build/build.
15#
16# Optional Variables:
17#
18# WORKSPACE = Path of the workspace directory where some intermediate
19# files will be saved to.
20# QEMU_RUN_TIMER = Defaults to 300, a timer for the QEMU container.
Andrew Geissler27876c52018-02-21 08:18:35 -080021# QEMU_LOGIN_TIMER = Defaults to 180, a timer for the QEMU container to reach
22# login.
Alanny Lopez74d2aba2017-07-27 10:23:47 -050023# DOCKER_IMG_NAME = Defaults to openbmc/ubuntu-robot-qemu, the name the
24# Docker image will be tagged with when built.
25# OBMC_BUILD_DIR = Defaults to /tmp/openbmc/build, the path to the
26# directory where the UPSTREAM_WORKSPACE build files will
27# be mounted to. Since the build containers have been
28# changed to use /tmp as the parent directory for their
29# builds, move the mounting location to be the same to
30# resolve issues with file links or referrals to exact
31# paths in the original build directory. If the build
32# directory was changed in the build-setup.sh run, this
33# variable should also be changed. Otherwise, the default
34# should be used.
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050035# LAUNCH = Used to determine how to launch the qemu robot test
36# containers. The options are "local", and "k8s". It will
37# default to local which will launch a single container
38# to do the runs. If specified k8s will launch a group of
39# containers into a kubernetes cluster using the helper
40# script.
Andrew Geissler7a88f292018-01-04 15:16:02 -060041# QEMU_BIN = Location of qemu-system-arm binary to use when starting
42# QEMU relative to upstream workspace. Default is
43# ./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm
44# which is the default location when doing a bitbake
Nan Zhoue080fe82022-01-28 20:04:20 +000045# of obmc-phosphor-image. If you don't find the sysroots
46# folder, run `bitbake build-sysroots`.
Alanny Lopez74d2aba2017-07-27 10:23:47 -050047#
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060048# MACHINE = Machine to run test against. The options are "witherspoon",
49# "palmetto", "romulus", or undefined (default). Default
50# will use the versatilepb model.
Alanny Lopez74d2aba2017-07-27 10:23:47 -050051###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050052
53set -uo pipefail
54
Alanny Lopez74d2aba2017-07-27 10:23:47 -050055QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300}
Andrew Geissler27876c52018-02-21 08:18:35 -080056QEMU_LOGIN_TIMER=${QEMU_LOGIN_TIMER:-180}
Andrew Geissler1df680a2016-08-22 14:37:39 -050057WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez74d2aba2017-07-27 10:23:47 -050058DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu}
59OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build}
60UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}}
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050061LAUNCH=${LAUNCH:-local}
Andrew Geissler0c63ce12018-03-01 12:40:19 -080062DEFAULT_MACHINE=versatilepb
63MACHINE=${MACHINE:-${DEFAULT_MACHINE}}
64
65# The automated test suite needs a real machine type so
66# if we're using versatilepb for our qemu start parameter
67# then we need to just let our run-robot use the default
Patrick Williams384d7412020-11-06 16:15:41 -060068if [[ "$MACHINE" == "$DEFAULT_MACHINE" ]]; then
Andrew Geissler0c63ce12018-03-01 12:40:19 -080069 MACHINE_QEMU=
70else
71 MACHINE_QEMU=${MACHINE}
72fi
Andrew Geissler0205e8d2016-08-10 07:46:19 -050073
Alanny Lopez74d2aba2017-07-27 10:23:47 -050074# Determine the architecture
75ARCH=$(uname -m)
Andrew Geissler0205e8d2016-08-10 07:46:19 -050076
Alanny Lopez74d2aba2017-07-27 10:23:47 -050077# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable
78case ${ARCH} in
79 "ppc64le")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050080 QEMU_ARCH="ppc64le-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050081 ;;
82 "x86_64")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050083 QEMU_ARCH="x86_64-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050084 ;;
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000085 "aarch64")
86 QEMU_ARCH="arm64-linux"
87 ;;
Alanny Lopez74d2aba2017-07-27 10:23:47 -050088 *)
89 echo "Unsupported system architecture(${ARCH}) found for docker image"
90 exit 1
91esac
Andrew Geissler0205e8d2016-08-10 07:46:19 -050092
Andrew Geissler7a88f292018-01-04 15:16:02 -060093# Set the location of the qemu binary relative to UPSTREAM_WORKSPACE
94QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
95
Alanny Lopez74d2aba2017-07-27 10:23:47 -050096# Get the base directory of the openbmc-build-scripts repo so we can return
97DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
98
99# Create the base Docker image for QEMU and Robot
Patrick Williams384d7412020-11-06 16:15:41 -0600100# shellcheck source=scripts/build-qemu-robot-docker.sh
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500101. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME"
102
103# Copy the scripts to start and verify QEMU in the workspace
Patrick Williams384d7412020-11-06 16:15:41 -0600104cp "$DIR"/scripts/boot-qemu* "${UPSTREAM_WORKSPACE}"
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500105
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500106################################################################################
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500107
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500108if [[ ${LAUNCH} == "local" ]]; then
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500109
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500110 # Start QEMU docker instance
111 # root in docker required to open up the https/ssh ports
112 obmc_qemu_docker=$(docker run --detach \
Lei YUf2e658b2020-06-17 18:02:43 +0800113 --rm \
Andrew Geissler147776e2021-03-26 15:59:12 -0500114 --user root \
Patrick Williams384d7412020-11-06 16:15:41 -0600115 --env HOME="${OBMC_BUILD_DIR}" \
116 --env QEMU_RUN_TIMER="${QEMU_RUN_TIMER}" \
117 --env QEMU_ARCH="${QEMU_ARCH}" \
118 --env QEMU_BIN="${QEMU_BIN}" \
119 --env MACHINE="${MACHINE}" \
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500120 --workdir "${OBMC_BUILD_DIR}" \
Patrick Williamsa8c839d2021-04-12 12:40:21 -0500121 --volume "${UPSTREAM_WORKSPACE}:${OBMC_BUILD_DIR}:ro" \
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500122 --tty \
Patrick Williams384d7412020-11-06 16:15:41 -0600123 "${DOCKER_IMG_NAME}" "${OBMC_BUILD_DIR}"/boot-qemu-test.exp)
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500124
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500125 # We can use default ports because we're going to have the 2
126 # docker instances talk over their private network
127 DOCKER_SSH_PORT=22
128 DOCKER_HTTPS_PORT=443
Andrew Geissler9d913fe2018-02-21 08:29:39 -0800129
130 # This docker command intermittently asserts a SIGPIPE which
131 # causes the whole script to fail. The IP address comes through
132 # fine on these errors so just ignore the SIGPIPE
133 trap '' PIPE
134
Patrick Williams384d7412020-11-06 16:15:41 -0600135 DOCKER_QEMU_IP_ADDR="$(docker inspect "$obmc_qemu_docker" | \
Andrew Geissler5b4a0d22018-04-03 11:11:02 -0700136 grep "IPAddress\":" | tail -n1 | cut -d '"' -f 4)"
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500137
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500138 #Now wait for the OpenBMC QEMU Docker instance to get to standby
Andrew Geissler27876c52018-02-21 08:18:35 -0800139 delay=5
Patrick Williams384d7412020-11-06 16:15:41 -0600140 attempt=$(( QEMU_LOGIN_TIMER / delay ))
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500141 while [ $attempt -gt 0 ]; do
Patrick Williams384d7412020-11-06 16:15:41 -0600142 attempt=$(( attempt - 1 ))
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500143 echo "Waiting for qemu to get to standby (attempt: $attempt)..."
Patrick Williams384d7412020-11-06 16:15:41 -0600144 result=$(docker logs "$obmc_qemu_docker")
145 if grep -q 'OPENBMC-READY' <<< "$result" ; then
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500146 echo "QEMU is ready!"
George Keishing11a6e9e2019-07-22 08:18:40 -0500147 # Give QEMU a few secs to stabilize
Andrew Geissler27876c52018-02-21 08:18:35 -0800148 sleep $delay
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500149 break
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500150 fi
Andrew Geissler27876c52018-02-21 08:18:35 -0800151 sleep $delay
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500152 done
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500153
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500154 if [ "$attempt" -eq 0 ]; then
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500155 echo "Timed out waiting for QEMU, exiting"
156 exit 1
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500157 fi
158
159 # Now run the Robot test (Tests commented out until they are working again)
160
161 # Timestamp for job
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800162 echo "Robot Test started, $(date)"
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500163
Patrick Williams384d7412020-11-06 16:15:41 -0600164 mkdir -p "${WORKSPACE}"
165 cd "${WORKSPACE}"
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500166
167 # Copy in the script which will execute the Robot tests
Patrick Williams384d7412020-11-06 16:15:41 -0600168 cp "$DIR"/scripts/run-robot.sh "${WORKSPACE}"
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500169
170 # Run the Docker container to execute the Robot test cases
171 # The test results will be put in ${WORKSPACE}
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800172 docker run --rm \
Patrick Williams384d7412020-11-06 16:15:41 -0600173 --env HOME="${HOME}" \
174 --env IP_ADDR="${DOCKER_QEMU_IP_ADDR}" \
175 --env SSH_PORT="${DOCKER_SSH_PORT}" \
176 --env HTTPS_PORT="${DOCKER_HTTPS_PORT}" \
177 --env MACHINE="${MACHINE_QEMU}" \
178 --workdir "${HOME}" \
179 --volume "${WORKSPACE}":"${HOME}" \
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800180 --tty \
Patrick Williams384d7412020-11-06 16:15:41 -0600181 "${DOCKER_IMG_NAME}" "${HOME}"/run-robot.sh
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500182
183 # Now stop the QEMU Docker image
Patrick Williams384d7412020-11-06 16:15:41 -0600184 docker stop "$obmc_qemu_docker"
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500185
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500186else
187 echo "LAUNCH variable invalid, Exiting"
188 exit 1
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500189fi