Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | # This script is for starting QEMU against the input build and running |
| 4 | # the robot CI test suite against it. |
| 5 | # |
| 6 | # Parameters: |
| 7 | # UPSTREAM_WORKSPACE = <required, base dir of QEMU image> |
| 8 | # WORKSPACE = <optional, temp dir for robot script> |
| 9 | |
| 10 | set -uo pipefail |
| 11 | |
| 12 | QEMU_RUN_TIMER=300 |
| 13 | WORKSPACE=${WORKSPACE:-${HOME}}/${RANDOM}${RANDOM} |
| 14 | DOCKER_IMG_NAME="openbmc/ubuntu-robot-qemu" |
| 15 | |
| 16 | # Get base directory of our repo so we can find the scripts later |
| 17 | DIR="${BASH_SOURCE%/*}" |
| 18 | if [[ ! -d "$DIR" || "$DIR" == "." ]]; then DIR="$PWD"; fi |
| 19 | |
| 20 | cd ${UPSTREAM_WORKSPACE} |
| 21 | |
| 22 | # Determine our architecture, ppc64le or the other one |
| 23 | if [ $(uname -m) == "ppc64le" ]; then |
| 24 | DOCKER_BASE="ppc64le/" |
| 25 | QEMU_ARCH="ppc64le-linux" |
| 26 | else |
| 27 | DOCKER_BASE="" |
| 28 | QEMU_ARCH="x86_64-linux" |
| 29 | fi |
| 30 | |
| 31 | # Create the docker image that QEMU and Robot will run in |
| 32 | . "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" |
| 33 | |
| 34 | # Copy the scripts to start and verify QEMU in the workspace |
| 35 | cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} |
| 36 | |
| 37 | # Start QEMU docker instance |
| 38 | # root in docker required to open up the https/ssh ports |
| 39 | obmc_qemu_docker=$(docker run --detach \ |
| 40 | --user root \ |
| 41 | --env HOME=${HOME} \ |
| 42 | --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \ |
| 43 | --env QEMU_ARCH=${QEMU_ARCH} \ |
| 44 | --workdir "${HOME}" \ |
| 45 | --volume "${UPSTREAM_WORKSPACE}":"${HOME}" \ |
| 46 | --tty \ |
| 47 | ${DOCKER_IMG_NAME} ${HOME}/boot-qemu-test.exp) |
| 48 | |
| 49 | # We can use default ports because we're going to have the 2 |
| 50 | # docker instances talk over their private network |
| 51 | DOCKER_SSH_PORT=22 |
| 52 | DOCKER_HTTPS_PORT=443 |
| 53 | DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \ |
| 54 | grep -m 1 "IPAddress\":" | cut -d '"' -f 4)" |
| 55 | |
| 56 | # Now wait for the openbmc qemu docker instance to get to standby |
| 57 | attempt=60 |
| 58 | while [ $attempt -gt 0 ]; do |
| 59 | attempt=$(( $attempt - 1 )) |
| 60 | echo "Waiting for qemu to get to standby (attempt: $attempt)..." |
| 61 | result=$(docker logs $obmc_qemu_docker) |
| 62 | if grep -q 'OPENBMC-READY' <<< $result ; then |
| 63 | echo "QEMU is ready!" |
| 64 | # Give QEMU a few secs to stablize |
| 65 | sleep 5 |
| 66 | break |
| 67 | fi |
| 68 | sleep 2 |
| 69 | done |
| 70 | |
| 71 | if [ "$attempt" -eq 0 ]; then |
| 72 | echo "Timed out waiting for QEMU, exiting" |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | # Now run the robot test |
| 77 | |
| 78 | # Timestamp for job |
| 79 | echo "Robot Test started, $(date)" |
| 80 | |
| 81 | mkdir -p ${WORKSPACE} |
| 82 | cd ${WORKSPACE} |
| 83 | |
| 84 | # Copy in the script which will execute the robot tests |
| 85 | cp $DIR/scripts/run-robot.sh ${WORKSPACE} |
| 86 | |
| 87 | # Run the docker container to execute the robot test cases |
| 88 | # The test results will be put in ${WORKSPACE} |
| 89 | docker run --user root \ |
| 90 | --env HOME=${HOME} \ |
| 91 | --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \ |
| 92 | --env SSH_PORT=${DOCKER_SSH_PORT} \ |
| 93 | --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \ |
| 94 | --workdir ${HOME} \ |
| 95 | --volume ${WORKSPACE}:${HOME} \ |
| 96 | --tty \ |
| 97 | ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh |
| 98 | |
| 99 | # Now stop the QEMU docker image |
| 100 | docker stop $obmc_qemu_docker |