1#!/bin/bash -xe 2############################################################################### 3# 4# 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# LAUNCH = Used to determine how to launch the qemu robot test 34# containers. The options are "local", and "k8s". It will 35# default to local which will launch a single container 36# to do the runs. If specified k8s will launch a group of 37# containers into a kubernetes cluster using the helper 38# script. 39# QEMU_BIN = Location of qemu-system-arm binary to use when starting 40# QEMU relative to upstream workspace. Default is 41# ./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm 42# which is the default location when doing a bitbake 43# of obmc-phosphor-image 44# 45# MACHINE = Machine to run test against. The options are "witherspoon", 46# "palmetto", "romulus", or undefined (default). Default 47# will use the versatilepb model. 48############################################################################### 49 50set -uo pipefail 51 52QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300} 53WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 54DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu} 55OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build} 56UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}} 57LAUNCH=${LAUNCH:-local} 58MACHINE=${MACHINE:-versatilepb} 59 60# Determine the architecture 61ARCH=$(uname -m) 62 63# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable 64case ${ARCH} in 65 "ppc64le") 66 DOCKER_BASE="ppc64le/" 67 QEMU_ARCH="ppc64le-linux" 68 ;; 69 "x86_64") 70 DOCKER_BASE="" 71 QEMU_ARCH="x86_64-linux" 72 ;; 73 *) 74 echo "Unsupported system architecture(${ARCH}) found for docker image" 75 exit 1 76esac 77 78# Set the location of the qemu binary relative to UPSTREAM_WORKSPACE 79QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm} 80 81# Get the base directory of the openbmc-build-scripts repo so we can return 82DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 83 84# Create the base Docker image for QEMU and Robot 85. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" 86 87# Copy the scripts to start and verify QEMU in the workspace 88cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} 89 90################################################################################ 91 92if [[ ${LAUNCH} == "local" ]]; then 93 94 # Start QEMU docker instance 95 # root in docker required to open up the https/ssh ports 96 obmc_qemu_docker=$(docker run --detach \ 97 --user root \ 98 --env HOME=${OBMC_BUILD_DIR} \ 99 --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \ 100 --env QEMU_ARCH=${QEMU_ARCH} \ 101 --env QEMU_BIN=${QEMU_BIN} \ 102 --env MACHINE=${MACHINE} \ 103 --workdir "${OBMC_BUILD_DIR}" \ 104 --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \ 105 --tty \ 106 ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp) 107 108 # We can use default ports because we're going to have the 2 109 # docker instances talk over their private network 110 DOCKER_SSH_PORT=22 111 DOCKER_HTTPS_PORT=443 112 DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \ 113 grep -m 1 "IPAddress\":" | cut -d '"' -f 4)" 114 115 #Now wait for the OpenBMC QEMU Docker instance to get to standby 116 attempt=60 117 while [ $attempt -gt 0 ]; do 118 attempt=$(( $attempt - 1 )) 119 echo "Waiting for qemu to get to standby (attempt: $attempt)..." 120 result=$(docker logs $obmc_qemu_docker) 121 if grep -q 'OPENBMC-READY' <<< $result ; then 122 echo "QEMU is ready!" 123 # Give QEMU a few secs to stablize 124 sleep 5 125 break 126 fi 127 sleep 2 128 done 129 130 if [ "$attempt" -eq 0 ]; then 131 echo "Timed out waiting for QEMU, exiting" 132 exit 1 133 fi 134 135 # Now run the Robot test (Tests commented out until they are working again) 136 137 # Timestamp for job 138 #echo "Robot Test started, $(date)" 139 140 #mkdir -p ${WORKSPACE} 141 #cd ${WORKSPACE} 142 143 # Copy in the script which will execute the Robot tests 144 #cp $DIR/scripts/run-robot.sh ${WORKSPACE} 145 146 # Run the Docker container to execute the Robot test cases 147 # The test results will be put in ${WORKSPACE} 148 #docker run --rm \ 149 # --user root \ 150 # --env HOME=${HOME} \ 151 # --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \ 152 # --env SSH_PORT=${DOCKER_SSH_PORT} \ 153 # --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \ 154 # --workdir ${HOME} \ 155 # --volume ${WORKSPACE}:${HOME} \ 156 # --tty \ 157 # ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh 158 159 # Now stop the QEMU Docker image 160 docker stop $obmc_qemu_docker 161 162elif [[ ${LAUNCH} == "k8s" ]]; then 163 # Package the Upstream into an image based off the one created by the build-qemu-robot.sh 164 # Dockerfile = $( cat << EOF 165 imgname=$DOCKER_IMG_NAME 166 cd $DIR 167 source ./kubernetes/kubernetes-launch.sh QEMU-launch false false deployment 168 169 # Xcat Launch (NYI) 170 171 # source ./kubernetes/kubernetes-launch.sh XCAT-launch true true 172 173else 174 echo "LAUNCH variable invalid, Exiting" 175 exit 1 176fi 177