Ptest: Difference between revisions
No edit summary |
|||
Line 5: | Line 5: | ||
=Adding ptest to your build= | =Adding ptest to your build= | ||
Ptest is enabled in | Ptest is enabled in two parts: | ||
# Adding "ptest" to your DISTRO_FEATURES variable causes -ptest packages to be built. | |||
# Adding "ptest-pkgs" to IMAGE_FEATURES variable causes -ptest packages to be installed in your image. | |||
All ptest files are installed in /usr/lib/<package>/ptest. | |||
=Running ptest= | =Running ptest= | ||
The "ptest-runner" package installs a "ptest-runner" shell script which loops through all installed ptest test suites and runs them in sequence. | The "ptest-runner" package installs a "ptest-runner" shell script which loops through all installed ptest test suites and runs them in sequence. You may therefore want to add "ptest-runner" to your image. | ||
= | =Implementing ptest in a package recipe= | ||
==What constitutes a ptest?== | ==What constitutes a ptest?== | ||
Line 39: | Line 44: | ||
Few packages support cross-compiling their test suites, so this is something we typically have to add. | Few packages support cross-compiling their test suites, so this is something we typically have to add. | ||
Many automake-based packages compile and run the test suite in a single command: "make check". This doesn't work when cross-compiling, since we need to build on host and run on target. So we need to split that into two targets: One for building the test and one for running it. Our build of automake comes with a patch which does this automatically, so packages using the plain "make check" arrangement from automake get this automatically. | Many automake-based packages compile and run the test suite in a single command: "make check". This doesn't work when cross-compiling, since we need to build on host and run on target. So we need to split that into two targets: One for building the test and one for running it. Our build of automake comes with a [http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/recipes-devtools/automake/automake/buildtest.patch patch] which does this automatically, so packages using the plain "make check" arrangement from automake get this automatically. | ||
Now add a do_compile_ptest function to build the test suite: | Now add a do_compile_ptest function to build the test suite: | ||
Line 51: | Line 56: | ||
==Installing the test suite== | ==Installing the test suite== | ||
The ptest.bbclass will automatically copy the required "run-ptest" file and run "make install-ptest" if there is such a target in the top-level Makefile. For packages where this is enough, you don't need to | The ptest.bbclass will automatically copy the required "run-ptest" file and run "make install-ptest" if there is such a target in the top-level Makefile. For packages where this is enough, you don't need to do anything else. | ||
If you need to do | If you need to do something more than the automatic "make install-ptest", create a do_install_ptest function and put the required actions there. This function will be called after "make install-ptest" has completed. |
Revision as of 13:10, 11 April 2013
Introduction
Ptest (package test) is a concept for building, installing and running the test suites that are included in many packages, and producing a consistent output format.
Adding ptest to your build
Ptest is enabled in two parts:
- Adding "ptest" to your DISTRO_FEATURES variable causes -ptest packages to be built.
- Adding "ptest-pkgs" to IMAGE_FEATURES variable causes -ptest packages to be installed in your image.
All ptest files are installed in /usr/lib/<package>/ptest.
Running ptest
The "ptest-runner" package installs a "ptest-runner" shell script which loops through all installed ptest test suites and runs them in sequence. You may therefore want to add "ptest-runner" to your image.
Implementing ptest in a package recipe
What constitutes a ptest?
A ptest must at minimum contain two things: run-ptest and the actual test.
run-ptest is a minimal shell script that starts the test suite. Note: It must not contain the test suite, only start it!
The test can be anything, from a simple shell script running a binary and checking its output to an elaborate system of test binaries and data files.
One major point of ptest is to consolidate the output format of all tests into a single common format. The format selected is the automake "simple test" format:
result: testname
Where "result" is one of PASS, FAIL or SKIP and "testname" can be any identifying string. (The same format used by Automake.)
General recipe preparations
First, add "ptest" to the "inherit" line in the package recipe.
If a test adds build-time or run-time dependencies to the package which are not there normally (such as requiring "make" to run the test suite), add those with a -ptest suffix, like this:
RDEPENDS_${PN}-ptest += "make"
Building the test suite
Few packages support cross-compiling their test suites, so this is something we typically have to add.
Many automake-based packages compile and run the test suite in a single command: "make check". This doesn't work when cross-compiling, since we need to build on host and run on target. So we need to split that into two targets: One for building the test and one for running it. Our build of automake comes with a patch which does this automatically, so packages using the plain "make check" arrangement from automake get this automatically.
Now add a do_compile_ptest function to build the test suite:
do_compile_ptest() { oe_runmake buildtest-TESTS }
If the package requires special configuration actions prior to compiling the test code, create a do_configure_ptest function to do that.
Installing the test suite
The ptest.bbclass will automatically copy the required "run-ptest" file and run "make install-ptest" if there is such a target in the top-level Makefile. For packages where this is enough, you don't need to do anything else.
If you need to do something more than the automatic "make install-ptest", create a do_install_ptest function and put the required actions there. This function will be called after "make install-ptest" has completed.