blob: 847555657a163fa06b17be9cd860224c4768ae7f [file] [log] [blame]
Matthew Barthc5dec752016-11-18 13:14:37 -06001#!/bin/bash -xe
2
3# This build script is for running the Jenkins unit test builds using docker.
4#
Andrew Jeffery4b4a6bc2018-03-08 12:58:48 +10305# DISTRO = Docker base image. Ubuntu and Fedora are supported.
Matthew Barthc5dec752016-11-18 13:14:37 -06006# WORKSPACE = <location of unit test execution script>
Andrew Jeffery4b4a6bc2018-03-08 12:58:48 +10307# dbus_sys_config_file = <path of the dbus config file>
Matthew Barthc5dec752016-11-18 13:14:37 -06008
9# Trace bash processing. Set -e so when a step fails, we fail the build
10set -uo pipefail
11
12# Default variables
13DOCKER_IMG_NAME="openbmc/ubuntu-unit-test"
Patrick Venture52164fd2018-08-28 16:12:47 -070014DISTRO=${DISTRO:-ubuntu:bionic}
Andrew Jeffery0b252e32018-03-08 13:03:12 +103015WORKSPACE=${WORKSPACE:-$(mktemp -d --tmpdir unit-test.XXXXXX)}
Matthew Barthc5dec752016-11-18 13:14:37 -060016OBMC_BUILD_SCRIPTS="openbmc-build-scripts"
17UNIT_TEST_PY_DIR="scripts"
18UNIT_TEST_PY="unit-test.py"
Andrew Geisslera28286d2018-01-10 11:00:00 -080019FORMAT_CODE_SH="format-code.sh"
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060020DBUS_UNIT_TEST_PY="dbus-unit-test.py"
21DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"}
Andrew Jefferya153ee32018-03-09 13:22:04 +103022MAKEFLAGS="${MAKEFLAGS:-""}"
William A. Kennington IIId70980f2018-11-08 15:14:27 -080023DOCKER_WORKDIR="${DOCKER_WORKDIR:-$WORKSPACE}"
Matthew Barthc5dec752016-11-18 13:14:37 -060024
25# Timestamp for job
26echo "Unit test build started, $(date)"
27
Andrew Jeffery316ebd32018-03-08 13:05:32 +103028if [[ "${DISTRO}" == "fedora" ]]; then
Matthew Barthc5dec752016-11-18 13:14:37 -060029 echo "Distro (${DISTRO}) not supported, running as ubuntu"
30 DISTRO="ubuntu:latest"
31fi
32
33# Check workspace, build scripts, and package to be unit tested exists
34if [ ! -d "${WORKSPACE}" ]; then
35 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
36 exit 1
37fi
38if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
39 echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..."
40 exit 1
41fi
42if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then
43 echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..."
44 exit 1
45fi
46
47# Copy unit test script into workspace
48cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \
49${WORKSPACE}/${UNIT_TEST_PY}
50chmod a+x ${WORKSPACE}/${UNIT_TEST_PY}
51
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060052# Copy dbus unit test script into workspace
53cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \
54${WORKSPACE}/${DBUS_UNIT_TEST_PY}
55chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
56
Andrew Geisslera28286d2018-01-10 11:00:00 -080057# Copy format code script into workspace
58cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \
59${WORKSPACE}/${FORMAT_CODE_SH}
60chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH}
61
Matthew Barthc5dec752016-11-18 13:14:37 -060062# Configure docker build
63cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
64echo "Building docker image with build-unit-test-docker.sh"
65./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO}
66
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060067# Unit test and parameters
William A. Kennington IIId70980f2018-11-08 15:14:27 -080068UNIT_TEST="${DOCKER_WORKDIR}/${UNIT_TEST_PY},-w,${DOCKER_WORKDIR},-p,${UNIT_TEST_PKG},-v"
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060069
Matthew Barthc5dec752016-11-18 13:14:37 -060070# Run the docker unit test container with the unit test execution script
71echo "Executing docker image"
72docker run --cap-add=sys_admin --rm=true \
James Feist878df5c2018-07-26 14:54:28 -070073 --network host \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060074 --privileged=true \
William A. Kennington IIIbe6aab22018-12-06 15:01:54 -080075 -u "$USER" \
William A. Kennington IIId70980f2018-11-08 15:14:27 -080076 -w "${DOCKER_WORKDIR}" -v "${WORKSPACE}":"${DOCKER_WORKDIR}" \
Andrew Jefferya153ee32018-03-09 13:22:04 +103077 -e "MAKEFLAGS=${MAKEFLAGS}" \
Matthew Barth33df8792016-12-19 14:30:17 -060078 -t ${DOCKER_IMG_NAME} \
William A. Kennington IIId70980f2018-11-08 15:14:27 -080079 "${DOCKER_WORKDIR}"/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060080 -f ${DBUS_SYS_CONFIG_FILE}
Matthew Barthc5dec752016-11-18 13:14:37 -060081
82# Timestamp for build
83echo "Unit test build completed, $(date)"