summaryrefslogtreecommitdiffstats
path: root/documentation/test-manual/ptest.rst
diff options
context:
space:
mode:
Diffstat (limited to 'documentation/test-manual/ptest.rst')
-rw-r--r--documentation/test-manual/ptest.rst135
1 files changed, 135 insertions, 0 deletions
diff --git a/documentation/test-manual/ptest.rst b/documentation/test-manual/ptest.rst
new file mode 100644
index 0000000000..4e6be35df5
--- /dev/null
+++ b/documentation/test-manual/ptest.rst
@@ -0,0 +1,135 @@
1.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2
3***************************
4Testing Packages With ptest
5***************************
6
7A Package Test (ptest) runs tests against packages built by the
8OpenEmbedded build system on the target machine. A ptest contains at
9least two items: the actual test, and a shell script (``run-ptest``)
10that starts the test. The shell script that starts the test must not
11contain the actual test --- the script only starts the test. On the other
12hand, the test can be anything from a simple shell script that runs a
13binary and checks the output to an elaborate system of test binaries and
14data files.
15
16The test generates output in the format used by Automake::
17
18 result: testname
19
20where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
21the testname can be any identifying string.
22
23For a list of Yocto Project recipes that are already enabled with ptest,
24see the :yocto_wiki:`Ptest </Ptest>` wiki page.
25
26.. note::
27
28 A recipe is "ptest-enabled" if it inherits the :ref:`ref-classes-ptest`
29 class.
30
31Adding ptest to Your Build
32==========================
33
34To add package testing to your build, add the :term:`DISTRO_FEATURES` and
35:term:`EXTRA_IMAGE_FEATURES` variables to your ``local.conf`` file, which
36is found in the :term:`Build Directory`::
37
38 DISTRO_FEATURES:append = " ptest"
39 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
40
41Once your build is complete, the ptest files are installed into the
42``/usr/lib/package/ptest`` directory within the image, where ``package``
43is the name of the package.
44
45Running ptest
46=============
47
48The ``ptest-runner`` package installs a shell script that loops through
49all installed ptest test suites and runs them in sequence.
50
51During the execution ``ptest-runner`` keeps count of total and failed
52``ptests``. At end the execution summary is written to the console.
53If any of the ``run-ptest`` fails, ``ptest-runner`` returns '1'.
54
55Consequently, you might want to add ``ptest-runner`` to your image.
56
57
58Getting Your Package Ready
59==========================
60
61In order to enable a recipe to run installed ``ptests`` on target hardware,
62you need to prepare the recipes that build the packages you want to
63test. Here is what you have to do for each recipe:
64
65- *Be sure the recipe inherits the* :ref:`ref-classes-ptest` *class:*
66 Include the following line in each recipe::
67
68 inherit ptest
69
70 .. note::
71
72 Classes for common frameworks already exist in :term:`OpenEmbedded-Core
73 (OE-Core)`, such as:
74
75 - :oe_git:`go-ptest </openembedded-core/tree/meta/classes-recipe/go-ptest.bbclass>`
76 - :ref:`ref-classes-ptest-cargo`
77 - :ref:`ref-classes-ptest-gnome`
78 - :oe_git:`ptest-perl </openembedded-core/tree/meta/classes-recipe/ptest-perl.bbclass>`
79 - :oe_git:`ptest-python-pytest </openembedded-core/tree/meta/classes-recipe/ptest-python-pytest.bbclass>`
80
81 Inheriting these classes with the ``inherit`` keyword in your recipe will
82 make the next steps automatic.
83
84- *Create run-ptest:* This script starts your test. Locate the
85 script where you will refer to it using
86 :term:`SRC_URI`. Be sure ``run-ptest`` exits with 0 to mark it
87 as successfully executed otherwise will be marked as fail.
88 Here is an example that starts a test for ``dbus``::
89
90 #!/bin/sh
91 cd test
92 make -k runtest-TESTS
93
94- *Ensure dependencies are met:* If the test adds build or runtime
95 dependencies that normally do not exist for the package (such as
96 requiring "make" to run the test suite), use the
97 :term:`DEPENDS` and
98 :term:`RDEPENDS` variables in
99 your recipe in order for the package to meet the dependencies. Here
100 is an example where the package has a runtime dependency on "make"::
101
102 RDEPENDS:${PN}-ptest += "make"
103
104- *Add a function to build the test suite:* Not many packages support
105 cross-compilation of their test suites. Consequently, you usually
106 need to add a cross-compilation function to the package.
107
108 Many packages based on Automake compile and run the test suite by
109 using a single command such as ``make check``. However, the host
110 ``make check`` builds and runs on the same computer, while
111 cross-compiling requires that the package is built on the host but
112 executed for the target architecture (though often, as in the case
113 for ptest, the execution occurs on the host). The built version of
114 Automake that ships with the Yocto Project includes a patch that
115 separates building and execution. Consequently, packages that use the
116 unaltered, patched version of ``make check`` automatically
117 cross-compiles.
118
119 Regardless, you still must add a ``do_compile_ptest`` function to
120 build the test suite. Add a function similar to the following to your
121 recipe::
122
123 do_compile_ptest() {
124 oe_runmake buildtest-TESTS
125 }
126
127- *Ensure special configurations are set:* If the package requires
128 special configurations prior to compiling the test code, you must
129 insert a ``do_configure_ptest`` function into the recipe.
130
131- *Install the test suite:* The :ref:`ref-classes-ptest` class
132 automatically copies the file ``run-ptest`` to the target and then runs make
133 ``install-ptest`` to run the tests. If this is not enough, you need
134 to create a ``do_install_ptest`` function and make sure it gets
135 called after the "make install-ptest" completes.