1*49cdfc7eSAndroid Build Coastguard Worker.. SPDX-License-Identifier: GPL-2.0-or-later 2*49cdfc7eSAndroid Build Coastguard Worker 3*49cdfc7eSAndroid Build Coastguard WorkerWriting tests 4*49cdfc7eSAndroid Build Coastguard Worker============= 5*49cdfc7eSAndroid Build Coastguard Worker 6*49cdfc7eSAndroid Build Coastguard WorkerThis document describes LTP guidelines and it's intended for anybody who wants 7*49cdfc7eSAndroid Build Coastguard Workerto write or to modify a LTP testcase. It's not a definitive guide and it's not, 8*49cdfc7eSAndroid Build Coastguard Workerby any means, a substitute for common sense. 9*49cdfc7eSAndroid Build Coastguard Worker 10*49cdfc7eSAndroid Build Coastguard WorkerGuide to clean and understandable code 11*49cdfc7eSAndroid Build Coastguard Worker-------------------------------------- 12*49cdfc7eSAndroid Build Coastguard Worker 13*49cdfc7eSAndroid Build Coastguard WorkerTestcases require that the source code is easy to follow. When a test starts to 14*49cdfc7eSAndroid Build Coastguard Workerfail, the failure has to be analyzed and clean test codebase makes this task 15*49cdfc7eSAndroid Build Coastguard Workermuch easier and quicker. 16*49cdfc7eSAndroid Build Coastguard Worker 17*49cdfc7eSAndroid Build Coastguard WorkerKeep things simple 18*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~ 19*49cdfc7eSAndroid Build Coastguard Worker 20*49cdfc7eSAndroid Build Coastguard WorkerIt's worth to keep testcases simple or, better, as simple as possible. 21*49cdfc7eSAndroid Build Coastguard Worker 22*49cdfc7eSAndroid Build Coastguard WorkerThe kernel and libc are tricky beasts and the complexity imposed by their 23*49cdfc7eSAndroid Build Coastguard Workerinterfaces is quite high. Concentrate on the interface you want to test and 24*49cdfc7eSAndroid Build Coastguard Workerfollow the UNIX philosophy. 25*49cdfc7eSAndroid Build Coastguard Worker 26*49cdfc7eSAndroid Build Coastguard WorkerIt's a good idea to make the test as self-contained as possible too, ideally 27*49cdfc7eSAndroid Build Coastguard Workertests should not depend on tools or libraries that are not widely available. 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard WorkerDo not reinvent the wheel! 30*49cdfc7eSAndroid Build Coastguard Worker 31*49cdfc7eSAndroid Build Coastguard Worker* Use LTP standard interface 32*49cdfc7eSAndroid Build Coastguard Worker* Do not add custom PASS/FAIL reporting functions 33*49cdfc7eSAndroid Build Coastguard Worker* Do not write Makefiles from scratch, use LTP build system instead 34*49cdfc7eSAndroid Build Coastguard Worker* Etc. 35*49cdfc7eSAndroid Build Coastguard Worker 36*49cdfc7eSAndroid Build Coastguard WorkerKeep functions and variable names short 37*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard WorkerChoosing a good name for an API functions or even variables is a difficult 40*49cdfc7eSAndroid Build Coastguard Workertask do not underestimate it. 41*49cdfc7eSAndroid Build Coastguard Worker 42*49cdfc7eSAndroid Build Coastguard WorkerThere are a couple of customary names for different things that help people to 43*49cdfc7eSAndroid Build Coastguard Workerunderstand code, for example: 44*49cdfc7eSAndroid Build Coastguard Worker 45*49cdfc7eSAndroid Build Coastguard Worker* For loop variables are usually named with a single letter ``i``, ``j``, ... 46*49cdfc7eSAndroid Build Coastguard Worker* File descriptors ``fd`` or ``fd_foo``. 47*49cdfc7eSAndroid Build Coastguard Worker* Number of bytes stored in file are usually named as ``size`` or ``len`` 48*49cdfc7eSAndroid Build Coastguard Worker* Etc. 49*49cdfc7eSAndroid Build Coastguard Worker 50*49cdfc7eSAndroid Build Coastguard WorkerDo not over-comment 51*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~ 52*49cdfc7eSAndroid Build Coastguard Worker 53*49cdfc7eSAndroid Build Coastguard WorkerComments can sometimes save your day, but they can easily do more harm than 54*49cdfc7eSAndroid Build Coastguard Workergood. There has been several cases where comments and actual implementation 55*49cdfc7eSAndroid Build Coastguard Workerdrifted slowly apart which yielded into API misuses and hard to find bugs. 56*49cdfc7eSAndroid Build Coastguard WorkerRemember there is only one thing worse than no documentation: wrong 57*49cdfc7eSAndroid Build Coastguard Workerdocumentation. 58*49cdfc7eSAndroid Build Coastguard Worker 59*49cdfc7eSAndroid Build Coastguard WorkerIdeally, everybody should write code that is obvious, which unfortunately isn't 60*49cdfc7eSAndroid Build Coastguard Workeralways possible. If there is a code that requires to be commented, keep it 61*49cdfc7eSAndroid Build Coastguard Workershort and to the point. These comments should explain *why* and not *how* 62*49cdfc7eSAndroid Build Coastguard Workerthings are done. 63*49cdfc7eSAndroid Build Coastguard Worker 64*49cdfc7eSAndroid Build Coastguard WorkerNever ever comment the obvious. 65*49cdfc7eSAndroid Build Coastguard Worker 66*49cdfc7eSAndroid Build Coastguard WorkerIn case of LTP testcases, it's customary to add an asciidoc formatted comment 67*49cdfc7eSAndroid Build Coastguard Workerparagraph with high-level test description at the beginning of the file right 68*49cdfc7eSAndroid Build Coastguard Workerunder the GPL SPDX header. This helps other people to understand the overall 69*49cdfc7eSAndroid Build Coastguard Workergoal of the test before they dive into the technical details. It's also 70*49cdfc7eSAndroid Build Coastguard Workerexported into generated documentation hence it should mostly explain what is 71*49cdfc7eSAndroid Build Coastguard Workertested. 72*49cdfc7eSAndroid Build Coastguard Worker 73*49cdfc7eSAndroid Build Coastguard WorkerDRY (Code duplication) 74*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 75*49cdfc7eSAndroid Build Coastguard Worker 76*49cdfc7eSAndroid Build Coastguard WorkerCopy & paste is a good servant but very poor master. If you are about to copy a 77*49cdfc7eSAndroid Build Coastguard Workerlarge part of the code from one testcase to another, think what would happen if 78*49cdfc7eSAndroid Build Coastguard Workeryou find bug in the code that has been copied all around the tree. What about 79*49cdfc7eSAndroid Build Coastguard Workermoving it to a library instead? 80*49cdfc7eSAndroid Build Coastguard Worker 81*49cdfc7eSAndroid Build Coastguard WorkerThe same goes for short but complicated parts, whenever you are about to copy & 82*49cdfc7eSAndroid Build Coastguard Workerpaste a syscall wrapper that packs arguments accordingly to machine 83*49cdfc7eSAndroid Build Coastguard Workerarchitecture or similarly complicated code, put it into a header instead. 84*49cdfc7eSAndroid Build Coastguard Worker 85*49cdfc7eSAndroid Build Coastguard WorkerC coding style 86*49cdfc7eSAndroid Build Coastguard Worker-------------- 87*49cdfc7eSAndroid Build Coastguard Worker 88*49cdfc7eSAndroid Build Coastguard WorkerLTP adopted `Linux kernel coding style <https://www.kernel.org/doc/html/latest/process/coding-style.html>`_. 89*49cdfc7eSAndroid Build Coastguard WorkerRun ``make check`` in the test's directory and/or use ``make check-$TCID``, it 90*49cdfc7eSAndroid Build Coastguard Workeruses (among other checks) our vendoring version of 91*49cdfc7eSAndroid Build Coastguard Worker`checkpatch.pl <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl>`_ 92*49cdfc7eSAndroid Build Coastguard Workerscript from kernel git tree. 93*49cdfc7eSAndroid Build Coastguard Worker 94*49cdfc7eSAndroid Build Coastguard Worker.. note:: 95*49cdfc7eSAndroid Build Coastguard Worker If ``make check`` does not report any problems, the code still may be wrong 96*49cdfc7eSAndroid Build Coastguard Worker as all tools used for checking only look for common mistakes. 97*49cdfc7eSAndroid Build Coastguard Worker 98*49cdfc7eSAndroid Build Coastguard WorkerThe following linting code can be found when we run ``make check``: 99*49cdfc7eSAndroid Build Coastguard Worker 100*49cdfc7eSAndroid Build Coastguard Worker.. list-table:: 101*49cdfc7eSAndroid Build Coastguard Worker :header-rows: 1 102*49cdfc7eSAndroid Build Coastguard Worker 103*49cdfc7eSAndroid Build Coastguard Worker * - Linting code 104*49cdfc7eSAndroid Build Coastguard Worker - Message 105*49cdfc7eSAndroid Build Coastguard Worker - Explanation 106*49cdfc7eSAndroid Build Coastguard Worker 107*49cdfc7eSAndroid Build Coastguard Worker * - LTP-001 108*49cdfc7eSAndroid Build Coastguard Worker - Library source files have ``tst_`` prefix 109*49cdfc7eSAndroid Build Coastguard Worker - API source code is inside headers in ``include/{empty}*.h``, 110*49cdfc7eSAndroid Build Coastguard Worker ``include/lapi/{empty}*.h`` (backward compatibility for old kernel and 111*49cdfc7eSAndroid Build Coastguard Worker libc) and C sources in ``lib/{empty}*.c``. Files must have ``tst_`` 112*49cdfc7eSAndroid Build Coastguard Worker prefix. 113*49cdfc7eSAndroid Build Coastguard Worker 114*49cdfc7eSAndroid Build Coastguard Worker * - LTP-002 115*49cdfc7eSAndroid Build Coastguard Worker - ``TST_RET`` and ``TST_ERR`` are never modified by test library functions 116*49cdfc7eSAndroid Build Coastguard Worker - The test author is guaranteed that the test API will not modify these 117*49cdfc7eSAndroid Build Coastguard Worker variables. This prevents silent errors where the return value and 118*49cdfc7eSAndroid Build Coastguard Worker errno are overwritten before the test has chance to check them. 119*49cdfc7eSAndroid Build Coastguard Worker 120*49cdfc7eSAndroid Build Coastguard Worker The macros which are clearly intended to update these variables. That 121*49cdfc7eSAndroid Build Coastguard Worker is ``TEST`` and those in ``tst_test_macros.h``. Are of course allowed to 122*49cdfc7eSAndroid Build Coastguard Worker update these variables. 123*49cdfc7eSAndroid Build Coastguard Worker 124*49cdfc7eSAndroid Build Coastguard Worker * - LTP-003 125*49cdfc7eSAndroid Build Coastguard Worker - Externally visible library symbols have the ``tst_`` prefix 126*49cdfc7eSAndroid Build Coastguard Worker - Functions, types and variables in the public test API should have the 127*49cdfc7eSAndroid Build Coastguard Worker ``tst_`` prefix. With some exceptions for symbols already prefixed with 128*49cdfc7eSAndroid Build Coastguard Worker ``safe_`` or ``ltp_``. 129*49cdfc7eSAndroid Build Coastguard Worker 130*49cdfc7eSAndroid Build Coastguard Worker Static (private) symbols should not have the prefix. 131*49cdfc7eSAndroid Build Coastguard Worker 132*49cdfc7eSAndroid Build Coastguard Worker * - LTP-004 133*49cdfc7eSAndroid Build Coastguard Worker - Test executable symbols are marked ``static`` 134*49cdfc7eSAndroid Build Coastguard Worker - Test executables should not export symbols unnecessarily. This means 135*49cdfc7eSAndroid Build Coastguard Worker that all top-level variables and functions should be marked with the 136*49cdfc7eSAndroid Build Coastguard Worker ``static`` keyword. The only visible symbols should be those included 137*49cdfc7eSAndroid Build Coastguard Worker from shared object files. 138*49cdfc7eSAndroid Build Coastguard Worker 139*49cdfc7eSAndroid Build Coastguard Worker * - LTP-005 140*49cdfc7eSAndroid Build Coastguard Worker - Array must terminate with a sentinel value (i.e. ``NULL`` or ``{}``) 141*49cdfc7eSAndroid Build Coastguard Worker - When defining arrays in the ``struct tst_test`` structure, we need to 142*49cdfc7eSAndroid Build Coastguard Worker end the array items with a sentinel ``NULL`` value. 143*49cdfc7eSAndroid Build Coastguard Worker 144*49cdfc7eSAndroid Build Coastguard WorkerShell coding style 145*49cdfc7eSAndroid Build Coastguard Worker------------------ 146*49cdfc7eSAndroid Build Coastguard Worker 147*49cdfc7eSAndroid Build Coastguard WorkerWhen writing testcases in shell, write in *portable shell* only, it's a good 148*49cdfc7eSAndroid Build Coastguard Workeridea to try to run the test using alternative shell (alternative to bash, for 149*49cdfc7eSAndroid Build Coastguard Workerexample dash) too. 150*49cdfc7eSAndroid Build Coastguard Worker 151*49cdfc7eSAndroid Build Coastguard Worker*Portable shell* means Shell Command Language as defined by POSIX with an 152*49cdfc7eSAndroid Build Coastguard Workerexception of few widely used extensions, namely **local** keyword used inside of 153*49cdfc7eSAndroid Build Coastguard Workerfunctions and ``-o`` and ``-a`` test parameters (that are marked as obsolete in 154*49cdfc7eSAndroid Build Coastguard WorkerPOSIX). 155*49cdfc7eSAndroid Build Coastguard Worker 156*49cdfc7eSAndroid Build Coastguard WorkerYou can either try to run the testcases in Debian which has ``/bin/sh`` pointing 157*49cdfc7eSAndroid Build Coastguard Workerto ``dash`` by default, or to install ``dash`` on your favorite distribution, 158*49cdfc7eSAndroid Build Coastguard Workerthen use it to run tests. If your distribution lacks ``dash`` package, you can 159*49cdfc7eSAndroid Build Coastguard Workeralways compile it from `sources <http://gondor.apana.org.au/~herbert/dash/files/>`_. 160*49cdfc7eSAndroid Build Coastguard Worker 161*49cdfc7eSAndroid Build Coastguard WorkerRun ``make check`` in the test's directory and/or use ``make check-$TCID.sh``. 162*49cdfc7eSAndroid Build Coastguard WorkerIt uses (among other checks) our vendoring version of 163*49cdfc7eSAndroid Build Coastguard Worker`checkbashism.pl <https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkbashisms.pl>`_ 164*49cdfc7eSAndroid Build Coastguard Workerfrom Debian that is used to check for non-portable shell code. 165*49cdfc7eSAndroid Build Coastguard Worker 166*49cdfc7eSAndroid Build Coastguard Worker.. note:: 167*49cdfc7eSAndroid Build Coastguard Worker 168*49cdfc7eSAndroid Build Coastguard Worker If ``make check`` does not report any problems the code still may be wrong, 169*49cdfc7eSAndroid Build Coastguard Worker as ``checkbashisms.pl`` is used for checking only common mistakes. 170*49cdfc7eSAndroid Build Coastguard Worker 171*49cdfc7eSAndroid Build Coastguard WorkerHere there are some common sense style rules for shell 172*49cdfc7eSAndroid Build Coastguard Worker 173*49cdfc7eSAndroid Build Coastguard Worker* Keep lines under 80 chars 174*49cdfc7eSAndroid Build Coastguard Worker* Use tabs for indentation 175*49cdfc7eSAndroid Build Coastguard Worker* Keep things simple, avoid unnecessary subshells 176*49cdfc7eSAndroid Build Coastguard Worker* Don't do confusing things (i.e. don't name your functions like common shell 177*49cdfc7eSAndroid Build Coastguard Worker commands, etc.) 178*49cdfc7eSAndroid Build Coastguard Worker* Quote variables 179*49cdfc7eSAndroid Build Coastguard Worker* Be consistent 180*49cdfc7eSAndroid Build Coastguard Worker 181*49cdfc7eSAndroid Build Coastguard Worker3 Backwards compatibility 182*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~ 183*49cdfc7eSAndroid Build Coastguard Worker 184*49cdfc7eSAndroid Build Coastguard WorkerLTP test should be as backward compatible as possible. Think of an enterprise 185*49cdfc7eSAndroid Build Coastguard Workerdistributions with long term support (more than five years since the initial 186*49cdfc7eSAndroid Build Coastguard Workerrelease) or of an embedded platform that needs to use several years old 187*49cdfc7eSAndroid Build Coastguard Workertoolchain supplied by the manufacturer. 188*49cdfc7eSAndroid Build Coastguard Worker 189*49cdfc7eSAndroid Build Coastguard WorkerTherefore LTP test for more current features should be able to cope with older 190*49cdfc7eSAndroid Build Coastguard Workersystems. It should at least compile fine and if it's not appropriate for the 191*49cdfc7eSAndroid Build Coastguard Workerconfiguration it should return ``TCONF``. 192*49cdfc7eSAndroid Build Coastguard Worker 193*49cdfc7eSAndroid Build Coastguard WorkerThere are several types of checks we use: 194*49cdfc7eSAndroid Build Coastguard Worker 195*49cdfc7eSAndroid Build Coastguard Worker* The *configure script* is usually used to detect availability of a function 196*49cdfc7eSAndroid Build Coastguard Worker declarations in system headers. It's used to disable tests at compile time or 197*49cdfc7eSAndroid Build Coastguard Worker to enable fallback definitions. 198*49cdfc7eSAndroid Build Coastguard Worker 199*49cdfc7eSAndroid Build Coastguard Worker* Checking the ``errno`` value is another type of runtime check. Most of the 200*49cdfc7eSAndroid Build Coastguard Worker syscalls returns either ``EINVAL`` or ``ENOSYS`` when syscall was not 201*49cdfc7eSAndroid Build Coastguard Worker implemented or was disabled upon kernel compilation. 202*49cdfc7eSAndroid Build Coastguard Worker 203*49cdfc7eSAndroid Build Coastguard Worker* LTP has kernel version detection that can be used to disable tests at runtime. 204*49cdfc7eSAndroid Build Coastguard Worker Unfortunately, the kernel version does not always corresponds to a well 205*49cdfc7eSAndroid Build Coastguard Worker defined feature set, as distributions tend to backport hundreds of patches 206*49cdfc7eSAndroid Build Coastguard Worker while the kernel version stays the same. Use with caution. 207*49cdfc7eSAndroid Build Coastguard Worker 208*49cdfc7eSAndroid Build Coastguard Worker* Lately, we added a kernel ``.config`` parser. A test can define a boolean 209*49cdfc7eSAndroid Build Coastguard Worker expression of kernel config variables that has to be satisfied in order to run 210*49cdfc7eSAndroid Build Coastguard Worker a test. At the moment, this is mostly used for kernel namespaces. 211*49cdfc7eSAndroid Build Coastguard Worker 212*49cdfc7eSAndroid Build Coastguard Worker* Sometimes it makes sense to define a few macros instead of creating a 213*49cdfc7eSAndroid Build Coastguard Worker configure test. One example is Linux specific POSIX clock ids in 214*49cdfc7eSAndroid Build Coastguard Worker :master:`include/lapi/posix_clocks.h`. 215*49cdfc7eSAndroid Build Coastguard Worker 216*49cdfc7eSAndroid Build Coastguard WorkerDealing with messed up legacy code 217*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 218*49cdfc7eSAndroid Build Coastguard Worker 219*49cdfc7eSAndroid Build Coastguard WorkerLTP still contains a lot of old and messy code and we are cleaning it up as 220*49cdfc7eSAndroid Build Coastguard Workerfast as we can but, despite the decade of efforts, there is still a lot of it. 221*49cdfc7eSAndroid Build Coastguard WorkerIf you start modifying old or a messy testcase and your changes are more 222*49cdfc7eSAndroid Build Coastguard Workercomplicated than simple typo fixes, you should convert the test into a new 223*49cdfc7eSAndroid Build Coastguard Workerlibrary first. 224*49cdfc7eSAndroid Build Coastguard Worker 225*49cdfc7eSAndroid Build Coastguard WorkerIt's also much easier to review the changes if you split them into a smaller 226*49cdfc7eSAndroid Build Coastguard Workerlogical groups. The same goes for moving files: if you need to rename or to move 227*49cdfc7eSAndroid Build Coastguard Workerfiles, do it in a separate patch. 228*49cdfc7eSAndroid Build Coastguard Worker 229*49cdfc7eSAndroid Build Coastguard WorkerLicense 230*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~ 231*49cdfc7eSAndroid Build Coastguard Worker 232*49cdfc7eSAndroid Build Coastguard WorkerCode contributed to LTP should be licensed under GPLv2+ (GNU GPL version 2 or 233*49cdfc7eSAndroid Build Coastguard Workerany later version). 234*49cdfc7eSAndroid Build Coastguard Worker 235*49cdfc7eSAndroid Build Coastguard WorkerUse ``SPDX-License-Identifier: GPL-2.0-or-later`` 236*49cdfc7eSAndroid Build Coastguard Worker 237*49cdfc7eSAndroid Build Coastguard WorkerLTP Structure 238*49cdfc7eSAndroid Build Coastguard Worker------------- 239*49cdfc7eSAndroid Build Coastguard Worker 240*49cdfc7eSAndroid Build Coastguard WorkerThe structure of LTP is quite simple. Each test is a binary written either in 241*49cdfc7eSAndroid Build Coastguard Workerportable shell or C. The test gets a configuration via environment variables 242*49cdfc7eSAndroid Build Coastguard Workerand/or command line parameters, it prints additional information into the 243*49cdfc7eSAndroid Build Coastguard Workerstdout and reports overall success/failure via the exit value. 244*49cdfc7eSAndroid Build Coastguard Worker 245*49cdfc7eSAndroid Build Coastguard WorkerTests are generally placed under the :master:`testcases` directory. Everything that 246*49cdfc7eSAndroid Build Coastguard Workeris a syscall or (slightly confusingly) libc syscall wrapper, goes under 247*49cdfc7eSAndroid Build Coastguard Worker:master:`testcases/kernel/syscalls/`. 248*49cdfc7eSAndroid Build Coastguard Worker 249*49cdfc7eSAndroid Build Coastguard WorkerThere is also :master:`testcases/open_posix_testsuite/` which is a well maintained 250*49cdfc7eSAndroid Build Coastguard Workerfork of the Open POSIX testsuite project, that has been dead since 2005. 251*49cdfc7eSAndroid Build Coastguard Worker 252*49cdfc7eSAndroid Build Coastguard WorkerWe also have a number of directories with tests for more specific features, such 253*49cdfc7eSAndroid Build Coastguard Workeras containers, etc. 254*49cdfc7eSAndroid Build Coastguard Worker 255*49cdfc7eSAndroid Build Coastguard WorkerRuntest Files 256*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~ 257*49cdfc7eSAndroid Build Coastguard Worker 258*49cdfc7eSAndroid Build Coastguard WorkerThe list of tests to be executed is stored in runtest files under the 259*49cdfc7eSAndroid Build Coastguard Worker:master:`runtest` directory. The default set of runtest files to be executed is 260*49cdfc7eSAndroid Build Coastguard Workerstored in :master:`scenario_groups/default`. When you add a test, you should add 261*49cdfc7eSAndroid Build Coastguard Workercorresponding entries into some runtest file(s) as well. 262*49cdfc7eSAndroid Build Coastguard Worker 263*49cdfc7eSAndroid Build Coastguard WorkerEach line of runtest file contains one test. The first item is the test name. 264*49cdfc7eSAndroid Build Coastguard WorkerAll other items, separated by space will be executed as a command. 265*49cdfc7eSAndroid Build Coastguard Worker 266*49cdfc7eSAndroid Build Coastguard Worker.. code-block:: bash 267*49cdfc7eSAndroid Build Coastguard Worker 268*49cdfc7eSAndroid Build Coastguard Worker shell_test01 echo "SUCCESS" | shell_pipe01.sh 269*49cdfc7eSAndroid Build Coastguard Worker splice02 splice02 -s 20 270*49cdfc7eSAndroid Build Coastguard Worker 271*49cdfc7eSAndroid Build Coastguard WorkerBlank lines and lines starting with a ``#`` (comments) are ignored. 272*49cdfc7eSAndroid Build Coastguard Worker 273*49cdfc7eSAndroid Build Coastguard WorkerSyscalls tests, placed under :master:`testcases/kernel/syscalls/`, use 274*49cdfc7eSAndroid Build Coastguard Worker:master:`runtest/syscalls` file. For kernel related tests for memory management we 275*49cdfc7eSAndroid Build Coastguard Workerhave :master:`runtest/mm`, etc. 276*49cdfc7eSAndroid Build Coastguard Worker 277*49cdfc7eSAndroid Build Coastguard Worker.. note:: 278*49cdfc7eSAndroid Build Coastguard Worker 279*49cdfc7eSAndroid Build Coastguard Worker runtest files should have one entry per a test. Creating a 280*49cdfc7eSAndroid Build Coastguard Worker wrapper that runs all your tests and adding it as a single test 281*49cdfc7eSAndroid Build Coastguard Worker into runtest file is strongly discouraged. 282*49cdfc7eSAndroid Build Coastguard Worker 283*49cdfc7eSAndroid Build Coastguard WorkerDatafiles 284*49cdfc7eSAndroid Build Coastguard Worker--------- 285*49cdfc7eSAndroid Build Coastguard Worker 286*49cdfc7eSAndroid Build Coastguard WorkerIf your test needs data files, these should be put into a subdirectory 287*49cdfc7eSAndroid Build Coastguard Workernamed ``datafiles`` and installed into the ``testcases/data/$TCID`` directory. 288*49cdfc7eSAndroid Build Coastguard WorkerThis will require to add ``INSTALL_DIR := testcases/data/TCID`` into 289*49cdfc7eSAndroid Build Coastguard Workercorrespondent ``datafiles/Makefile``. 290*49cdfc7eSAndroid Build Coastguard Worker 291*49cdfc7eSAndroid Build Coastguard WorkerYou can obtain path to datafiles via ``$TST_DATAROOT`` provided by ``test.sh`` 292*49cdfc7eSAndroid Build Coastguard Workeror via C function ``tst_dataroot()`` provided by libltp: 293*49cdfc7eSAndroid Build Coastguard Worker 294*49cdfc7eSAndroid Build Coastguard Worker.. code-block:: c 295*49cdfc7eSAndroid Build Coastguard Worker 296*49cdfc7eSAndroid Build Coastguard Worker const char *dataroot = tst_dataroot(); 297*49cdfc7eSAndroid Build Coastguard Worker 298*49cdfc7eSAndroid Build Coastguard WorkerDatafiles can also be accessed as ``$LTPROOT/testcases/data/$TCID/...``, 299*49cdfc7eSAndroid Build Coastguard Workerbut ``$TST_DATAROOT`` and ``tst_dataroot()`` are preferred, as these can be used 300*49cdfc7eSAndroid Build Coastguard Workerwhen running testcases directly in git tree as well as from install location. 301*49cdfc7eSAndroid Build Coastguard Worker 302*49cdfc7eSAndroid Build Coastguard WorkerSub-executables 303*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~ 304*49cdfc7eSAndroid Build Coastguard Worker 305*49cdfc7eSAndroid Build Coastguard WorkerIf your test needs to execute a binary, place it in the same directory of the 306*49cdfc7eSAndroid Build Coastguard Workertestcase and name the binary with ``$TESTNAME_`` prefix, where ``$TESTNAME`` is 307*49cdfc7eSAndroid Build Coastguard Workerthe name of the test binary. Once the test is executed by the framework, the 308*49cdfc7eSAndroid Build Coastguard Workerpath to the directory with all LTP binaries is added to the ``$PATH`` and you 309*49cdfc7eSAndroid Build Coastguard Workercan execute it via its name. 310*49cdfc7eSAndroid Build Coastguard Worker 311*49cdfc7eSAndroid Build Coastguard Worker.. note:: 312*49cdfc7eSAndroid Build Coastguard Worker 313*49cdfc7eSAndroid Build Coastguard Worker If you need to execute a test from the LTP tree, you can add ``PATH`` to 314*49cdfc7eSAndroid Build Coastguard Worker the current directory with ``PATH="$PATH:$PWD" ./foo01``. 315*49cdfc7eSAndroid Build Coastguard Worker 316*49cdfc7eSAndroid Build Coastguard WorkerTest Contribution Checklist 317*49cdfc7eSAndroid Build Coastguard Worker--------------------------- 318*49cdfc7eSAndroid Build Coastguard Worker 319*49cdfc7eSAndroid Build Coastguard Worker#. Test compiles and it runs fine (check with ``-i 10`` and ``-i 0`` too) 320*49cdfc7eSAndroid Build Coastguard Worker#. ``make check`` should not emit any warnings for the test you are working on 321*49cdfc7eSAndroid Build Coastguard Worker (hint: run it in the test's directory and/or use ``make check-$TCID``) 322*49cdfc7eSAndroid Build Coastguard Worker#. The runtest entries are in place 323*49cdfc7eSAndroid Build Coastguard Worker#. New test binaries are added into the corresponding ``.gitignore`` files 324*49cdfc7eSAndroid Build Coastguard Worker#. Patches apply over the latest git 325*49cdfc7eSAndroid Build Coastguard Worker 326*49cdfc7eSAndroid Build Coastguard WorkerAbout .gitignore files 327*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 328*49cdfc7eSAndroid Build Coastguard Worker 329*49cdfc7eSAndroid Build Coastguard WorkerThere are numerous ``.gitignore`` files in the LTP tree. Usually, there is a 330*49cdfc7eSAndroid Build Coastguard Worker``.gitignore`` file for a group of tests. The reason of this setup is simple: 331*49cdfc7eSAndroid Build Coastguard Workerit's easier to maintain a ``.gitignore`` file per tests' directory, rather 332*49cdfc7eSAndroid Build Coastguard Workerthan having a single file in the project root directory. In this way, we don't 333*49cdfc7eSAndroid Build Coastguard Workerhave to update all the gitignore files when moving directories, and they get 334*49cdfc7eSAndroid Build Coastguard Workerdeleted automatically when a directory with tests is removed. 335*49cdfc7eSAndroid Build Coastguard Worker 336*49cdfc7eSAndroid Build Coastguard WorkerTesting pre-release kernel features 337*49cdfc7eSAndroid Build Coastguard Worker----------------------------------- 338*49cdfc7eSAndroid Build Coastguard Worker 339*49cdfc7eSAndroid Build Coastguard WorkerTests for features not yet in the mainline kernel release are accepted. However, 340*49cdfc7eSAndroid Build Coastguard Workerthey must be added only to :master:`runtest/staging`. Once a feature is part 341*49cdfc7eSAndroid Build Coastguard Workerof the stable kernel ABI, the associated test must be moved out of staging. 342*49cdfc7eSAndroid Build Coastguard Worker 343*49cdfc7eSAndroid Build Coastguard WorkerTesting builds with GitHub Actions 344*49cdfc7eSAndroid Build Coastguard Worker---------------------------------- 345*49cdfc7eSAndroid Build Coastguard Worker 346*49cdfc7eSAndroid Build Coastguard WorkerMaster branch is tested in GitHub :repo:`actions` 347*49cdfc7eSAndroid Build Coastguard Workerto ensure LTP builds in various distributions, including old, current and 348*49cdfc7eSAndroid Build Coastguard Workerbleeding edge. ``gcc`` and ``clang`` toolchains are also tested for various 349*49cdfc7eSAndroid Build Coastguard Workerarchitectures using cross-compilation. For a full list of tested distros, please 350*49cdfc7eSAndroid Build Coastguard Workercheck :master:`.github/workflows/ci-docker-build.yml`. 351*49cdfc7eSAndroid Build Coastguard Worker 352*49cdfc7eSAndroid Build Coastguard Worker.. note:: 353*49cdfc7eSAndroid Build Coastguard Worker 354*49cdfc7eSAndroid Build Coastguard Worker Passing the GitHub Actions CI means that LTP compiles in a variety of 355*49cdfc7eSAndroid Build Coastguard Worker different distributions on their **newest releases**. 356*49cdfc7eSAndroid Build Coastguard Worker The CI also checks for code linting, running ``make check`` in the whole 357*49cdfc7eSAndroid Build Coastguard Worker LTP project. 358*49cdfc7eSAndroid Build Coastguard Worker 359*49cdfc7eSAndroid Build Coastguard WorkerLTP C And Shell Test API Comparison 360*49cdfc7eSAndroid Build Coastguard Worker----------------------------------- 361*49cdfc7eSAndroid Build Coastguard Worker 362*49cdfc7eSAndroid Build Coastguard Worker.. list-table:: 363*49cdfc7eSAndroid Build Coastguard Worker :header-rows: 1 364*49cdfc7eSAndroid Build Coastguard Worker 365*49cdfc7eSAndroid Build Coastguard Worker * - C API ``struct tst_test`` members 366*49cdfc7eSAndroid Build Coastguard Worker - Shell API ``$TST_*`` variables 367*49cdfc7eSAndroid Build Coastguard Worker 368*49cdfc7eSAndroid Build Coastguard Worker * - .all_filesystems 369*49cdfc7eSAndroid Build Coastguard Worker - TST_ALL_FILESYSTEMS 370*49cdfc7eSAndroid Build Coastguard Worker 371*49cdfc7eSAndroid Build Coastguard Worker * - .bufs 372*49cdfc7eSAndroid Build Coastguard Worker - \- 373*49cdfc7eSAndroid Build Coastguard Worker 374*49cdfc7eSAndroid Build Coastguard Worker * - .caps 375*49cdfc7eSAndroid Build Coastguard Worker - \- 376*49cdfc7eSAndroid Build Coastguard Worker 377*49cdfc7eSAndroid Build Coastguard Worker * - .child_needs_reinit 378*49cdfc7eSAndroid Build Coastguard Worker - not applicable 379*49cdfc7eSAndroid Build Coastguard Worker 380*49cdfc7eSAndroid Build Coastguard Worker * - .cleanup 381*49cdfc7eSAndroid Build Coastguard Worker - TST_CLEANUP 382*49cdfc7eSAndroid Build Coastguard Worker 383*49cdfc7eSAndroid Build Coastguard Worker * - .dev_extra_opts 384*49cdfc7eSAndroid Build Coastguard Worker - TST_DEV_EXTRA_OPTS 385*49cdfc7eSAndroid Build Coastguard Worker 386*49cdfc7eSAndroid Build Coastguard Worker * - .dev_fs_opts 387*49cdfc7eSAndroid Build Coastguard Worker - TST_DEV_FS_OPTS 388*49cdfc7eSAndroid Build Coastguard Worker 389*49cdfc7eSAndroid Build Coastguard Worker * - .dev_fs_type 390*49cdfc7eSAndroid Build Coastguard Worker - TST_FS_TYPE 391*49cdfc7eSAndroid Build Coastguard Worker 392*49cdfc7eSAndroid Build Coastguard Worker * - .dev_min_size 393*49cdfc7eSAndroid Build Coastguard Worker - not applicable 394*49cdfc7eSAndroid Build Coastguard Worker 395*49cdfc7eSAndroid Build Coastguard Worker * - .format_device 396*49cdfc7eSAndroid Build Coastguard Worker - TST_FORMAT_DEVICE 397*49cdfc7eSAndroid Build Coastguard Worker 398*49cdfc7eSAndroid Build Coastguard Worker * - .max_runtime 399*49cdfc7eSAndroid Build Coastguard Worker - \- 400*49cdfc7eSAndroid Build Coastguard Worker 401*49cdfc7eSAndroid Build Coastguard Worker * - .min_cpus 402*49cdfc7eSAndroid Build Coastguard Worker - not applicable 403*49cdfc7eSAndroid Build Coastguard Worker 404*49cdfc7eSAndroid Build Coastguard Worker * - .min_kver 405*49cdfc7eSAndroid Build Coastguard Worker - TST_MIN_KVER 406*49cdfc7eSAndroid Build Coastguard Worker 407*49cdfc7eSAndroid Build Coastguard Worker * - .min_mem_avail 408*49cdfc7eSAndroid Build Coastguard Worker - not applicable 409*49cdfc7eSAndroid Build Coastguard Worker 410*49cdfc7eSAndroid Build Coastguard Worker * - .mnt_flags 411*49cdfc7eSAndroid Build Coastguard Worker - TST_MNT_PARAMS 412*49cdfc7eSAndroid Build Coastguard Worker 413*49cdfc7eSAndroid Build Coastguard Worker * - .min_swap_avail 414*49cdfc7eSAndroid Build Coastguard Worker - not applicable 415*49cdfc7eSAndroid Build Coastguard Worker 416*49cdfc7eSAndroid Build Coastguard Worker * - .mntpoint | .mnt_data 417*49cdfc7eSAndroid Build Coastguard Worker - TST_MNTPOINT 418*49cdfc7eSAndroid Build Coastguard Worker 419*49cdfc7eSAndroid Build Coastguard Worker * - .mount_device 420*49cdfc7eSAndroid Build Coastguard Worker - TST_MOUNT_DEVICE 421*49cdfc7eSAndroid Build Coastguard Worker 422*49cdfc7eSAndroid Build Coastguard Worker * - .needs_cgroup_ctrls 423*49cdfc7eSAndroid Build Coastguard Worker - \- 424*49cdfc7eSAndroid Build Coastguard Worker 425*49cdfc7eSAndroid Build Coastguard Worker * - .needs_checkpoints 426*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_CHECKPOINTS 427*49cdfc7eSAndroid Build Coastguard Worker 428*49cdfc7eSAndroid Build Coastguard Worker * - .needs_cmds 429*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_CMDS 430*49cdfc7eSAndroid Build Coastguard Worker 431*49cdfc7eSAndroid Build Coastguard Worker * - .needs_devfs 432*49cdfc7eSAndroid Build Coastguard Worker - \- 433*49cdfc7eSAndroid Build Coastguard Worker 434*49cdfc7eSAndroid Build Coastguard Worker * - .needs_device 435*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_DEVICE 436*49cdfc7eSAndroid Build Coastguard Worker 437*49cdfc7eSAndroid Build Coastguard Worker * - .needs_drivers 438*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_DRIVERS 439*49cdfc7eSAndroid Build Coastguard Worker 440*49cdfc7eSAndroid Build Coastguard Worker * - .needs_kconfigs 441*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_KCONFIGS 442*49cdfc7eSAndroid Build Coastguard Worker 443*49cdfc7eSAndroid Build Coastguard Worker * - .needs_overlay 444*49cdfc7eSAndroid Build Coastguard Worker - \- 445*49cdfc7eSAndroid Build Coastguard Worker 446*49cdfc7eSAndroid Build Coastguard Worker * - .needs_rofs 447*49cdfc7eSAndroid Build Coastguard Worker - \- 448*49cdfc7eSAndroid Build Coastguard Worker 449*49cdfc7eSAndroid Build Coastguard Worker * - .needs_root 450*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_ROOT 451*49cdfc7eSAndroid Build Coastguard Worker 452*49cdfc7eSAndroid Build Coastguard Worker * - .needs_tmpdir 453*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_TMPDIR 454*49cdfc7eSAndroid Build Coastguard Worker 455*49cdfc7eSAndroid Build Coastguard Worker * - .options 456*49cdfc7eSAndroid Build Coastguard Worker - TST_PARSE_ARGS | TST_OPTS 457*49cdfc7eSAndroid Build Coastguard Worker 458*49cdfc7eSAndroid Build Coastguard Worker * - .resource_files 459*49cdfc7eSAndroid Build Coastguard Worker - \- 460*49cdfc7eSAndroid Build Coastguard Worker 461*49cdfc7eSAndroid Build Coastguard Worker * - .restore_wallclock 462*49cdfc7eSAndroid Build Coastguard Worker - not applicable 463*49cdfc7eSAndroid Build Coastguard Worker 464*49cdfc7eSAndroid Build Coastguard Worker * - .sample 465*49cdfc7eSAndroid Build Coastguard Worker - \- 466*49cdfc7eSAndroid Build Coastguard Worker 467*49cdfc7eSAndroid Build Coastguard Worker * - .save_restore 468*49cdfc7eSAndroid Build Coastguard Worker - \- 469*49cdfc7eSAndroid Build Coastguard Worker 470*49cdfc7eSAndroid Build Coastguard Worker * - .scall 471*49cdfc7eSAndroid Build Coastguard Worker - not applicable 472*49cdfc7eSAndroid Build Coastguard Worker 473*49cdfc7eSAndroid Build Coastguard Worker * - .setup 474*49cdfc7eSAndroid Build Coastguard Worker - TST_SETUP 475*49cdfc7eSAndroid Build Coastguard Worker 476*49cdfc7eSAndroid Build Coastguard Worker * - .skip_filesystems 477*49cdfc7eSAndroid Build Coastguard Worker - TST_SKIP_FILESYSTEMS 478*49cdfc7eSAndroid Build Coastguard Worker 479*49cdfc7eSAndroid Build Coastguard Worker * - .skip_in_compat 480*49cdfc7eSAndroid Build Coastguard Worker - \- 481*49cdfc7eSAndroid Build Coastguard Worker 482*49cdfc7eSAndroid Build Coastguard Worker * - .skip_in_lockdown 483*49cdfc7eSAndroid Build Coastguard Worker - TST_SKIP_IN_LOCKDOWN 484*49cdfc7eSAndroid Build Coastguard Worker 485*49cdfc7eSAndroid Build Coastguard Worker * - .skip_in_secureboot 486*49cdfc7eSAndroid Build Coastguard Worker - TST_SKIP_IN_SECUREBOOT 487*49cdfc7eSAndroid Build Coastguard Worker 488*49cdfc7eSAndroid Build Coastguard Worker * - .supported_archs 489*49cdfc7eSAndroid Build Coastguard Worker - not applicable 490*49cdfc7eSAndroid Build Coastguard Worker 491*49cdfc7eSAndroid Build Coastguard Worker * - .tags 492*49cdfc7eSAndroid Build Coastguard Worker - \- 493*49cdfc7eSAndroid Build Coastguard Worker 494*49cdfc7eSAndroid Build Coastguard Worker * - .taint_check 495*49cdfc7eSAndroid Build Coastguard Worker - \- 496*49cdfc7eSAndroid Build Coastguard Worker 497*49cdfc7eSAndroid Build Coastguard Worker * - .tcnt 498*49cdfc7eSAndroid Build Coastguard Worker - TST_CNT 499*49cdfc7eSAndroid Build Coastguard Worker 500*49cdfc7eSAndroid Build Coastguard Worker * - .tconf_msg 501*49cdfc7eSAndroid Build Coastguard Worker - not applicable 502*49cdfc7eSAndroid Build Coastguard Worker 503*49cdfc7eSAndroid Build Coastguard Worker * - .test | .test_all 504*49cdfc7eSAndroid Build Coastguard Worker - TST_TESTFUNC 505*49cdfc7eSAndroid Build Coastguard Worker 506*49cdfc7eSAndroid Build Coastguard Worker * - .test_variants 507*49cdfc7eSAndroid Build Coastguard Worker - \- 508*49cdfc7eSAndroid Build Coastguard Worker 509*49cdfc7eSAndroid Build Coastguard Worker * - .timeout 510*49cdfc7eSAndroid Build Coastguard Worker - TST_TIMEOUT 511*49cdfc7eSAndroid Build Coastguard Worker 512*49cdfc7eSAndroid Build Coastguard Worker * - .tst_hugepage 513*49cdfc7eSAndroid Build Coastguard Worker - not applicable 514*49cdfc7eSAndroid Build Coastguard Worker 515*49cdfc7eSAndroid Build Coastguard Worker * - .ulimit 516*49cdfc7eSAndroid Build Coastguard Worker - not applicable 517*49cdfc7eSAndroid Build Coastguard Worker 518*49cdfc7eSAndroid Build Coastguard Worker * - not applicable 519*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_KCONFIGS_IFS 520*49cdfc7eSAndroid Build Coastguard Worker 521*49cdfc7eSAndroid Build Coastguard Worker * - not applicable 522*49cdfc7eSAndroid Build Coastguard Worker - TST_NEEDS_MODULE 523*49cdfc7eSAndroid Build Coastguard Worker 524*49cdfc7eSAndroid Build Coastguard Worker * - not applicable 525*49cdfc7eSAndroid Build Coastguard Worker - TST_POS_ARGS 526*49cdfc7eSAndroid Build Coastguard Worker 527*49cdfc7eSAndroid Build Coastguard Worker * - not applicable 528*49cdfc7eSAndroid Build Coastguard Worker - TST_USAGE 529*49cdfc7eSAndroid Build Coastguard Worker 530*49cdfc7eSAndroid Build Coastguard Worker.. list-table:: 531*49cdfc7eSAndroid Build Coastguard Worker :header-rows: 1 532*49cdfc7eSAndroid Build Coastguard Worker 533*49cdfc7eSAndroid Build Coastguard Worker * - C API other structs 534*49cdfc7eSAndroid Build Coastguard Worker - Shell API ``$TST_*`` variables 535*49cdfc7eSAndroid Build Coastguard Worker 536*49cdfc7eSAndroid Build Coastguard Worker * - struct tst_device 537*49cdfc7eSAndroid Build Coastguard Worker - TST_DEVICE 538