Autopkgtest - Defining tests for Debian packages

This document describes how the autopkgtest tester core (the program adt-run) interprets and executes tests found in Debian source packages.

Overview

The source package provides a test metadata file debian/tests/control. This is a file containing zero or more RFC822-style stanzas, along these lines:

Tests: fred bill bongo
Restrictions: needs-root breaks-testbed

This example defines three tests, called fred, bill and bongo. The tests will be performed by executing debian/tests/fred, debian/tests/bill, etc. Each test program should, on success, exit with status 0 and print nothing to stderr; if a test exits nonzero, or prints to stderr, it is considered to have failed.

The cwd of each test is guaranteed to be the root of the source package, which will have been unpacked but not built. However note that the tests must test the installed version of the program. Tests may not modify the source tree (and may not have write access to it).

If the file to be executed has no execute bits set, chmod a+x is applied to it (this means that tests can be added in patches without the need for additional chmod; contrast this with debian/rules).

During execution of the test, the environment variable $AUTOPKGTEST_TMP will point to a directory for the execution of this particular test, which starts empty and will be deleted afterwards (so there is no need for the test to clean up files left there).

If tests want to create artifacts which are useful to attach to test results, such as additional log files or screenshots, they can put them into the directory specified by the $ADT_ARTIFACTS environment variable. When using the --output-dir option, they will be copied into outputdir/artifacts/.

Tests must declare all applicable Restrictions - see below.

Control fields

The fields which may appear in debian/tests/control stanzas are:

Any unknown fields will cause the whole stanza to be skipped.

Defined restrictions

Defined features

There are no currently defined Features.

Source package header

To allow test execution environments to discover packages which provide tests, their source packages should have a Testsuite: header containing autopkgtest (which is currently the only defined value). Multiple values get comma separated, as usual in control files.

This tag is added automatically by dpkg-source version 1.17.11 or later. For earlier Debian/Ubuntu releases you need to set it manually in debian/control by adding

XS-Testsuite: autopkgtest

in the Source: stanza.

Implicit test control file for known package types

There are groups of similarly-structured packages for which the contents of debian/tests/control would be mostly identical. For those packages, if debian/tests/control is absent, an implicit control file is assumed. Those packages do not have to provide anything else, although they should still include an appropriate source package header (XS-Testsuite) so that they can be discovered in the archive.

Ruby packages

The source package must contain at least one of the following files:

Implied control file: :

Test-Command: gem2deb-test-runner --autopkgtest 2>&1
Depends: @, @builddeps@, gem2deb-test-runner

Note: gem2deb will be filtered out of the Depends: field, as it is not needed to run the tests for installed packages.

Packages should declare Testsuite: autopkgtest-pkg-ruby in debian/control.

Perl packages

The source package must contain a t/ directory and at least one of the following files:

Implied control file: :

Test-Command: /usr/share/pkg-perl-autopkgtest/runner build-deps
Depends: @, @builddeps@, pkg-perl-autopkgtest

Test-Command: /usr/share/pkg-perl-autopkgtest/runner runtime-deps
Depends: @, pkg-perl-autopkgtest

Packages should declare Testsuite: autopkgtest-pkg-perl in debian/control.

Reboot during a test

Some testbeds support rebooting; for those, the testbed will have an autopkgtest-reboot command which tests can call to cause a reboot. Do not use reboot and similar commands directly! They will cause testbeds like null or schroot to reboot the entire host, and even for qemu it will just cause the test to fail as there is no state keeping to resume a test at the right position after reboot.

The particular steps for a rebooting tests are:

This example test will reboot the testbed two times in between:

#!/bin/sh -e
case "$ADT_REBOOT_MARK" in
  "") echo "test beginning"; autopkgtest-reboot mark1 ;;
  mark1) echo "test in mark1"; autopkgtest-reboot mark2 ;;
  mark2) echo "test in mark2" ;;
esac
echo "test end"

Debian Policy 4.6.2.0, 2022-12-17