Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | # This build script is for running the Jenkins unit test builds using docker. |
| 4 | # |
Andrew Jeffery | 4b4a6bc | 2018-03-08 12:58:48 +1030 | [diff] [blame] | 5 | # DISTRO = Docker base image. Ubuntu and Fedora are supported. |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 6 | # WORKSPACE = <location of unit test execution script> |
Andrew Jeffery | 4b4a6bc | 2018-03-08 12:58:48 +1030 | [diff] [blame] | 7 | # dbus_sys_config_file = <path of the dbus config file> |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 8 | |
| 9 | # Trace bash processing. Set -e so when a step fails, we fail the build |
| 10 | set -uo pipefail |
| 11 | |
| 12 | # Default variables |
| 13 | DOCKER_IMG_NAME="openbmc/ubuntu-unit-test" |
Patrick Venture | 52164fd | 2018-08-28 16:12:47 -0700 | [diff] [blame] | 14 | DISTRO=${DISTRO:-ubuntu:bionic} |
Andrew Jeffery | 0b252e3 | 2018-03-08 13:03:12 +1030 | [diff] [blame] | 15 | WORKSPACE=${WORKSPACE:-$(mktemp -d --tmpdir unit-test.XXXXXX)} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 16 | OBMC_BUILD_SCRIPTS="openbmc-build-scripts" |
| 17 | UNIT_TEST_PY_DIR="scripts" |
| 18 | UNIT_TEST_PY="unit-test.py" |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 19 | FORMAT_CODE_SH="format-code.sh" |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 20 | DBUS_UNIT_TEST_PY="dbus-unit-test.py" |
| 21 | DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"} |
Andrew Jeffery | a153ee3 | 2018-03-09 13:22:04 +1030 | [diff] [blame] | 22 | MAKEFLAGS="${MAKEFLAGS:-""}" |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 23 | DOCKER_WORKDIR="${DOCKER_WORKDIR:-$WORKSPACE}" |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 24 | |
| 25 | # Timestamp for job |
| 26 | echo "Unit test build started, $(date)" |
| 27 | |
Andrew Jeffery | 316ebd3 | 2018-03-08 13:05:32 +1030 | [diff] [blame] | 28 | if [[ "${DISTRO}" == "fedora" ]]; then |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 29 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 30 | DISTRO="ubuntu:latest" |
| 31 | fi |
| 32 | |
| 33 | # Check workspace, build scripts, and package to be unit tested exists |
| 34 | if [ ! -d "${WORKSPACE}" ]; then |
| 35 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 36 | exit 1 |
| 37 | fi |
| 38 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 39 | echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." |
| 40 | exit 1 |
| 41 | fi |
| 42 | if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then |
| 43 | echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..." |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Copy unit test script into workspace |
| 48 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \ |
| 49 | ${WORKSPACE}/${UNIT_TEST_PY} |
| 50 | chmod a+x ${WORKSPACE}/${UNIT_TEST_PY} |
| 51 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 52 | # Copy dbus unit test script into workspace |
| 53 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \ |
| 54 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 55 | chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 56 | |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 57 | # Copy format code script into workspace |
| 58 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \ |
| 59 | ${WORKSPACE}/${FORMAT_CODE_SH} |
| 60 | chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH} |
| 61 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 62 | # Configure docker build |
| 63 | cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS} |
| 64 | echo "Building docker image with build-unit-test-docker.sh" |
| 65 | ./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO} |
| 66 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 67 | # Unit test and parameters |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 68 | UNIT_TEST="${DOCKER_WORKDIR}/${UNIT_TEST_PY},-w,${DOCKER_WORKDIR},-p,${UNIT_TEST_PKG},-v" |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 69 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 70 | # Run the docker unit test container with the unit test execution script |
| 71 | echo "Executing docker image" |
| 72 | docker run --cap-add=sys_admin --rm=true \ |
James Feist | 878df5c | 2018-07-26 14:54:28 -0700 | [diff] [blame] | 73 | --network host \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 74 | --privileged=true \ |
William A. Kennington III | be6aab2 | 2018-12-06 15:01:54 -0800 | [diff] [blame] | 75 | -u "$USER" \ |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 76 | -w "${DOCKER_WORKDIR}" -v "${WORKSPACE}":"${DOCKER_WORKDIR}" \ |
Andrew Jeffery | a153ee3 | 2018-03-09 13:22:04 +1030 | [diff] [blame] | 77 | -e "MAKEFLAGS=${MAKEFLAGS}" \ |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 78 | -t ${DOCKER_IMG_NAME} \ |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 79 | "${DOCKER_WORKDIR}"/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 80 | -f ${DBUS_SYS_CONFIG_FILE} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 81 | |
| 82 | # Timestamp for build |
| 83 | echo "Unit test build completed, $(date)" |