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" |
Andrew Jeffery | 53befe1 | 2018-03-08 14:07:25 +1030 | [diff] [blame] | 14 | DISTRO=${DISTRO:-ubuntu:artful} |
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:-""}" |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 23 | |
| 24 | # Timestamp for job |
| 25 | echo "Unit test build started, $(date)" |
| 26 | |
Andrew Jeffery | 316ebd3 | 2018-03-08 13:05:32 +1030 | [diff] [blame] | 27 | if [[ "${DISTRO}" == "fedora" ]]; then |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 28 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 29 | DISTRO="ubuntu:latest" |
| 30 | fi |
| 31 | |
| 32 | # Check workspace, build scripts, and package to be unit tested exists |
| 33 | if [ ! -d "${WORKSPACE}" ]; then |
| 34 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 35 | exit 1 |
| 36 | fi |
| 37 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 38 | echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." |
| 39 | exit 1 |
| 40 | fi |
| 41 | if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then |
| 42 | echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..." |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | # Copy unit test script into workspace |
| 47 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \ |
| 48 | ${WORKSPACE}/${UNIT_TEST_PY} |
| 49 | chmod a+x ${WORKSPACE}/${UNIT_TEST_PY} |
| 50 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 51 | # Copy dbus unit test script into workspace |
| 52 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \ |
| 53 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 54 | chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 55 | |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 56 | # Copy format code script into workspace |
| 57 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \ |
| 58 | ${WORKSPACE}/${FORMAT_CODE_SH} |
| 59 | chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH} |
| 60 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 61 | # Configure docker build |
| 62 | cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS} |
| 63 | echo "Building docker image with build-unit-test-docker.sh" |
| 64 | ./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO} |
| 65 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 66 | # Unit test and parameters |
| 67 | UNIT_TEST="${WORKSPACE}/${UNIT_TEST_PY},-w,${WORKSPACE},-p,${UNIT_TEST_PKG},-v" |
| 68 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 69 | # Run the docker unit test container with the unit test execution script |
| 70 | echo "Executing docker image" |
| 71 | docker run --cap-add=sys_admin --rm=true \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 72 | --privileged=true \ |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 73 | -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \ |
Andrew Jeffery | a153ee3 | 2018-03-09 13:22:04 +1030 | [diff] [blame] | 74 | -e "MAKEFLAGS=${MAKEFLAGS}" \ |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 75 | -t ${DOCKER_IMG_NAME} \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 76 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \ |
| 77 | -f ${DBUS_SYS_CONFIG_FILE} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 78 | |
| 79 | # Timestamp for build |
| 80 | echo "Unit test build completed, $(date)" |