testing the packaging-farm command

The version 2.0.4 of the packaging-farm was published with tests for the packaging-farm command.

test environment

The primary command for packaging-farm is a Makefile for which a small script prepares the environment.

: ${LIBDIR:=/usr/lib/packaging-farm}
: ${CACHEDIR:=/var/cache/packaging-farm}

SILENT="--quiet --no-print-directory"

if [ "$1" = "--cd" ] ; then
    cd $(packaging-farm --var DIR_$1)

if [ "$1" = "--var" ] ; then

if [ "$1" = "--lock" ] ; then
# Check that lockfile exists
    type lockfile > /dev/null
# lockfile is found in the procmail package

    if lockfile -! -l$((24 * 60 * 60)) -r1 -s8 ${LOCK} > /dev/null 2>&1
        echo "${LOCK} present, abort" || /bin/true
        exit 0
        trap "rm -f ${LOCK}" EXIT

if [ ! -r Makefile -o -z "$(make ${SILENT} PACKAGE 2>/dev/null)" ] ; then
   cd ${LIBDIR}

make ${VAR_OPTIONS} "$@"

The goal of the tests is to ensure that the logic of the Makefile is working properly. The packaging-farm command will be used to run the Makefile to create more realistic use cases.
A shell script was added to the tests directory. Before running any test, it creates a fake environment in the tmp directory and removes it when it is done. To reduce the time needed to run the tests, a copy of a squeeze chroot for i386 is kept across tests. It is removed when the clean target is invoked in the top level makefile of packaging-farm, which happens before a package is built with debuild -uc -us.

error and verbosity

In case of error, the tests are re-run in verbose mode.

if ! run ; then
    set -x
    unset SILENT

When running in verbose mode, all shell lines numbers and file are reported with:

PS4=' ${FUNCNAME[0]}: $LINENO: '

The verbosity of the Makefile commands is controlled by the TRACE=yes environment variable which triggers the following lines in the Makefile itself.

export SHELL=$(warning ) bash

As a side effect, each command line being displayed will be prefixed with the file and line number of the rule in which it appears. It will not display the actual line of the command.

variable tests

A number of variables in packaging-farm are generated by a oneliner. They are tested for correctness.

function test_var() {
    [ "$(./packaging-farm --var ROLE)" = package ] # default ROLE
        # The list of packages is the list of directories found in ${CACHEDIR}/build
        mkdir $dir
        [ "$(./packaging-farm --var DIR_package1)" = $dir ]
        mkdir ${CACHEDIR}/build/package2
        [ "$(./packaging-farm --var PACKAGES)" = "package1 package2" ]
        rmdir ${CACHEDIR}/build/package?
    [ "$(./packaging-farm --var OSTYPE_debian)" = gnulinux ]
    [ "$(./packaging-farm --var DISTTYPE_unstable)" = debian ]
    [[ "$(./packaging-farm --var DISTTYPES_gnulinux)" =~ debian ]]
    [[ "$(./packaging-farm --var DISTRIBUTIONS_debian)" =~ unstable ]]
        export DISTRIBUTIONS="wheezy unstable"
        [ "$(./packaging-farm --var DISTTYPES)" = debian ]
        [ "$(./packaging-farm --var OSTYPES)" = gnulinux ]

In addition, some of them make use of the GNU Make Standard Library such as the uniq function to remove duplicates in the list of distributions (debian … ) to be considered. Testing for the uniqueness of the distribution name also ensures that the local copy of gmsl is properly included and used.

chroot initialization

The build environment (for an environment defined by DISTRIBUTION=squeeze ARCHITECTURE=i386 PACKAGE=package1 for instance) is made of a chroot which is mounted via AUFS if available. Testing for the operations involving such a chroot requires an actual chroot that is built with :

function squeeze() {
    if [ ! -d squeeze ] ; then
        debootstrap --variant=minbase --arch i386 squeeze squeeze

Before the tests run, all AUFS mounts are removed to take care of leftovers of a previously failed test:

mount | grep aufs | cut -d' ' -f3 | xargs --no-run-if-empty umount

The tests involving a chroot are expected to umount all the mount they created before exiting.

This entry was posted in XiVO. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>