blob: 0857c6d72ba3db6887f083c0c018eccc3802af04 [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
13# when run with "target=qemu".
14# 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
45# of obmc-phosphor-image
Alanny Lopez74d2aba2017-07-27 10:23:47 -050046#
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060047# MACHINE = Machine to run test against. The options are "witherspoon",
48# "palmetto", "romulus", or undefined (default). Default
49# will use the versatilepb model.
Alanny Lopez74d2aba2017-07-27 10:23:47 -050050###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050051
52set -uo pipefail
53
Alanny Lopez74d2aba2017-07-27 10:23:47 -050054QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300}
Andrew Geissler27876c52018-02-21 08:18:35 -080055QEMU_LOGIN_TIMER=${QEMU_LOGIN_TIMER:-180}
Andrew Geissler1df680a2016-08-22 14:37:39 -050056WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez74d2aba2017-07-27 10:23:47 -050057DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu}
58OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build}
59UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}}
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050060LAUNCH=${LAUNCH:-local}
Andrew Geissler0c63ce12018-03-01 12:40:19 -080061DEFAULT_MACHINE=versatilepb
62MACHINE=${MACHINE:-${DEFAULT_MACHINE}}
63
64# The automated test suite needs a real machine type so
65# if we're using versatilepb for our qemu start parameter
66# then we need to just let our run-robot use the default
67if [[ $MACHINE == $DEFAULT_MACHINE ]]; then
68 MACHINE_QEMU=
69else
70 MACHINE_QEMU=${MACHINE}
71fi
Andrew Geissler0205e8d2016-08-10 07:46:19 -050072
Alanny Lopez74d2aba2017-07-27 10:23:47 -050073# Determine the architecture
74ARCH=$(uname -m)
Andrew Geissler0205e8d2016-08-10 07:46:19 -050075
Alanny Lopez74d2aba2017-07-27 10:23:47 -050076# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable
77case ${ARCH} in
78 "ppc64le")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050079 DOCKER_BASE="ppc64le/"
80 QEMU_ARCH="ppc64le-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050081 ;;
82 "x86_64")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050083 DOCKER_BASE=""
84 QEMU_ARCH="x86_64-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050085 ;;
86 *)
87 echo "Unsupported system architecture(${ARCH}) found for docker image"
88 exit 1
89esac
Andrew Geissler0205e8d2016-08-10 07:46:19 -050090
Andrew Geissler7a88f292018-01-04 15:16:02 -060091# Set the location of the qemu binary relative to UPSTREAM_WORKSPACE
92QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
93
Alanny Lopez74d2aba2017-07-27 10:23:47 -050094# Get the base directory of the openbmc-build-scripts repo so we can return
95DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
96
97# Create the base Docker image for QEMU and Robot
Andrew Geissler0205e8d2016-08-10 07:46:19 -050098. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME"
99
100# Copy the scripts to start and verify QEMU in the workspace
101cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE}
102
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500103################################################################################
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500104
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500105if [[ ${LAUNCH} == "local" ]]; then
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500106
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500107 # Start QEMU docker instance
108 # root in docker required to open up the https/ssh ports
109 obmc_qemu_docker=$(docker run --detach \
Lei YUf2e658b2020-06-17 18:02:43 +0800110 --rm \
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500111 --user root \
112 --env HOME=${OBMC_BUILD_DIR} \
113 --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \
114 --env QEMU_ARCH=${QEMU_ARCH} \
Andrew Geissler7a88f292018-01-04 15:16:02 -0600115 --env QEMU_BIN=${QEMU_BIN} \
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -0600116 --env MACHINE=${MACHINE} \
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500117 --workdir "${OBMC_BUILD_DIR}" \
118 --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \
119 --tty \
120 ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp)
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500121
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500122 # We can use default ports because we're going to have the 2
123 # docker instances talk over their private network
124 DOCKER_SSH_PORT=22
125 DOCKER_HTTPS_PORT=443
Andrew Geissler9d913fe2018-02-21 08:29:39 -0800126
127 # This docker command intermittently asserts a SIGPIPE which
128 # causes the whole script to fail. The IP address comes through
129 # fine on these errors so just ignore the SIGPIPE
130 trap '' PIPE
131
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500132 DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \
Andrew Geissler5b4a0d22018-04-03 11:11:02 -0700133 grep "IPAddress\":" | tail -n1 | cut -d '"' -f 4)"
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500134
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500135 #Now wait for the OpenBMC QEMU Docker instance to get to standby
Andrew Geissler27876c52018-02-21 08:18:35 -0800136 delay=5
137 attempt=$(( $QEMU_LOGIN_TIMER / $delay ))
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500138 while [ $attempt -gt 0 ]; do
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500139 attempt=$(( $attempt - 1 ))
140 echo "Waiting for qemu to get to standby (attempt: $attempt)..."
141 result=$(docker logs $obmc_qemu_docker)
142 if grep -q 'OPENBMC-READY' <<< $result ; then
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500143 echo "QEMU is ready!"
George Keishing11a6e9e2019-07-22 08:18:40 -0500144 # Give QEMU a few secs to stabilize
Andrew Geissler27876c52018-02-21 08:18:35 -0800145 sleep $delay
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500146 break
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500147 fi
Andrew Geissler27876c52018-02-21 08:18:35 -0800148 sleep $delay
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500149 done
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500150
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500151 if [ "$attempt" -eq 0 ]; then
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500152 echo "Timed out waiting for QEMU, exiting"
153 exit 1
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500154 fi
155
156 # Now run the Robot test (Tests commented out until they are working again)
157
158 # Timestamp for job
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800159 echo "Robot Test started, $(date)"
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500160
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800161 mkdir -p ${WORKSPACE}
162 cd ${WORKSPACE}
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500163
164 # Copy in the script which will execute the Robot tests
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800165 cp $DIR/scripts/run-robot.sh ${WORKSPACE}
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500166
167 # Run the Docker container to execute the Robot test cases
168 # The test results will be put in ${WORKSPACE}
Andrew Geissler0c63ce12018-03-01 12:40:19 -0800169 docker run --rm \
170 --user root \
171 --env HOME=${HOME} \
172 --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \
173 --env SSH_PORT=${DOCKER_SSH_PORT} \
174 --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \
175 --env MACHINE=${MACHINE_QEMU} \
176 --workdir ${HOME} \
177 --volume ${WORKSPACE}:${HOME} \
178 --tty \
179 ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500180
181 # Now stop the QEMU Docker image
182 docker stop $obmc_qemu_docker
183
184elif [[ ${LAUNCH} == "k8s" ]]; then
185 # Package the Upstream into an image based off the one created by the build-qemu-robot.sh
186 # Dockerfile = $( cat << EOF
187 imgname=$DOCKER_IMG_NAME
188 cd $DIR
189 source ./kubernetes/kubernetes-launch.sh QEMU-launch false false deployment
190
191 # Xcat Launch (NYI)
192
193 # source ./kubernetes/kubernetes-launch.sh XCAT-launch true true
194
195else
196 echo "LAUNCH variable invalid, Exiting"
197 exit 1
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500198fi