ptest.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ***************************
  3. Testing Packages With ptest
  4. ***************************
  5. A Package Test (ptest) runs tests against packages built by the
  6. OpenEmbedded build system on the target machine. A ptest contains at
  7. least two items: the actual test, and a shell script (``run-ptest``)
  8. that starts the test. The shell script that starts the test must not
  9. contain the actual test --- the script only starts the test. On the other
  10. hand, the test can be anything from a simple shell script that runs a
  11. binary and checks the output to an elaborate system of test binaries and
  12. data files.
  13. The test generates output in the format used by Automake::
  14. result: testname
  15. where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
  16. the testname can be any identifying string.
  17. For a list of Yocto Project recipes that are already enabled with ptest,
  18. see the :yocto_wiki:`Ptest </Ptest>` wiki page.
  19. .. note::
  20. A recipe is "ptest-enabled" if it inherits the :ref:`ref-classes-ptest`
  21. class.
  22. Adding ptest to Your Build
  23. ==========================
  24. To add package testing to your build, add the :term:`DISTRO_FEATURES` and
  25. :term:`EXTRA_IMAGE_FEATURES` variables to your ``local.conf`` file, which
  26. is found in the :term:`Build Directory`::
  27. DISTRO_FEATURES:append = " ptest"
  28. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  29. Once your build is complete, the ptest files are installed into the
  30. ``/usr/lib/package/ptest`` directory within the image, where ``package``
  31. is the name of the package.
  32. Running ptest
  33. =============
  34. The ``ptest-runner`` package installs a shell script that loops through
  35. all installed ptest test suites and runs them in sequence. Consequently,
  36. you might want to add this package to your image.
  37. Getting Your Package Ready
  38. ==========================
  39. In order to enable a recipe to run installed ptests on target hardware,
  40. you need to prepare the recipes that build the packages you want to
  41. test. Here is what you have to do for each recipe:
  42. - *Be sure the recipe inherits the* :ref:`ref-classes-ptest` *class:*
  43. Include the following line in each recipe::
  44. inherit ptest
  45. - *Create run-ptest:* This script starts your test. Locate the
  46. script where you will refer to it using
  47. :term:`SRC_URI`. Here is an
  48. example that starts a test for ``dbus``::
  49. #!/bin/sh
  50. cd test
  51. make -k runtest-TESTS
  52. - *Ensure dependencies are met:* If the test adds build or runtime
  53. dependencies that normally do not exist for the package (such as
  54. requiring "make" to run the test suite), use the
  55. :term:`DEPENDS` and
  56. :term:`RDEPENDS` variables in
  57. your recipe in order for the package to meet the dependencies. Here
  58. is an example where the package has a runtime dependency on "make"::
  59. RDEPENDS:${PN}-ptest += "make"
  60. - *Add a function to build the test suite:* Not many packages support
  61. cross-compilation of their test suites. Consequently, you usually
  62. need to add a cross-compilation function to the package.
  63. Many packages based on Automake compile and run the test suite by
  64. using a single command such as ``make check``. However, the host
  65. ``make check`` builds and runs on the same computer, while
  66. cross-compiling requires that the package is built on the host but
  67. executed for the target architecture (though often, as in the case
  68. for ptest, the execution occurs on the host). The built version of
  69. Automake that ships with the Yocto Project includes a patch that
  70. separates building and execution. Consequently, packages that use the
  71. unaltered, patched version of ``make check`` automatically
  72. cross-compiles.
  73. Regardless, you still must add a ``do_compile_ptest`` function to
  74. build the test suite. Add a function similar to the following to your
  75. recipe::
  76. do_compile_ptest() {
  77. oe_runmake buildtest-TESTS
  78. }
  79. - *Ensure special configurations are set:* If the package requires
  80. special configurations prior to compiling the test code, you must
  81. insert a ``do_configure_ptest`` function into the recipe.
  82. - *Install the test suite:* The :ref:`ref-classes-ptest` class
  83. automatically copies the file ``run-ptest`` to the target and then runs make
  84. ``install-ptest`` to run the tests. If this is not enough, you need
  85. to create a ``do_install_ptest`` function and make sure it gets
  86. called after the "make install-ptest" completes.