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 | # |
| 5 | # It uses a few variables which are part of Jenkins build job matrix: |
| 6 | # distro = fedora|ubuntu|ubuntu:14.04|ubuntu:16.04 |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [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 | # WORKSPACE = <location of unit test execution script> |
| 9 | |
| 10 | # Trace bash processing. Set -e so when a step fails, we fail the build |
| 11 | set -uo pipefail |
| 12 | |
| 13 | # Default variables |
| 14 | DOCKER_IMG_NAME="openbmc/ubuntu-unit-test" |
| 15 | DISTRO=${distro:-ubuntu:latest} |
| 16 | WORKSPACE=${WORKSPACE:-${TMP}/unit-test${RANDOM}} |
| 17 | OBMC_BUILD_SCRIPTS="openbmc-build-scripts" |
| 18 | UNIT_TEST_PY_DIR="scripts" |
| 19 | UNIT_TEST_PY="unit-test.py" |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 20 | FORMAT_CODE_SH="format-code.sh" |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 21 | DBUS_UNIT_TEST_PY="dbus-unit-test.py" |
| 22 | DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"} |
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 | |
| 27 | # Currently only support ubuntu:latest due to systemd requirements |
| 28 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
| 29 | DISTRO="ubuntu:latest" |
| 30 | elif [[ "${DISTRO}" == "fedora" ]]; then |
| 31 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 32 | DISTRO="ubuntu:latest" |
| 33 | fi |
| 34 | |
| 35 | # Check workspace, build scripts, and package to be unit tested exists |
| 36 | if [ ! -d "${WORKSPACE}" ]; then |
| 37 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 38 | exit 1 |
| 39 | fi |
| 40 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 41 | echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." |
| 42 | exit 1 |
| 43 | fi |
| 44 | if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then |
| 45 | echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..." |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | # Copy unit test script into workspace |
| 50 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \ |
| 51 | ${WORKSPACE}/${UNIT_TEST_PY} |
| 52 | chmod a+x ${WORKSPACE}/${UNIT_TEST_PY} |
| 53 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 54 | # Copy dbus unit test script into workspace |
| 55 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \ |
| 56 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 57 | chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 58 | |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 59 | # Copy format code script into workspace |
| 60 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \ |
| 61 | ${WORKSPACE}/${FORMAT_CODE_SH} |
| 62 | chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH} |
| 63 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 64 | # Configure docker build |
| 65 | cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS} |
| 66 | echo "Building docker image with build-unit-test-docker.sh" |
| 67 | ./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO} |
| 68 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 69 | # Unit test and parameters |
| 70 | UNIT_TEST="${WORKSPACE}/${UNIT_TEST_PY},-w,${WORKSPACE},-p,${UNIT_TEST_PKG},-v" |
| 71 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 72 | # Run the docker unit test container with the unit test execution script |
| 73 | echo "Executing docker image" |
| 74 | docker run --cap-add=sys_admin --rm=true \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 75 | --privileged=true \ |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 76 | -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \ |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 77 | -t ${DOCKER_IMG_NAME} \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 78 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \ |
| 79 | -f ${DBUS_SYS_CONFIG_FILE} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 80 | |
| 81 | # Timestamp for build |
| 82 | echo "Unit test build completed, $(date)" |