.. SPDX-License-Identifier: Apache-2.0 Copyright (C) 2020-2022 OKTET Labs Ltd. All rights reserved. te-parent: te te-order: 20 .. index:: pair: group; Test Suite .. _doxid-group__te__ts: Test Suite ========== .. include:: _toctree/te_ts.inc .. _doxid-group__te__ts_1te_ts_terminology: Terminology ~~~~~~~~~~~ ============ ================================================================================================================================================================================ Term Definition ============ ================================================================================================================================================================================ Test Package Group of tightly related tests or test packages, which may share internal libraries and usually run together (one-by-one or simultaneously). Test Package may consist of one test. It may have a prologue (performing some initialization) and epilogue (releasing resources and restoring TE configuration). Test Script A test which is a minimal structural unit of a test harness. Test Suite Test Package which may be considered as standalone entity from organisational point of view and build issues. ============ ================================================================================================================================================================================ .. _doxid-group__te__ts_1te_ts_tree_structure: Directory tree structure ~~~~~~~~~~~~~~~~~~~~~~~~ Test suite can be distributed in two forms: #. pre-installed binary form; #. source based form. For pre-installed binary test suite does not require building procedure, which is why there is no need to have build related files. Pre-installed binary test suite has the following directory structure: .. code-block:: none ${TS_ROOT} +-- package.xml +-- prologue +-- epilogue +-- p1_test1 + ... +-- p1_testN +-- subpackage +-- package.xml +-- prologue +-- epilogue +-- p2_test1 + ... +-- p2_testN A test suite consists of a set of packages each containing a number of test executables and package description file. For the details on the format of package.xml files refer to :ref:`Tester Package Description File ` section. A source based test suite additionally has build files. Like every other component of TE it is built through :ref:`Builder `, which uses meson, so each directory that contains tests needs a ``meson.build`` next to its ``package.xml``: .. code-block:: none ${TS_ROOT} +-- package.xml +-- meson.build +-- prologue.c +-- epilogue.c +-- p1_test1.c + ... +-- p1_testN.c +-- subpackage +-- package.xml +-- meson.build +-- prologue.c +-- epilogue.c +-- p2_test1.c + ... +-- p2_testN.c There is nothing to run by hand before the build: :ref:`Builder ` invokes meson itself when :ref:`Tester ` asks for the suite. .. note:: Some old suites in the tree still carry ``configure.ac`` and ``Makefile.am`` from the days when Builder used autotools. Do not copy them for new work. .. _doxid-group__te__ts_1te_ts_min: Minimal Test Suite ~~~~~~~~~~~~~~~~~~ The smallest complete example lives in TE's own self-test suite, under ``${TE_BASE}/suites/selftest``. It is built and run on every change to TE, so unlike a written-down example it cannot quietly stop working. Its layout is the one described above: .. code-block:: none ${TE_BASE}/suites/selftest +-- run.sh - entry point, wraps dispatcher.sh +-- conf | +-- builder.conf | +-- cs.conf | +-- logger.conf | +-- rcf.conf | +-- tester.conf +-- ts +-- meson.build - suite level build file +-- package.xml - root package +-- prologue.c +-- minimal - the package we look at below +-- meson.build +-- package.xml +-- helloworld.c +-- ... :ref:`Tester ` needs to be told where the suite sources are. That is what ``conf/tester.conf`` does: .. code-block:: xml TE Self Tests The ``src`` attribute points at the suite sources and the ``run`` section says which package to execute. Everything below that point is described by ``package.xml`` files. To run it: .. code-block:: none cd ${TE_BASE}/suites/selftest ./run.sh --cfg=localhost ``run.sh`` is a thin wrapper around ``dispatcher.sh`` that fills in the suite-specific options; ``--cfg=`` selects one of the configurations under ``conf/run``. See :ref:`TE Execution ` for what happens next and where the logs end up. The build artefacts appear under the build directory: .. code-block:: none build +-- engine - :ref:`Test Engine ` build directory +-- agents - :ref:`Test Agents ` build directory +-- lib - build directory for TE libraries +-- include - build directory for includes +-- platforms - platforms build +-- suites - test suites build directory +-- inst - installation directory +-- agents +-- default +-- suites +-- ts +-- package.xml - installed package description file +-- minimal +-- helloworld - test executable Please note that :ref:`Tester ` runs a test suite from the inst/suites/ directory. .. _doxid-group__te__ts_1te_ts_min_builder: Build files ----------- A package ``meson.build`` lists the tests in the directory and builds one executable per test. This is the whole of ``ts/minimal/meson.build``, with the list of tests cut down: .. code-block:: none tests = [ 'helloworld', 'verdict', ] foreach test : tests test_exe = test test_c = test + '.c' package_tests_c += [ test_c ] executable(test_exe, test_c, install: true, install_dir: package_dir, dependencies: test_deps) endforeach install_data([ 'package.xml' ], install_dir: package_dir) ``package_dir``, ``package_tests_c`` and ``test_deps`` come from the suite level ``ts/meson.build``, which is where the TE libraries the tests link against are declared: .. code-block:: none project('selftest', 'c', version : '1.0.0', meson_version: '>= 0.49.0', ) te_path = get_option('te_path') te_libdir = get_option('te_libdir') add_project_arguments(get_option('te_cflags').split(), language: 'c') add_project_link_arguments(get_option('te_ldflags').split(), language: 'c') test_deps = [ dependency('threads') ] te_libs = [ 'rcfapi', 'confapi', 'tapi', 'tapi_rpc', 'tapi_env', 'tools', 'logger_core', 'logger_ten', ] foreach lib : te_libs test_deps += dependency('te-' + lib) endforeach package_dir = 'ts' package_tests_c = [ ] packages = [ 'minimal' ] mydir = package_dir foreach package : packages package_dir = join_paths(mydir, package) package_tests_c = [] subdir(package) endforeach The ``te_path``, ``te_libdir``, ``te_cflags`` and ``te_ldflags`` options are passed in by :ref:`Builder `; a suite does not set them itself. Each TE library is picked up as ``dependency('te-')``, and the same library must also be listed in the suite's ``builder.conf`` so that it gets built in the first place --- see :ref:`Builder configuration file `. Adding a test to an existing package therefore means three things: write the ``.c`` file, add its name to ``tests`` in ``meson.build``, and add a ``run`` entry for it in ``package.xml``. .. _doxid-group__te__ts_1te_ts_min_test_file: Test scenario file ------------------ A test scenario is a plain C program. This is ``ts/minimal/helloworld.c`` in full --- it is as small as a TE test gets: .. code-block:: c /* SPDX-License-Identifier: Apache-2.0 */ /** @file * @brief Minimal test * * Minimal test scenario. * * Copyright (C) 2019-2022 OKTET Labs Ltd. All rights reserved. */ /** @page minimal_helloworld Hello World test * * @objective Demo of minimal Hello World test * * For each test @p TEST_STEP() is required. This is needed to generate * documentation of test steps. * * @par Test sequence: * */ #ifndef DOXYGEN_TEST_SPEC /** Logging subsystem entity name */ #define TE_TEST_NAME "helloworld" #include "te_config.h" #include "tapi_test.h" int main(int argc, char **argv) { TEST_START; TEST_STEP("Print \"Hello, World!\""); RING("Hello, World!"); TEST_SUCCESS; cleanup: TEST_END; } #endif /* !DOXYGEN_TEST_SPEC */ and the ``package.xml`` entry that makes :ref:`Tester ` run it: .. code-block:: xml Package for demonstrating minimal tests