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