blob: 659c4ab9aec02b3b4e8634806584bd942cf87323 [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 Jeffery4b4a6bc2018-03-08 12:58:48 +103014DISTRO=${DISTRO:-ubuntu:latest}
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"}
Matthew Barthc5dec752016-11-18 13:14:37 -060022
23# Timestamp for job
24echo "Unit test build started, $(date)"
25
Andrew Jeffery316ebd32018-03-08 13:05:32 +103026if [[ "${DISTRO}" == "fedora" ]]; then
Matthew Barthc5dec752016-11-18 13:14:37 -060027 echo "Distro (${DISTRO}) not supported, running as ubuntu"
28 DISTRO="ubuntu:latest"
29fi
30
31# Check workspace, build scripts, and package to be unit tested exists
32if [ ! -d "${WORKSPACE}" ]; then
33 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
34 exit 1
35fi
36if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
37 echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..."
38 exit 1
39fi
40if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then
41 echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..."
42 exit 1
43fi
44
45# Copy unit test script into workspace
46cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \
47${WORKSPACE}/${UNIT_TEST_PY}
48chmod a+x ${WORKSPACE}/${UNIT_TEST_PY}
49
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060050# Copy dbus unit test script into workspace
51cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \
52${WORKSPACE}/${DBUS_UNIT_TEST_PY}
53chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
54
Andrew Geisslera28286d2018-01-10 11:00:00 -080055# Copy format code script into workspace
56cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \
57${WORKSPACE}/${FORMAT_CODE_SH}
58chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH}
59
Matthew Barthc5dec752016-11-18 13:14:37 -060060# Configure docker build
61cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
62echo "Building docker image with build-unit-test-docker.sh"
63./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO}
64
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060065# Unit test and parameters
66UNIT_TEST="${WORKSPACE}/${UNIT_TEST_PY},-w,${WORKSPACE},-p,${UNIT_TEST_PKG},-v"
67
Matthew Barthc5dec752016-11-18 13:14:37 -060068# Run the docker unit test container with the unit test execution script
69echo "Executing docker image"
70docker run --cap-add=sys_admin --rm=true \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060071 --privileged=true \
Matthew Barthc5dec752016-11-18 13:14:37 -060072 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
Matthew Barth33df8792016-12-19 14:30:17 -060073 -t ${DOCKER_IMG_NAME} \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060074 ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \
75 -f ${DBUS_SYS_CONFIG_FILE}
Matthew Barthc5dec752016-11-18 13:14:37 -060076
77# Timestamp for build
78echo "Unit test build completed, $(date)"