Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 1 | #!/bin/bash -xe |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 2 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 3 | # |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 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. |
Andrew Geissler | 27876c5 | 2018-02-21 08:18:35 -0800 | [diff] [blame] | 21 | # QEMU_LOGIN_TIMER = Defaults to 180, a timer for the QEMU container to reach |
| 22 | # login. |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 23 | # 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 Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 35 | # 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 Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame] | 41 | # 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 Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 46 | # |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 47 | # MACHINE = Machine to run test against. The options are "witherspoon", |
| 48 | # "palmetto", "romulus", or undefined (default). Default |
| 49 | # will use the versatilepb model. |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 50 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 51 | |
| 52 | set -uo pipefail |
| 53 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 54 | QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300} |
Andrew Geissler | 27876c5 | 2018-02-21 08:18:35 -0800 | [diff] [blame] | 55 | QEMU_LOGIN_TIMER=${QEMU_LOGIN_TIMER:-180} |
Andrew Geissler | 1df680a | 2016-08-22 14:37:39 -0500 | [diff] [blame] | 56 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 57 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu} |
| 58 | OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build} |
| 59 | UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}} |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 60 | LAUNCH=${LAUNCH:-local} |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 61 | MACHINE=${MACHINE:-versatilepb} |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 62 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 63 | # Determine the architecture |
| 64 | ARCH=$(uname -m) |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 65 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 66 | # Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable |
| 67 | case ${ARCH} in |
| 68 | "ppc64le") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 69 | DOCKER_BASE="ppc64le/" |
| 70 | QEMU_ARCH="ppc64le-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 71 | ;; |
| 72 | "x86_64") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 73 | DOCKER_BASE="" |
| 74 | QEMU_ARCH="x86_64-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 75 | ;; |
| 76 | *) |
| 77 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 78 | exit 1 |
| 79 | esac |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 80 | |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame] | 81 | # Set the location of the qemu binary relative to UPSTREAM_WORKSPACE |
| 82 | QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm} |
| 83 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 84 | # Get the base directory of the openbmc-build-scripts repo so we can return |
| 85 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 86 | |
| 87 | # Create the base Docker image for QEMU and Robot |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 88 | . "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" |
| 89 | |
| 90 | # Copy the scripts to start and verify QEMU in the workspace |
| 91 | cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} |
| 92 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 93 | ################################################################################ |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 94 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 95 | if [[ ${LAUNCH} == "local" ]]; then |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 96 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 97 | # Start QEMU docker instance |
| 98 | # root in docker required to open up the https/ssh ports |
| 99 | obmc_qemu_docker=$(docker run --detach \ |
| 100 | --user root \ |
| 101 | --env HOME=${OBMC_BUILD_DIR} \ |
| 102 | --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \ |
| 103 | --env QEMU_ARCH=${QEMU_ARCH} \ |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame] | 104 | --env QEMU_BIN=${QEMU_BIN} \ |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 105 | --env MACHINE=${MACHINE} \ |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 106 | --workdir "${OBMC_BUILD_DIR}" \ |
| 107 | --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \ |
| 108 | --tty \ |
| 109 | ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp) |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 110 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 111 | # We can use default ports because we're going to have the 2 |
| 112 | # docker instances talk over their private network |
| 113 | DOCKER_SSH_PORT=22 |
| 114 | DOCKER_HTTPS_PORT=443 |
Andrew Geissler | 9d913fe | 2018-02-21 08:29:39 -0800 | [diff] [blame] | 115 | |
| 116 | # This docker command intermittently asserts a SIGPIPE which |
| 117 | # causes the whole script to fail. The IP address comes through |
| 118 | # fine on these errors so just ignore the SIGPIPE |
| 119 | trap '' PIPE |
| 120 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 121 | DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \ |
| 122 | grep -m 1 "IPAddress\":" | cut -d '"' -f 4)" |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 123 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 124 | #Now wait for the OpenBMC QEMU Docker instance to get to standby |
Andrew Geissler | 27876c5 | 2018-02-21 08:18:35 -0800 | [diff] [blame] | 125 | delay=5 |
| 126 | attempt=$(( $QEMU_LOGIN_TIMER / $delay )) |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 127 | while [ $attempt -gt 0 ]; do |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 128 | attempt=$(( $attempt - 1 )) |
| 129 | echo "Waiting for qemu to get to standby (attempt: $attempt)..." |
| 130 | result=$(docker logs $obmc_qemu_docker) |
| 131 | if grep -q 'OPENBMC-READY' <<< $result ; then |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 132 | echo "QEMU is ready!" |
| 133 | # Give QEMU a few secs to stablize |
Andrew Geissler | 27876c5 | 2018-02-21 08:18:35 -0800 | [diff] [blame] | 134 | sleep $delay |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 135 | break |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 136 | fi |
Andrew Geissler | 27876c5 | 2018-02-21 08:18:35 -0800 | [diff] [blame] | 137 | sleep $delay |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 138 | done |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 139 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 140 | if [ "$attempt" -eq 0 ]; then |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 141 | echo "Timed out waiting for QEMU, exiting" |
| 142 | exit 1 |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 143 | fi |
| 144 | |
| 145 | # Now run the Robot test (Tests commented out until they are working again) |
| 146 | |
| 147 | # Timestamp for job |
| 148 | #echo "Robot Test started, $(date)" |
| 149 | |
| 150 | #mkdir -p ${WORKSPACE} |
| 151 | #cd ${WORKSPACE} |
| 152 | |
| 153 | # Copy in the script which will execute the Robot tests |
| 154 | #cp $DIR/scripts/run-robot.sh ${WORKSPACE} |
| 155 | |
| 156 | # Run the Docker container to execute the Robot test cases |
| 157 | # The test results will be put in ${WORKSPACE} |
| 158 | #docker run --rm \ |
| 159 | # --user root \ |
| 160 | # --env HOME=${HOME} \ |
| 161 | # --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \ |
| 162 | # --env SSH_PORT=${DOCKER_SSH_PORT} \ |
| 163 | # --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \ |
| 164 | # --workdir ${HOME} \ |
| 165 | # --volume ${WORKSPACE}:${HOME} \ |
| 166 | # --tty \ |
| 167 | # ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh |
| 168 | |
| 169 | # Now stop the QEMU Docker image |
| 170 | docker stop $obmc_qemu_docker |
| 171 | |
| 172 | elif [[ ${LAUNCH} == "k8s" ]]; then |
| 173 | # Package the Upstream into an image based off the one created by the build-qemu-robot.sh |
| 174 | # Dockerfile = $( cat << EOF |
| 175 | imgname=$DOCKER_IMG_NAME |
| 176 | cd $DIR |
| 177 | source ./kubernetes/kubernetes-launch.sh QEMU-launch false false deployment |
| 178 | |
| 179 | # Xcat Launch (NYI) |
| 180 | |
| 181 | # source ./kubernetes/kubernetes-launch.sh XCAT-launch true true |
| 182 | |
| 183 | else |
| 184 | echo "LAUNCH variable invalid, Exiting" |
| 185 | exit 1 |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 186 | fi |