blob: 5a07de9590f3d16fa93439478153b7a3fb50d633 [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"
Andrew Jeffery53befe12018-03-08 14:07:25 +103014DISTRO=${DISTRO:-ubuntu:artful}
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:-""}"
Matthew Barthc5dec752016-11-18 13:14:37 -060023
24# Timestamp for job
25echo "Unit test build started, $(date)"
26
Andrew Jeffery316ebd32018-03-08 13:05:32 +103027if [[ "${DISTRO}" == "fedora" ]]; then
Matthew Barthc5dec752016-11-18 13:14:37 -060028 echo "Distro (${DISTRO}) not supported, running as ubuntu"
29 DISTRO="ubuntu:latest"
30fi
31
32# Check workspace, build scripts, and package to be unit tested exists
33if [ ! -d "${WORKSPACE}" ]; then
34 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
35 exit 1
36fi
37if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
38 echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..."
39 exit 1
40fi
41if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then
42 echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..."
43 exit 1
44fi
45
46# Copy unit test script into workspace
47cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \
48${WORKSPACE}/${UNIT_TEST_PY}
49chmod a+x ${WORKSPACE}/${UNIT_TEST_PY}
50
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060051# Copy dbus unit test script into workspace
52cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \
53${WORKSPACE}/${DBUS_UNIT_TEST_PY}
54chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
55
Andrew Geisslera28286d2018-01-10 11:00:00 -080056# Copy format code script into workspace
57cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \
58${WORKSPACE}/${FORMAT_CODE_SH}
59chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH}
60
Matthew Barthc5dec752016-11-18 13:14:37 -060061# Configure docker build
62cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
63echo "Building docker image with build-unit-test-docker.sh"
64./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO}
65
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060066# Unit test and parameters
67UNIT_TEST="${WORKSPACE}/${UNIT_TEST_PY},-w,${WORKSPACE},-p,${UNIT_TEST_PKG},-v"
68
Matthew Barthc5dec752016-11-18 13:14:37 -060069# Run the docker unit test container with the unit test execution script
70echo "Executing docker image"
71docker run --cap-add=sys_admin --rm=true \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060072 --privileged=true \
Matthew Barthc5dec752016-11-18 13:14:37 -060073 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
Andrew Jefferya153ee32018-03-09 13:22:04 +103074 -e "MAKEFLAGS=${MAKEFLAGS}" \
Matthew Barth33df8792016-12-19 14:30:17 -060075 -t ${DOCKER_IMG_NAME} \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060076 ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \
77 -f ${DBUS_SYS_CONFIG_FILE}
Matthew Barthc5dec752016-11-18 13:14:37 -060078
79# Timestamp for build
80echo "Unit test build completed, $(date)"