blob: 32786b90d034df38f45a3e8b38c5ab14d1b9addb [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.
21# DOCKER_IMG_NAME = Defaults to openbmc/ubuntu-robot-qemu, the name the
22# Docker image will be tagged with when built.
23# OBMC_BUILD_DIR = Defaults to /tmp/openbmc/build, the path to the
24# directory where the UPSTREAM_WORKSPACE build files will
25# be mounted to. Since the build containers have been
26# changed to use /tmp as the parent directory for their
27# builds, move the mounting location to be the same to
28# resolve issues with file links or referrals to exact
29# paths in the original build directory. If the build
30# directory was changed in the build-setup.sh run, this
31# variable should also be changed. Otherwise, the default
32# should be used.
33#
34###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050035
36set -uo pipefail
37
Alanny Lopez74d2aba2017-07-27 10:23:47 -050038QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300}
Andrew Geissler1df680a2016-08-22 14:37:39 -050039WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez74d2aba2017-07-27 10:23:47 -050040DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu}
41OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build}
42UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}}
Andrew Geissler0205e8d2016-08-10 07:46:19 -050043
Alanny Lopez74d2aba2017-07-27 10:23:47 -050044# Determine the architecture
45ARCH=$(uname -m)
Andrew Geissler0205e8d2016-08-10 07:46:19 -050046
Alanny Lopez74d2aba2017-07-27 10:23:47 -050047# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable
48case ${ARCH} in
49 "ppc64le")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050050 DOCKER_BASE="ppc64le/"
51 QEMU_ARCH="ppc64le-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050052 ;;
53 "x86_64")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050054 DOCKER_BASE=""
55 QEMU_ARCH="x86_64-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050056 ;;
57 *)
58 echo "Unsupported system architecture(${ARCH}) found for docker image"
59 exit 1
60esac
Andrew Geissler0205e8d2016-08-10 07:46:19 -050061
Alanny Lopez74d2aba2017-07-27 10:23:47 -050062# Get the base directory of the openbmc-build-scripts repo so we can return
63DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
64
65# Create the base Docker image for QEMU and Robot
Andrew Geissler0205e8d2016-08-10 07:46:19 -050066. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME"
67
68# Copy the scripts to start and verify QEMU in the workspace
69cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE}
70
Alanny Lopez74d2aba2017-07-27 10:23:47 -050071# Move into the upstream workspace directory
72cd ${UPSTREAM_WORKSPACE}
73
Andrew Geissler0205e8d2016-08-10 07:46:19 -050074# Start QEMU docker instance
75# root in docker required to open up the https/ssh ports
Leonel Gonzalez10a193c2017-02-10 11:06:58 -060076obmc_qemu_docker=$(docker run --detach \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050077 --user root \
Alanny Lopez74d2aba2017-07-27 10:23:47 -050078 --env HOME=${OBMC_BUILD_DIR} \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050079 --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \
80 --env QEMU_ARCH=${QEMU_ARCH} \
Alanny Lopez74d2aba2017-07-27 10:23:47 -050081 --workdir "${OBMC_BUILD_DIR}" \
82 --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050083 --tty \
Alanny Lopez74d2aba2017-07-27 10:23:47 -050084 ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp)
85
Andrew Geissler0205e8d2016-08-10 07:46:19 -050086
87# We can use default ports because we're going to have the 2
88# docker instances talk over their private network
89DOCKER_SSH_PORT=22
90DOCKER_HTTPS_PORT=443
91DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \
92 grep -m 1 "IPAddress\":" | cut -d '"' -f 4)"
93
Alanny Lopez74d2aba2017-07-27 10:23:47 -050094# Now wait for the OpenBMC QEMU Docker instance to get to standby
Andrew Geissler0205e8d2016-08-10 07:46:19 -050095attempt=60
96while [ $attempt -gt 0 ]; do
97 attempt=$(( $attempt - 1 ))
98 echo "Waiting for qemu to get to standby (attempt: $attempt)..."
99 result=$(docker logs $obmc_qemu_docker)
100 if grep -q 'OPENBMC-READY' <<< $result ; then
101 echo "QEMU is ready!"
102 # Give QEMU a few secs to stablize
103 sleep 5
104 break
105 fi
106 sleep 2
107done
108
109if [ "$attempt" -eq 0 ]; then
110 echo "Timed out waiting for QEMU, exiting"
111 exit 1
112fi
113
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500114# Now run the Robot test
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500115
116# Timestamp for job
117echo "Robot Test started, $(date)"
118
119mkdir -p ${WORKSPACE}
120cd ${WORKSPACE}
121
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500122# Copy in the script which will execute the Robot tests
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500123cp $DIR/scripts/run-robot.sh ${WORKSPACE}
124
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500125# Run the Docker container to execute the Robot test cases
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500126# The test results will be put in ${WORKSPACE}
Andrew Geisslerd008c542017-02-02 10:46:20 -0600127docker run --rm \
128 --user root \
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500129 --env HOME=${HOME} \
130 --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \
131 --env SSH_PORT=${DOCKER_SSH_PORT} \
132 --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \
133 --workdir ${HOME} \
134 --volume ${WORKSPACE}:${HOME} \
135 --tty \
136 ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh
137
Alanny Lopez74d2aba2017-07-27 10:23:47 -0500138# Now stop the QEMU Docker image
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500139docker stop $obmc_qemu_docker