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