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. |
| 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 Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 35 | |
| 36 | set -uo pipefail |
| 37 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 38 | QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300} |
Andrew Geissler | 1df680a | 2016-08-22 14:37:39 -0500 | [diff] [blame] | 39 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 40 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu} |
| 41 | OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build} |
| 42 | UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}} |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 43 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 44 | # Determine the architecture |
| 45 | ARCH=$(uname -m) |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 46 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 47 | # Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable |
| 48 | case ${ARCH} in |
| 49 | "ppc64le") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 50 | DOCKER_BASE="ppc64le/" |
| 51 | QEMU_ARCH="ppc64le-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 52 | ;; |
| 53 | "x86_64") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 54 | DOCKER_BASE="" |
| 55 | QEMU_ARCH="x86_64-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 56 | ;; |
| 57 | *) |
| 58 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 59 | exit 1 |
| 60 | esac |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 61 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 62 | # Get the base directory of the openbmc-build-scripts repo so we can return |
| 63 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 64 | |
| 65 | # Create the base Docker image for QEMU and Robot |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 66 | . "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" |
| 67 | |
| 68 | # Copy the scripts to start and verify QEMU in the workspace |
| 69 | cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} |
| 70 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 71 | # Move into the upstream workspace directory |
| 72 | cd ${UPSTREAM_WORKSPACE} |
| 73 | |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 74 | # Start QEMU docker instance |
| 75 | # root in docker required to open up the https/ssh ports |
Leonel Gonzalez | 10a193c | 2017-02-10 11:06:58 -0600 | [diff] [blame] | 76 | obmc_qemu_docker=$(docker run --detach \ |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 77 | --user root \ |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 78 | --env HOME=${OBMC_BUILD_DIR} \ |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 79 | --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \ |
| 80 | --env QEMU_ARCH=${QEMU_ARCH} \ |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 81 | --workdir "${OBMC_BUILD_DIR}" \ |
| 82 | --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \ |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 83 | --tty \ |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 84 | ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp) |
| 85 | |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 86 | |
| 87 | # We can use default ports because we're going to have the 2 |
| 88 | # docker instances talk over their private network |
| 89 | DOCKER_SSH_PORT=22 |
| 90 | DOCKER_HTTPS_PORT=443 |
| 91 | DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \ |
| 92 | grep -m 1 "IPAddress\":" | cut -d '"' -f 4)" |
| 93 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 94 | # Now wait for the OpenBMC QEMU Docker instance to get to standby |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 95 | attempt=60 |
| 96 | while [ $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 |
| 107 | done |
| 108 | |
| 109 | if [ "$attempt" -eq 0 ]; then |
| 110 | echo "Timed out waiting for QEMU, exiting" |
| 111 | exit 1 |
| 112 | fi |
| 113 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 114 | # Now run the Robot test |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 115 | |
| 116 | # Timestamp for job |
| 117 | echo "Robot Test started, $(date)" |
| 118 | |
| 119 | mkdir -p ${WORKSPACE} |
| 120 | cd ${WORKSPACE} |
| 121 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 122 | # Copy in the script which will execute the Robot tests |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 123 | cp $DIR/scripts/run-robot.sh ${WORKSPACE} |
| 124 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 125 | # Run the Docker container to execute the Robot test cases |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 126 | # The test results will be put in ${WORKSPACE} |
Andrew Geissler | d008c54 | 2017-02-02 10:46:20 -0600 | [diff] [blame] | 127 | docker run --rm \ |
| 128 | --user root \ |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 129 | --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 Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame^] | 138 | # Now stop the QEMU Docker image |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 139 | docker stop $obmc_qemu_docker |