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