blob: 1c056f3131946709da6aff8733c57a703ed69d34 [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 Geissler61363572019-01-03 14:00:10 -06005# UNIT_TEST_PKG = Required, repository which has been extracted and is to
6# be tested.
7# WORKSPACE = Required, location of unit test scripts and repository code to
8# test.
Andrew Jeffery4b4a6bc2018-03-08 12:58:48 +10309# DISTRO = Docker base image. Ubuntu and Fedora are supported.
Andrew Jeffery4b4a6bc2018-03-08 12:58:48 +103010# dbus_sys_config_file = <path of the dbus config file>
Andrew Geisslera6b93bf2019-01-03 10:23:38 -060011# BRANCH = <optional, branch to build from each of the openbmc/respositories>
12# default is master, which will be used if input branch not
13# provided or not found
14# DOCKER_IMG_NAME = Default is openbmc/ubuntu-unit-test-master with a
15# -$BRANCH replacing -master if $BRANCH provided
Matthew Barthc5dec752016-11-18 13:14:37 -060016
17# Trace bash processing. Set -e so when a step fails, we fail the build
18set -uo pipefail
19
20# Default variables
Andrew Geisslera6b93bf2019-01-03 10:23:38 -060021DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-unit-test-${BRANCH:-master}"}
Patrick Venture52164fd2018-08-28 16:12:47 -070022DISTRO=${DISTRO:-ubuntu:bionic}
Matthew Barthc5dec752016-11-18 13:14:37 -060023OBMC_BUILD_SCRIPTS="openbmc-build-scripts"
24UNIT_TEST_PY_DIR="scripts"
25UNIT_TEST_PY="unit-test.py"
Andrew Geisslera28286d2018-01-10 11:00:00 -080026FORMAT_CODE_SH="format-code.sh"
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060027DBUS_UNIT_TEST_PY="dbus-unit-test.py"
28DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"}
Andrew Jefferya153ee32018-03-09 13:22:04 +103029MAKEFLAGS="${MAKEFLAGS:-""}"
William A. Kennington IIId70980f2018-11-08 15:14:27 -080030DOCKER_WORKDIR="${DOCKER_WORKDIR:-$WORKSPACE}"
Matthew Barthc5dec752016-11-18 13:14:37 -060031
32# Timestamp for job
33echo "Unit test build started, $(date)"
34
Andrew Jeffery316ebd32018-03-08 13:05:32 +103035if [[ "${DISTRO}" == "fedora" ]]; then
Matthew Barthc5dec752016-11-18 13:14:37 -060036 echo "Distro (${DISTRO}) not supported, running as ubuntu"
37 DISTRO="ubuntu:latest"
38fi
39
40# Check workspace, build scripts, and package to be unit tested exists
41if [ ! -d "${WORKSPACE}" ]; then
42 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
43 exit 1
44fi
45if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
46 echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..."
47 exit 1
48fi
49if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then
50 echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..."
51 exit 1
52fi
53
54# Copy unit test script into workspace
55cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \
56${WORKSPACE}/${UNIT_TEST_PY}
57chmod a+x ${WORKSPACE}/${UNIT_TEST_PY}
58
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060059# Copy dbus unit test script into workspace
60cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \
61${WORKSPACE}/${DBUS_UNIT_TEST_PY}
62chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
63
Andrew Geisslera28286d2018-01-10 11:00:00 -080064# Copy format code script into workspace
65cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \
66${WORKSPACE}/${FORMAT_CODE_SH}
67chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH}
68
Matthew Barthc5dec752016-11-18 13:14:37 -060069# Configure docker build
70cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
71echo "Building docker image with build-unit-test-docker.sh"
Andrew Geisslera6b93bf2019-01-03 10:23:38 -060072# Export input env variables
73export DOCKER_IMG_NAME
74export DISTRO
75export BRANCH
76./build-unit-test-docker.sh
Matthew Barthc5dec752016-11-18 13:14:37 -060077
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060078# Unit test and parameters
William A. Kennington IIId70980f2018-11-08 15:14:27 -080079UNIT_TEST="${DOCKER_WORKDIR}/${UNIT_TEST_PY},-w,${DOCKER_WORKDIR},-p,${UNIT_TEST_PKG},-v"
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060080
Matthew Barthc5dec752016-11-18 13:14:37 -060081# Run the docker unit test container with the unit test execution script
82echo "Executing docker image"
83docker run --cap-add=sys_admin --rm=true \
James Feist878df5c2018-07-26 14:54:28 -070084 --network host \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060085 --privileged=true \
William A. Kennington IIIbe6aab22018-12-06 15:01:54 -080086 -u "$USER" \
William A. Kennington IIId70980f2018-11-08 15:14:27 -080087 -w "${DOCKER_WORKDIR}" -v "${WORKSPACE}":"${DOCKER_WORKDIR}" \
Andrew Jefferya153ee32018-03-09 13:22:04 +103088 -e "MAKEFLAGS=${MAKEFLAGS}" \
Matthew Barth33df8792016-12-19 14:30:17 -060089 -t ${DOCKER_IMG_NAME} \
William A. Kennington IIId70980f2018-11-08 15:14:27 -080090 "${DOCKER_WORKDIR}"/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -060091 -f ${DBUS_SYS_CONFIG_FILE}
Matthew Barthc5dec752016-11-18 13:14:37 -060092
93# Timestamp for build
94echo "Unit test build completed, $(date)"