blob: 283017b71d1a6181f556ba4ffc7195ec3638b95f [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#
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 Gonzalez13ca3802017-03-07 14:08:44 -06007# dbus_sys_config_file = <path of the dbus config file>
Matthew Barthc5dec752016-11-18 13:14:37 -06008# WORKSPACE = <location of unit test execution script>
9
10# Trace bash processing. Set -e so when a step fails, we fail the build
11set -uo pipefail
12
13# Default variables
14DOCKER_IMG_NAME="openbmc/ubuntu-unit-test"
15DISTRO=${distro:-ubuntu:latest}
16WORKSPACE=${WORKSPACE:-${TMP}/unit-test${RANDOM}}
17OBMC_BUILD_SCRIPTS="openbmc-build-scripts"
18UNIT_TEST_PY_DIR="scripts"
19UNIT_TEST_PY="unit-test.py"
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"}
Matthew Barthc5dec752016-11-18 13:14:37 -060022
23# Timestamp for job
24echo "Unit test build started, $(date)"
25
26# Currently only support ubuntu:latest due to systemd requirements
27if [[ "${DISTRO}" == "ubuntu"* ]]; then
28 DISTRO="ubuntu:latest"
29elif [[ "${DISTRO}" == "fedora" ]]; then
30 echo "Distro (${DISTRO}) not supported, running as ubuntu"
31 DISTRO="ubuntu:latest"
32fi
33
34# Check workspace, build scripts, and package to be unit tested exists
35if [ ! -d "${WORKSPACE}" ]; then
36 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
37 exit 1
38fi
39if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
40 echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..."
41 exit 1
42fi
43if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then
44 echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..."
45 exit 1
46fi
47
48# Copy unit test script into workspace
49cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \
50${WORKSPACE}/${UNIT_TEST_PY}
51chmod a+x ${WORKSPACE}/${UNIT_TEST_PY}
52
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060053# Copy dbus unit test script into workspace
54cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \
55${WORKSPACE}/${DBUS_UNIT_TEST_PY}
56chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
57
Matthew Barthc5dec752016-11-18 13:14:37 -060058# Configure docker build
59cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
60echo "Building docker image with build-unit-test-docker.sh"
61./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO}
62
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060063# Unit test and parameters
64UNIT_TEST="${WORKSPACE}/${UNIT_TEST_PY},-w,${WORKSPACE},-p,${UNIT_TEST_PKG},-v"
65
Matthew Barthc5dec752016-11-18 13:14:37 -060066# Run the docker unit test container with the unit test execution script
67echo "Executing docker image"
68docker run --cap-add=sys_admin --rm=true \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060069 --privileged=true \
Matthew Barthc5dec752016-11-18 13:14:37 -060070 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
Matthew Barth33df8792016-12-19 14:30:17 -060071 -t ${DOCKER_IMG_NAME} \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060072 ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \
73 -f ${DBUS_SYS_CONFIG_FILE}
Matthew Barthc5dec752016-11-18 13:14:37 -060074
75# Timestamp for build
76echo "Unit test build completed, $(date)"