1bb5f2990SJuraj Linkeš.. SPDX-License-Identifier: BSD-3-Clause 2680d8a24SJuraj Linkeš Copyright(c) 2022-2023 PANTHEON.tech s.r.o. 3*3fbb93cfSLuca Vizzarro Copyright(c) 2024 Arm Limited 4bb5f2990SJuraj Linkeš 5bb5f2990SJuraj LinkešDPDK Test Suite 6bb5f2990SJuraj Linkeš=============== 7bb5f2990SJuraj Linkeš 8bb5f2990SJuraj LinkešThe DPDK Test Suite, abbreviated DTS, is a Python test framework with test suites 9bb5f2990SJuraj Linkešimplementing functional and performance tests used to test DPDK. 10bb5f2990SJuraj Linkeš 11bb5f2990SJuraj Linkeš 12724b8a37SJuraj LinkešDTS Terminology 13724b8a37SJuraj Linkeš--------------- 14724b8a37SJuraj Linkeš 15724b8a37SJuraj LinkešDTS node 16724b8a37SJuraj Linkeš A generic description of any host/server DTS connects to. 17724b8a37SJuraj Linkeš 18724b8a37SJuraj LinkešDTS runtime environment 19724b8a37SJuraj Linkeš An environment containing Python with packages needed to run DTS. 20724b8a37SJuraj Linkeš 21724b8a37SJuraj LinkešDTS runtime environment node 22724b8a37SJuraj Linkeš A node where at least one DTS runtime environment is present. 23724b8a37SJuraj Linkeš This is the node where we run DTS and from which DTS connects to other nodes. 24724b8a37SJuraj Linkeš 25724b8a37SJuraj LinkešSystem under test 26724b8a37SJuraj Linkeš An SUT is the combination of DPDK and the hardware we're testing 27724b8a37SJuraj Linkeš in conjunction with DPDK (NICs, crypto and other devices). 28724b8a37SJuraj Linkeš 29724b8a37SJuraj LinkešSystem under test node 30724b8a37SJuraj Linkeš A node where at least one SUT is present. 31724b8a37SJuraj Linkeš 32724b8a37SJuraj LinkešTraffic generator 33724b8a37SJuraj Linkeš A TG is either software or hardware capable of sending packets. 34724b8a37SJuraj Linkeš 35724b8a37SJuraj LinkešTraffic generator node 36724b8a37SJuraj Linkeš A node where at least one TG is present. 37724b8a37SJuraj Linkeš In case of hardware traffic generators, the TG and the node are literally the same. 38724b8a37SJuraj Linkeš 39724b8a37SJuraj Linkeš 40724b8a37SJuraj LinkešIn most cases, interchangeably referring to a runtime environment, SUT, TG or the node 41724b8a37SJuraj Linkešthey're running on (e.g. using SUT and SUT node interchangeably) doesn't cause confusion. 42724b8a37SJuraj LinkešThere could theoretically be more than of these running on the same node and in that case 43724b8a37SJuraj Linkešit's useful to have stricter definitions. 44724b8a37SJuraj LinkešAn example would be two different traffic generators (such as Trex and Scapy) 45724b8a37SJuraj Linkešrunning on the same node. 46724b8a37SJuraj LinkešA different example would be a node containing both a DTS runtime environment 47724b8a37SJuraj Linkešand a traffic generator, in which case it's both a DTS runtime environment node and a TG node. 48724b8a37SJuraj Linkeš 49724b8a37SJuraj Linkeš 50bb5f2990SJuraj LinkešDTS Environment 51bb5f2990SJuraj Linkeš--------------- 52bb5f2990SJuraj Linkeš 53bb5f2990SJuraj LinkešDTS is written entirely in Python using a variety of dependencies. 54bb5f2990SJuraj LinkešDTS uses Poetry as its Python dependency management. 55bb5f2990SJuraj LinkešPython build/development and runtime environments are the same and DTS development environment, 56bb5f2990SJuraj LinkešDTS runtime environment or just plain DTS environment are used interchangeably. 57bb5f2990SJuraj Linkeš 587f932642SJuraj Linkeš.. _dts_deps: 59bb5f2990SJuraj Linkeš 60bb5f2990SJuraj LinkešSetting up DTS environment 61680d8a24SJuraj Linkeš~~~~~~~~~~~~~~~~~~~~~~~~~~ 62bb5f2990SJuraj Linkeš 63bb5f2990SJuraj Linkeš#. **Python Version** 64bb5f2990SJuraj Linkeš 65bb5f2990SJuraj Linkeš The Python Version required by DTS is specified in ``dts/pyproject.toml`` in the 66bb5f2990SJuraj Linkeš **[tool.poetry.dependencies]** section: 67bb5f2990SJuraj Linkeš 68bb5f2990SJuraj Linkeš .. literalinclude:: ../../../dts/pyproject.toml 69bb5f2990SJuraj Linkeš :language: cfg 70bb5f2990SJuraj Linkeš :start-at: [tool.poetry.dependencies] 71bb5f2990SJuraj Linkeš :end-at: python 72bb5f2990SJuraj Linkeš 73bb5f2990SJuraj Linkeš The Python dependency manager DTS uses, Poetry, doesn't install Python, so you may need 74bb5f2990SJuraj Linkeš to satisfy this requirement by other means if your Python is not up-to-date. 75bb5f2990SJuraj Linkeš A tool such as `Pyenv <https://github.com/pyenv/pyenv>`_ is a good way to get Python, 76bb5f2990SJuraj Linkeš though not the only one. 77bb5f2990SJuraj Linkeš 78bb5f2990SJuraj Linkeš#. **Poetry** 79bb5f2990SJuraj Linkeš 80bb5f2990SJuraj Linkeš The typical style of python dependency management, pip with ``requirements.txt``, 81bb5f2990SJuraj Linkeš has a few issues. 82bb5f2990SJuraj Linkeš The advantages of Poetry include specifying what Python version is required and forcing you 83bb5f2990SJuraj Linkeš to specify versions, enforced by a lockfile, both of which help prevent broken dependencies. 84bb5f2990SJuraj Linkeš Another benefit is the usage of ``pyproject.toml``, which has become the standard config file 85bb5f2990SJuraj Linkeš for python projects, improving project organization. 86bb5f2990SJuraj Linkeš To install Poetry, visit their `doc pages <https://python-poetry.org/docs/>`_. 87282688eaSLuca Vizzarro The recommended Poetry version is at least 1.8.2. 88bb5f2990SJuraj Linkeš 89bb5f2990SJuraj Linkeš#. **Getting a Poetry shell** 90bb5f2990SJuraj Linkeš 91bb5f2990SJuraj Linkeš Once you have Poetry along with the proper Python version all set up, it's just a matter 92bb5f2990SJuraj Linkeš of installing dependencies via Poetry and using the virtual environment Poetry provides: 93bb5f2990SJuraj Linkeš 94bb5f2990SJuraj Linkeš .. code-block:: console 95bb5f2990SJuraj Linkeš 9672a44b26SDean Marx poetry install 97bb5f2990SJuraj Linkeš poetry shell 98724b8a37SJuraj Linkeš 99680d8a24SJuraj Linkeš#. **SSH Connection** 100680d8a24SJuraj Linkeš 101b8bdc4c5SJuraj Linkeš DTS uses the Fabric Python library for SSH connections between DTS environment 102b8bdc4c5SJuraj Linkeš and the other hosts. 103b8bdc4c5SJuraj Linkeš The authentication method used is pubkey authentication. 104b8bdc4c5SJuraj Linkeš Fabric tries to use a passed key/certificate, 105b8bdc4c5SJuraj Linkeš then any key it can with through an SSH agent, 106b8bdc4c5SJuraj Linkeš then any "id_rsa", "id_dsa" or "id_ecdsa" key discoverable in ``~/.ssh/`` 107b8bdc4c5SJuraj Linkeš (with any matching OpenSSH-style certificates). 108b8bdc4c5SJuraj Linkeš DTS doesn't pass any keys, so Fabric tries to use the other two methods. 109680d8a24SJuraj Linkeš 110680d8a24SJuraj Linkeš 111680d8a24SJuraj LinkešSetting up System Under Test 112680d8a24SJuraj Linkeš---------------------------- 113680d8a24SJuraj Linkeš 114680d8a24SJuraj LinkešThere are two areas that need to be set up on a System Under Test: 115680d8a24SJuraj Linkeš 116680d8a24SJuraj Linkeš#. **DPDK dependencies** 117680d8a24SJuraj Linkeš 118680d8a24SJuraj Linkeš DPDK will be built and run on the SUT. 119680d8a24SJuraj Linkeš Consult the Getting Started guides for the list of dependencies for each distribution. 120680d8a24SJuraj Linkeš 121c020b7ceSJuraj Linkeš#. **Hardware dependencies** 122c020b7ceSJuraj Linkeš 123c020b7ceSJuraj Linkeš Any hardware DPDK uses needs a proper driver 124c020b7ceSJuraj Linkeš and most OS distributions provide those, but the version may not be satisfactory. 125c020b7ceSJuraj Linkeš It's up to each user to install the driver they're interested in testing. 126c020b7ceSJuraj Linkeš The hardware also may also need firmware upgrades, which is also left at user discretion. 127c020b7ceSJuraj Linkeš 128b76d80a4SJuraj Linkeš#. **Hugepages** 129b76d80a4SJuraj Linkeš 130b76d80a4SJuraj Linkeš There are two ways to configure hugepages: 131b76d80a4SJuraj Linkeš 132b76d80a4SJuraj Linkeš * DTS configuration 133b76d80a4SJuraj Linkeš 134b76d80a4SJuraj Linkeš You may specify the optional hugepage configuration in the DTS config file. 135b76d80a4SJuraj Linkeš If you do, DTS will take care of configuring hugepages, 136b76d80a4SJuraj Linkeš overwriting your current SUT hugepage configuration. 137e5307b25SNicholas Pratte Configuration of hugepages via DTS allows only for allocation of 2MB hugepages, 138e5307b25SNicholas Pratte as doing so prevents accidental/over allocation of hugepage sizes 139e5307b25SNicholas Pratte not recommended during runtime due to contiguous memory space requirements. 140e5307b25SNicholas Pratte Thus, if you require hugepage sizes not equal to 2MB, 141e5307b25SNicholas Pratte then this configuration must be done outside of the DTS framework. 142b76d80a4SJuraj Linkeš 143b76d80a4SJuraj Linkeš * System under test configuration 144b76d80a4SJuraj Linkeš 145b76d80a4SJuraj Linkeš It's possible to use the hugepage configuration already present on the SUT. 146b76d80a4SJuraj Linkeš If you wish to do so, don't specify the hugepage configuration in the DTS config file. 147b76d80a4SJuraj Linkeš 148b8bdc4c5SJuraj Linkeš#. **User with administrator privileges** 149b8bdc4c5SJuraj Linkeš 150b8bdc4c5SJuraj Linkeš.. _sut_admin_user: 151b8bdc4c5SJuraj Linkeš 152b8bdc4c5SJuraj Linkeš DTS needs administrator privileges to run DPDK applications (such as testpmd) on the SUT. 153b8bdc4c5SJuraj Linkeš The SUT user must be able run commands in privileged mode without asking for password. 154b8bdc4c5SJuraj Linkeš On most Linux distributions, it's a matter of setting up passwordless sudo: 155b8bdc4c5SJuraj Linkeš 156b8bdc4c5SJuraj Linkeš #. Run ``sudo visudo`` and check that it contains ``%sudo ALL=(ALL:ALL) NOPASSWD:ALL``. 157b8bdc4c5SJuraj Linkeš 158b8bdc4c5SJuraj Linkeš #. Add the SUT user to the sudo group with: 159b8bdc4c5SJuraj Linkeš 160b8bdc4c5SJuraj Linkeš .. code-block:: console 161b8bdc4c5SJuraj Linkeš 162b8bdc4c5SJuraj Linkeš sudo usermod -aG sudo <sut_user> 163724b8a37SJuraj Linkeš 164cecfe0aaSJuraj Linkeš 165cecfe0aaSJuraj LinkešSetting up Traffic Generator Node 166cecfe0aaSJuraj Linkeš--------------------------------- 167cecfe0aaSJuraj Linkeš 168cecfe0aaSJuraj LinkešThese need to be set up on a Traffic Generator Node: 169cecfe0aaSJuraj Linkeš 170cecfe0aaSJuraj Linkeš#. **Traffic generator dependencies** 171cecfe0aaSJuraj Linkeš 172cecfe0aaSJuraj Linkeš The traffic generator running on the traffic generator node must be installed beforehand. 173cecfe0aaSJuraj Linkeš For Scapy traffic generator, only a few Python libraries need to be installed: 174cecfe0aaSJuraj Linkeš 175cecfe0aaSJuraj Linkeš .. code-block:: console 176cecfe0aaSJuraj Linkeš 177cecfe0aaSJuraj Linkeš sudo apt install python3-pip 178cecfe0aaSJuraj Linkeš sudo pip install --upgrade pip 179cecfe0aaSJuraj Linkeš sudo pip install scapy==2.5.0 180cecfe0aaSJuraj Linkeš 181cecfe0aaSJuraj Linkeš#. **Hardware dependencies** 182cecfe0aaSJuraj Linkeš 183cecfe0aaSJuraj Linkeš The traffic generators, like DPDK, need a proper driver and firmware. 184cecfe0aaSJuraj Linkeš The Scapy traffic generator doesn't have strict requirements - the drivers that come 185cecfe0aaSJuraj Linkeš with most OS distributions will be satisfactory. 186cecfe0aaSJuraj Linkeš 187cecfe0aaSJuraj Linkeš 188cecfe0aaSJuraj Linkeš#. **User with administrator privileges** 189cecfe0aaSJuraj Linkeš 190cecfe0aaSJuraj Linkeš Similarly to the System Under Test, traffic generators need administrator privileges 191cecfe0aaSJuraj Linkeš to be able to use the devices. 192cecfe0aaSJuraj Linkeš Refer to the `System Under Test section <sut_admin_user>` for details. 193cecfe0aaSJuraj Linkeš 194cecfe0aaSJuraj Linkeš 1951512a0d1SJuraj LinkešRunning DTS 1961512a0d1SJuraj Linkeš----------- 1971512a0d1SJuraj Linkeš 1981512a0d1SJuraj LinkešDTS needs to know which nodes to connect to and what hardware to use on those nodes. 1990ae32140STomáš ĎurovecOnce that's configured, either a DPDK source code tarball or tree folder 2000ae32140STomáš Ďurovecneed to be supplied whether these are on your DTS host machine or the SUT node. 2010ae32140STomáš ĎurovecDTS can accept a pre-compiled build placed in a subdirectory, 2020ae32140STomáš Ďurovecor it will compile DPDK on the SUT node, 20355442c14SLuca Vizzarroand then run the tests with the newly built binaries. 20455442c14SLuca Vizzarro 2051512a0d1SJuraj Linkeš 2061512a0d1SJuraj LinkešConfiguring DTS 2071512a0d1SJuraj Linkeš~~~~~~~~~~~~~~~ 2081512a0d1SJuraj Linkeš 2096597fa4aSLuca VizzarroDTS configuration is split into nodes and test runs, 2106597fa4aSLuca Vizzarroand must respect the model definitions 2116597fa4aSLuca Vizzarroas documented in the DTS API docs under the ``config`` page. 2126597fa4aSLuca VizzarroThe root of the configuration is represented by the ``Configuration`` model. 2136597fa4aSLuca VizzarroBy default, DTS will try to use the ``dts/conf.yaml`` :ref:`config file <configuration_example>`, 214515e1a4fSLuca Vizzarrowhich is a template that illustrates what can be configured in DTS. 2151512a0d1SJuraj Linkeš 216b8bdc4c5SJuraj LinkešThe user must have :ref:`administrator privileges <sut_admin_user>` 217b8bdc4c5SJuraj Linkešwhich don't require password authentication. 2181512a0d1SJuraj Linkeš 21955442c14SLuca Vizzarro 2201512a0d1SJuraj LinkešDTS Execution 2211512a0d1SJuraj Linkeš~~~~~~~~~~~~~ 2221512a0d1SJuraj Linkeš 22355442c14SLuca VizzarroDTS is run with ``main.py`` located in the ``dts`` directory after entering Poetry shell: 2241512a0d1SJuraj Linkeš 22555442c14SLuca Vizzarro.. code-block:: console 2261512a0d1SJuraj Linkeš 22755442c14SLuca Vizzarro (dts-py3.10) $ ./main.py --help 2280ae32140STomáš Ďurovec usage: main.py [-h] [--config-file FILE_PATH] [--output-dir DIR_PATH] [-t SECONDS] [-v] [--dpdk-tree DIR_PATH | --tarball FILE_PATH] [--remote-source] 2290ae32140STomáš Ďurovec [--precompiled-build-dir DIR_NAME] [--compile-timeout SECONDS] [--test-suite TEST_SUITE [TEST_CASES ...]] [--re-run N_TIMES] 2300ae32140STomáš Ďurovec [--random-seed NUMBER] 23155442c14SLuca Vizzarro 2320ae32140STomáš Ďurovec Run DPDK test suites. All options may be specified with the environment variables provided in brackets. Command line arguments have higher priority. 2331512a0d1SJuraj Linkeš 2341512a0d1SJuraj Linkeš options: 2351512a0d1SJuraj Linkeš -h, --help show this help message and exit 2367f86be25SLuca Vizzarro --config-file FILE_PATH 2370ae32140STomáš Ďurovec [DTS_CFG_FILE] The configuration file that describes the test cases, SUTs and DPDK build configs. (default: conf.yaml) 2387f86be25SLuca Vizzarro --output-dir DIR_PATH, --output DIR_PATH 23955442c14SLuca Vizzarro [DTS_OUTPUT_DIR] Output directory where DTS logs and results are saved. (default: output) 2407f86be25SLuca Vizzarro -t SECONDS, --timeout SECONDS 241a23f2245SLuca Vizzarro [DTS_TIMEOUT] The default timeout for all DTS operations except for compiling DPDK. (default: 15) 242a23f2245SLuca Vizzarro -v, --verbose [DTS_VERBOSE] Specify to enable verbose output, logging all messages to the console. (default: False) 2437f86be25SLuca Vizzarro --compile-timeout SECONDS 2441512a0d1SJuraj Linkeš [DTS_COMPILE_TIMEOUT] The timeout for compiling DPDK. (default: 1200) 2454a4678c7SJuraj Linkeš --test-suite TEST_SUITE [TEST_CASES ...] 2460ae32140STomáš Ďurovec [DTS_TEST_SUITES] A list containing a test suite with test cases. The first parameter is the test suite name, and the rest are 2470ae32140STomáš Ďurovec test case names, which are optional. May be specified multiple times. To specify multiple test suites in the environment 2480ae32140STomáš Ďurovec variable, join the lists with a comma. Examples: --test-suite suite case case --test-suite suite case ... | 2490ae32140STomáš Ďurovec DTS_TEST_SUITES='suite case case, suite case, ...' | --test-suite suite --test-suite suite case ... | DTS_TEST_SUITES='suite, 2500ae32140STomáš Ďurovec suite case, ...' (default: []) 2517f86be25SLuca Vizzarro --re-run N_TIMES, --re_run N_TIMES 252a23f2245SLuca Vizzarro [DTS_RERUN] Re-run each test case the specified number of times if a test failure occurs. (default: 0) 2530ae32140STomáš Ďurovec --random-seed NUMBER [DTS_RANDOM_SEED] The seed to use with the pseudo-random generator. If not specified, the configuration value is used instead. 254cfe40bacSLuca Vizzarro If that's also not specified, a random seed is generated. (default: None) 2551512a0d1SJuraj Linkeš 2560ae32140STomáš Ďurovec DPDK Build Options: 2570ae32140STomáš Ďurovec Arguments in this group (and subgroup) will be applied to a DPDKLocation when the DPDK tree, tarball or revision will be provided, other arguments 2580ae32140STomáš Ďurovec like remote source and build dir are optional. A DPDKLocation from settings are used instead of from config if construct successful. 2590ae32140STomáš Ďurovec 2600ae32140STomáš Ďurovec --dpdk-tree DIR_PATH [DTS_DPDK_TREE] The path to the DPDK source tree directory to test. Cannot be used in conjunction with --tarball. (default: 2610ae32140STomáš Ďurovec None) 2620ae32140STomáš Ďurovec --tarball FILE_PATH, --snapshot FILE_PATH 2630ae32140STomáš Ďurovec [DTS_DPDK_TARBALL] The path to the DPDK source tarball to test. DPDK must be contained in a folder with the same name as the 2640ae32140STomáš Ďurovec tarball file. Cannot be used in conjunction with --dpdk-tree. (default: None) 2650ae32140STomáš Ďurovec --remote-source [DTS_REMOTE_SOURCE] Set this option if either the DPDK source tree or tarball to be used are located on the SUT node. Can only 2660ae32140STomáš Ďurovec be used with --dpdk-tree or --tarball. (default: False) 2670ae32140STomáš Ďurovec --precompiled-build-dir DIR_NAME 2680ae32140STomáš Ďurovec [DTS_PRECOMPILED_BUILD_DIR] Define the subdirectory under the DPDK tree root directory where the pre-compiled binaries are 2690ae32140STomáš Ďurovec located. If set, DTS will build DPDK under the `build` directory instead. Can only be used with --dpdk-tree or --tarball. 2700ae32140STomáš Ďurovec (default: None) 2710ae32140STomáš Ďurovec 2721512a0d1SJuraj Linkeš 2731512a0d1SJuraj LinkešThe brackets contain the names of environment variables that set the same thing. 2740ae32140STomáš ĎurovecThe minimum DTS needs is a config file and a pre-built DPDK 2750ae32140STomáš Ďurovecor DPDK sources location which can be specified in said config file 2760ae32140STomáš Ďurovecor on the command line or environment variables. 2771512a0d1SJuraj Linkeš 2781512a0d1SJuraj Linkeš 2790c6f2d11SJuraj LinkešDTS Results 2800c6f2d11SJuraj Linkeš~~~~~~~~~~~ 2810c6f2d11SJuraj Linkeš 2820c6f2d11SJuraj LinkešResults are stored in the output dir by default 2830c6f2d11SJuraj Linkešwhich be changed with the ``--output-dir`` command line argument. 2840c6f2d11SJuraj LinkešThe results contain basic statistics of passed/failed test cases and DPDK version. 2850c6f2d11SJuraj Linkeš 2860c6f2d11SJuraj Linkeš 2877b2d709aSJuraj LinkešContributing to DTS 2887b2d709aSJuraj Linkeš------------------- 2897b2d709aSJuraj Linkeš 2907b2d709aSJuraj LinkešThere are two areas of contribution: The DTS framework and DTS test suites. 2917b2d709aSJuraj Linkeš 2927b2d709aSJuraj LinkešThe framework contains the logic needed to run test cases, such as connecting to nodes, 2937b2d709aSJuraj Linkešrunning DPDK applications and collecting results. 2947b2d709aSJuraj Linkeš 2957b2d709aSJuraj LinkešThe test cases call APIs from the framework to test their scenarios. 2967b2d709aSJuraj LinkešAdding test cases may require adding code to the framework as well. 2977b2d709aSJuraj Linkeš 2987b2d709aSJuraj Linkeš 2997b2d709aSJuraj LinkešFramework Coding Guidelines 3007b2d709aSJuraj Linkeš~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3017b2d709aSJuraj Linkeš 3027b2d709aSJuraj LinkešWhen adding code to the DTS framework, pay attention to the rest of the code 3037b2d709aSJuraj Linkešand try not to divert much from it. 3047b2d709aSJuraj LinkešThe :ref:`DTS developer tools <dts_dev_tools>` will issue warnings 3057b2d709aSJuraj Linkešwhen some of the basics are not met. 3067f932642SJuraj LinkešYou should also build the :ref:`API documentation <building_api_docs>` 3077f932642SJuraj Linkešto address any issues found during the build. 3087b2d709aSJuraj Linkeš 3097f932642SJuraj LinkešThe API documentation, which is a helpful reference when developing, may be accessed 3107f932642SJuraj Linkešin the code directly or generated with the :ref:`API docs build steps <building_api_docs>`. 3117f932642SJuraj LinkešWhen adding new files or modifying the directory structure, 3127f932642SJuraj Linkešthe corresponding changes must be made to DTS API doc sources in ``doc/api/dts``. 3137f932642SJuraj Linkeš 3147f932642SJuraj LinkešSpeaking of which, the code must be properly documented with docstrings. 3157b2d709aSJuraj LinkešThe style must conform to the `Google style 3167b2d709aSJuraj Linkeš<https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings>`_. 3177b2d709aSJuraj LinkešSee an example of the style `here 3187b2d709aSJuraj Linkeš<https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html>`_. 3197b2d709aSJuraj LinkešFor cases which are not covered by the Google style, refer to `PEP 257 3207b2d709aSJuraj Linkeš<https://peps.python.org/pep-0257/>`_. 3217b2d709aSJuraj LinkešThere are some cases which are not covered by the two style guides, 3227b2d709aSJuraj Linkešwhere we deviate or where some additional clarification is helpful: 3237b2d709aSJuraj Linkeš 3247b2d709aSJuraj Linkeš * The ``__init__()`` methods of classes are documented separately 3257b2d709aSJuraj Linkeš from the docstring of the class itself. 3267b2d709aSJuraj Linkeš * The docstrings of implemented abstract methods should refer to the superclass's definition 3277b2d709aSJuraj Linkeš if there's no deviation. 3287b2d709aSJuraj Linkeš * Instance variables/attributes should be documented in the docstring of the class 3297b2d709aSJuraj Linkeš in the ``Attributes:`` section. 3307b2d709aSJuraj Linkeš * The ``dataclass.dataclass`` decorator changes how the attributes are processed. 3317b2d709aSJuraj Linkeš The dataclass attributes which result in instance variables/attributes 3327b2d709aSJuraj Linkeš should also be recorded in the ``Attributes:`` section. 333*3fbb93cfSLuca Vizzarro * Class variables/attributes and Pydantic model fields, on the other hand, 334*3fbb93cfSLuca Vizzarro should be documented with ``#:`` above the type annotated line. 3357b2d709aSJuraj Linkeš The description may be omitted if the meaning is obvious. 3367b2d709aSJuraj Linkeš * The ``Enum`` and ``TypedDict`` also process the attributes in particular ways 3377b2d709aSJuraj Linkeš and should be documented with ``#:`` as well. 3387b2d709aSJuraj Linkeš This is mainly so that the autogenerated documentation contains the assigned value. 3397b2d709aSJuraj Linkeš * When referencing a parameter of a function or a method in their docstring, 3407b2d709aSJuraj Linkeš don't use any articles and put the parameter into single backticks. 3417b2d709aSJuraj Linkeš This mimics the style of `Python's documentation <https://docs.python.org/3/index.html>`_. 3427b2d709aSJuraj Linkeš * When specifying a value, use double backticks:: 3437b2d709aSJuraj Linkeš 3447b2d709aSJuraj Linkeš def foo(greet: bool) -> None: 3457b2d709aSJuraj Linkeš """Demonstration of single and double backticks. 3467b2d709aSJuraj Linkeš 3477b2d709aSJuraj Linkeš `greet` controls whether ``Hello World`` is printed. 3487b2d709aSJuraj Linkeš 3497b2d709aSJuraj Linkeš Args: 3507b2d709aSJuraj Linkeš greet: Whether to print the ``Hello World`` message. 3517b2d709aSJuraj Linkeš """ 3527b2d709aSJuraj Linkeš if greet: 3537b2d709aSJuraj Linkeš print(f"Hello World") 3547b2d709aSJuraj Linkeš 3557b2d709aSJuraj Linkeš * The docstring maximum line length is the same as the code maximum line length. 3567b2d709aSJuraj Linkeš 3577b2d709aSJuraj Linkeš 3586fc05ca7SJuraj LinkešHow To Write a Test Suite 3596fc05ca7SJuraj Linkeš------------------------- 3606fc05ca7SJuraj Linkeš 3616fc05ca7SJuraj LinkešAll test suites inherit from ``TestSuite`` defined in ``dts/framework/test_suite.py``. 3626fc05ca7SJuraj LinkešThere are four types of methods that comprise a test suite: 3636fc05ca7SJuraj Linkeš 3646fc05ca7SJuraj Linkeš#. **Test cases** 3656fc05ca7SJuraj Linkeš 3666fc05ca7SJuraj Linkeš | Test cases are methods that start with a particular prefix. 3676fc05ca7SJuraj Linkeš | Functional test cases start with ``test_``, e.g. ``test_hello_world_single_core``. 3686fc05ca7SJuraj Linkeš | Performance test cases start with ``test_perf_``, e.g. ``test_perf_nic_single_core``. 3696fc05ca7SJuraj Linkeš | A test suite may have any number of functional and/or performance test cases. 3706fc05ca7SJuraj Linkeš However, these test cases must test the same feature, 3716fc05ca7SJuraj Linkeš following the rule of one feature = one test suite. 3726fc05ca7SJuraj Linkeš Test cases for one feature don't need to be grouped in just one test suite, though. 3736fc05ca7SJuraj Linkeš If the feature requires many testing scenarios to cover, 3746fc05ca7SJuraj Linkeš the test cases would be better off spread over multiple test suites 3756fc05ca7SJuraj Linkeš so that each test suite doesn't take too long to execute. 3766fc05ca7SJuraj Linkeš 3776fc05ca7SJuraj Linkeš#. **Setup and Teardown methods** 3786fc05ca7SJuraj Linkeš 3796fc05ca7SJuraj Linkeš | There are setup and teardown methods for the whole test suite and each individual test case. 3806fc05ca7SJuraj Linkeš | Methods ``set_up_suite`` and ``tear_down_suite`` will be executed 3816fc05ca7SJuraj Linkeš before any and after all test cases have been executed, respectively. 3826fc05ca7SJuraj Linkeš | Methods ``set_up_test_case`` and ``tear_down_test_case`` will be executed 3836fc05ca7SJuraj Linkeš before and after each test case, respectively. 3846fc05ca7SJuraj Linkeš | These methods don't need to be implemented if there's no need for them in a test suite. 38555442c14SLuca Vizzarro In that case, nothing will happen when they are executed. 3866fc05ca7SJuraj Linkeš 3877b2d709aSJuraj Linkeš#. **Configuration, traffic and other logic** 3887b2d709aSJuraj Linkeš 3897b2d709aSJuraj Linkeš The ``TestSuite`` class contains a variety of methods for anything that 3907b2d709aSJuraj Linkeš a test suite setup, a teardown, or a test case may need to do. 3917b2d709aSJuraj Linkeš 3927b2d709aSJuraj Linkeš The test suites also frequently use a DPDK app, such as testpmd, in interactive mode 3937b2d709aSJuraj Linkeš and use the interactive shell instances directly. 3947b2d709aSJuraj Linkeš 3957b2d709aSJuraj Linkeš These are the two main ways to call the framework logic in test suites. 3967b2d709aSJuraj Linkeš If there's any functionality or logic missing from the framework, 3977b2d709aSJuraj Linkeš it should be implemented so that the test suites can use one of these two ways. 3987b2d709aSJuraj Linkeš 3996fc05ca7SJuraj Linkeš#. **Test case verification** 4006fc05ca7SJuraj Linkeš 4016fc05ca7SJuraj Linkeš Test case verification should be done with the ``verify`` method, which records the result. 4026fc05ca7SJuraj Linkeš The method should be called at the end of each test case. 4036fc05ca7SJuraj Linkeš 4046fc05ca7SJuraj Linkeš#. **Other methods** 4056fc05ca7SJuraj Linkeš 4066fc05ca7SJuraj Linkeš Of course, all test suite code should adhere to coding standards. 4076fc05ca7SJuraj Linkeš Only the above methods will be treated specially and any other methods may be defined 4086fc05ca7SJuraj Linkeš (which should be mostly private methods needed by each particular test suite). 4096fc05ca7SJuraj Linkeš Any specific features (such as NIC configuration) required by a test suite 4106fc05ca7SJuraj Linkeš should be implemented in the ``SutNode`` class (and the underlying classes that ``SutNode`` uses) 4116fc05ca7SJuraj Linkeš and used by the test suite via the ``sut_node`` field. 4126fc05ca7SJuraj Linkeš 4136fc05ca7SJuraj Linkeš 4147b2d709aSJuraj Linkeš.. _dts_dev_tools: 4157b2d709aSJuraj Linkeš 416724b8a37SJuraj LinkešDTS Developer Tools 417724b8a37SJuraj Linkeš------------------- 418724b8a37SJuraj Linkeš 419724b8a37SJuraj LinkešThere are three tools used in DTS to help with code checking, style and formatting: 420724b8a37SJuraj Linkeš 421724b8a37SJuraj Linkeš* `isort <https://pycqa.github.io/isort/>`_ 422724b8a37SJuraj Linkeš 423724b8a37SJuraj Linkeš Alphabetically sorts python imports within blocks. 424724b8a37SJuraj Linkeš 425724b8a37SJuraj Linkeš* `black <https://github.com/psf/black>`_ 426724b8a37SJuraj Linkeš 427724b8a37SJuraj Linkeš Does most of the actual formatting (whitespaces, comments, line length etc.) 428724b8a37SJuraj Linkeš and works similarly to clang-format. 429724b8a37SJuraj Linkeš 430724b8a37SJuraj Linkeš* `pylama <https://github.com/klen/pylama>`_ 431724b8a37SJuraj Linkeš 432724b8a37SJuraj Linkeš Runs a collection of python linters and aggregates output. 433724b8a37SJuraj Linkeš It will run these tools over the repository: 434724b8a37SJuraj Linkeš 435724b8a37SJuraj Linkeš .. literalinclude:: ../../../dts/pyproject.toml 436724b8a37SJuraj Linkeš :language: cfg 437724b8a37SJuraj Linkeš :start-after: [tool.pylama] 438724b8a37SJuraj Linkeš :end-at: linters 439724b8a37SJuraj Linkeš 44055442c14SLuca Vizzarro* `mypy <https://github.com/python/mypy>`_ 44155442c14SLuca Vizzarro 44255442c14SLuca Vizzarro Enables static typing for Python, exploiting the type hints in the source code. 44355442c14SLuca Vizzarro 444724b8a37SJuraj LinkešThese three tools are all used in ``devtools/dts-check-format.sh``, 445724b8a37SJuraj Linkešthe DTS code check and format script. 446724b8a37SJuraj LinkešRefer to the script for usage: ``devtools/dts-check-format.sh -h``. 447515e1a4fSLuca Vizzarro 448515e1a4fSLuca Vizzarro 4497f932642SJuraj Linkeš.. _building_api_docs: 4507f932642SJuraj Linkeš 4517f932642SJuraj LinkešBuilding DTS API docs 4527f932642SJuraj Linkeš--------------------- 4537f932642SJuraj Linkeš 4547f932642SJuraj LinkešThe documentation is built using the standard DPDK build system. 4557f932642SJuraj LinkešSee :doc:`../linux_gsg/build_dpdk` for more details on compiling DPDK with meson. 4567f932642SJuraj Linkeš 4577f932642SJuraj LinkešThe :ref:`doc build dependencies <doc_dependencies>` may be installed with Poetry: 4587f932642SJuraj Linkeš 4597f932642SJuraj Linkeš.. code-block:: console 4607f932642SJuraj Linkeš 46172a44b26SDean Marx poetry install --only docs 46272a44b26SDean Marx poetry install --with docs # an alternative that will also install DTS dependencies 4637f932642SJuraj Linkeš poetry shell 4647f932642SJuraj Linkeš 4657f932642SJuraj LinkešAfter executing the meson command, build the documentation with: 4667f932642SJuraj Linkeš 4677f932642SJuraj Linkeš.. code-block:: console 4687f932642SJuraj Linkeš 4697f932642SJuraj Linkeš ninja -C build doc 4707f932642SJuraj Linkeš 4717f932642SJuraj LinkešThe output is generated in ``build/doc/api/dts/html``. 4727f932642SJuraj Linkeš 4737f932642SJuraj Linkeš.. note:: 4747f932642SJuraj Linkeš 4757f932642SJuraj Linkeš Make sure to fix any Sphinx warnings when adding or updating docstrings. 4767f932642SJuraj Linkeš 4776597fa4aSLuca Vizzarro.. _configuration_example: 4787f932642SJuraj Linkeš 4796597fa4aSLuca VizzarroConfiguration Example 4806597fa4aSLuca Vizzarro--------------------- 481515e1a4fSLuca Vizzarro 482515e1a4fSLuca VizzarroThe following example (which can be found in ``dts/conf.yaml``) sets up two nodes: 483515e1a4fSLuca Vizzarro 484515e1a4fSLuca Vizzarro* ``SUT1`` which is already setup with the DPDK build requirements and any other 485515e1a4fSLuca Vizzarro required for execution; 486515e1a4fSLuca Vizzarro* ``TG1`` which already has Scapy installed in the system. 487515e1a4fSLuca Vizzarro 488515e1a4fSLuca VizzarroAnd they both have two network ports which are physically connected to each other. 489515e1a4fSLuca Vizzarro 490515e1a4fSLuca Vizzarro.. note:: 491515e1a4fSLuca Vizzarro This example assumes that you have setup SSH keys in both the system under test 492515e1a4fSLuca Vizzarro and traffic generator nodes. 493515e1a4fSLuca Vizzarro 494515e1a4fSLuca Vizzarro.. literalinclude:: ../../../dts/conf.yaml 495515e1a4fSLuca Vizzarro :language: yaml 49685ceeeceSJuraj Linkeš :start-at: test_runs: 497