1*49cdfc7eSAndroid Build Coastguard WorkerLTP Test Writing Guidelines 2*49cdfc7eSAndroid Build Coastguard Worker=========================== 3*49cdfc7eSAndroid Build Coastguard Worker 4*49cdfc7eSAndroid Build Coastguard WorkerThis document describes LTP guidelines and is intended for anybody who want to 5*49cdfc7eSAndroid Build Coastguard Workerwrite or modify a LTP testcase. It's not a definitive guide and it's not, by 6*49cdfc7eSAndroid Build Coastguard Workerany means, a substitute for common sense. 7*49cdfc7eSAndroid Build Coastguard Worker 8*49cdfc7eSAndroid Build Coastguard WorkerNOTE: See also 9*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API], 10*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API], 11*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/LTP-Library-API-Writing-Guidelines[LTP Library API Writing Guidelines]. 12*49cdfc7eSAndroid Build Coastguard Worker 13*49cdfc7eSAndroid Build Coastguard WorkerRules and recommendations which are "machine checkable" should be 14*49cdfc7eSAndroid Build Coastguard Workertagged with an ID like +LTP-XXX+. There will be a corresponding entry 15*49cdfc7eSAndroid Build Coastguard Workerin 16*49cdfc7eSAndroid Build Coastguard Workerhttps://github.com/linux-test-project/ltp/tree/master/doc/rules.tsv[doc/rules.tsv]. When 17*49cdfc7eSAndroid Build Coastguard Workeryou run 'make check' or 'make check-test' it will display these IDs as 18*49cdfc7eSAndroid Build Coastguard Workera reference. 19*49cdfc7eSAndroid Build Coastguard Worker 20*49cdfc7eSAndroid Build Coastguard Worker1. Guide to clean and understandable code 21*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22*49cdfc7eSAndroid Build Coastguard Worker 23*49cdfc7eSAndroid Build Coastguard WorkerFor testcases it's required that the source code is as easy to follow as 24*49cdfc7eSAndroid Build Coastguard Workerpossible. When a test starts to fail the failure has to be analyzed, clean 25*49cdfc7eSAndroid Build Coastguard Workertest codebase makes this task much easier and quicker. 26*49cdfc7eSAndroid Build Coastguard Worker 27*49cdfc7eSAndroid Build Coastguard WorkerHere are some hints on how to write clean and understandable code, a few of 28*49cdfc7eSAndroid Build Coastguard Workerthese points are further discussed below: 29*49cdfc7eSAndroid Build Coastguard Worker 30*49cdfc7eSAndroid Build Coastguard Worker* First of all *Keep things simple* 31*49cdfc7eSAndroid Build Coastguard Worker 32*49cdfc7eSAndroid Build Coastguard Worker* Keep function and variable names short but descriptive 33*49cdfc7eSAndroid Build Coastguard Worker 34*49cdfc7eSAndroid Build Coastguard Worker* Keep functions reasonably short and focused on a single task 35*49cdfc7eSAndroid Build Coastguard Worker 36*49cdfc7eSAndroid Build Coastguard Worker* Do not overcomment 37*49cdfc7eSAndroid Build Coastguard Worker 38*49cdfc7eSAndroid Build Coastguard Worker* Be consistent 39*49cdfc7eSAndroid Build Coastguard Worker 40*49cdfc7eSAndroid Build Coastguard Worker* Avoid deep nesting 41*49cdfc7eSAndroid Build Coastguard Worker 42*49cdfc7eSAndroid Build Coastguard Worker* DRY 43*49cdfc7eSAndroid Build Coastguard Worker 44*49cdfc7eSAndroid Build Coastguard Worker1.1 Keep things simple 45*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 46*49cdfc7eSAndroid Build Coastguard Worker 47*49cdfc7eSAndroid Build Coastguard WorkerFor all it's worth keep the testcases simple or better as simple as possible. 48*49cdfc7eSAndroid Build Coastguard Worker 49*49cdfc7eSAndroid Build Coastguard WorkerThe kernel and libc are tricky beasts and the complexity imposed by their 50*49cdfc7eSAndroid Build Coastguard Workerinterfaces is quite high. Concentrate on the interface you want to test and 51*49cdfc7eSAndroid Build Coastguard Workerfollow the UNIX philosophy. 52*49cdfc7eSAndroid Build Coastguard Worker 53*49cdfc7eSAndroid Build Coastguard WorkerIt's a good idea to make the test as self-contained as possible too, ideally 54*49cdfc7eSAndroid Build Coastguard Workertests should not depend on tools or libraries that are not widely available. 55*49cdfc7eSAndroid Build Coastguard Worker 56*49cdfc7eSAndroid Build Coastguard WorkerDo not reinvent the wheel! 57*49cdfc7eSAndroid Build Coastguard Worker 58*49cdfc7eSAndroid Build Coastguard Worker* Use LTP standard interface 59*49cdfc7eSAndroid Build Coastguard Worker 60*49cdfc7eSAndroid Build Coastguard Worker* Do not add custom PASS/FAIL reporting functions 61*49cdfc7eSAndroid Build Coastguard Worker 62*49cdfc7eSAndroid Build Coastguard Worker* Do not write Makefiles from scratch, use LTP build system instead 63*49cdfc7eSAndroid Build Coastguard Worker 64*49cdfc7eSAndroid Build Coastguard Worker* Etc. 65*49cdfc7eSAndroid Build Coastguard Worker 66*49cdfc7eSAndroid Build Coastguard Worker1.2 Keep functions and variable names short 67*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68*49cdfc7eSAndroid Build Coastguard Worker 69*49cdfc7eSAndroid Build Coastguard WorkerChoosing a good name for an API functions or even variables is a difficult 70*49cdfc7eSAndroid Build Coastguard Workertask do not underestimate it. 71*49cdfc7eSAndroid Build Coastguard Worker 72*49cdfc7eSAndroid Build Coastguard WorkerThere are a couple of customary names for different things that help people to 73*49cdfc7eSAndroid Build Coastguard Workerunderstand code, for example: 74*49cdfc7eSAndroid Build Coastguard Worker 75*49cdfc7eSAndroid Build Coastguard Worker* For loop variables are usually named with a single letter 'i', 'j', ... 76*49cdfc7eSAndroid Build Coastguard Worker 77*49cdfc7eSAndroid Build Coastguard Worker* File descriptors 'fd' or 'fd_foo'. 78*49cdfc7eSAndroid Build Coastguard Worker 79*49cdfc7eSAndroid Build Coastguard Worker* Number of bytes stored in file are usually named as 'size' or 'len' 80*49cdfc7eSAndroid Build Coastguard Worker 81*49cdfc7eSAndroid Build Coastguard Worker* Etc. 82*49cdfc7eSAndroid Build Coastguard Worker 83*49cdfc7eSAndroid Build Coastguard Worker1.3 Do not overcomment 84*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 85*49cdfc7eSAndroid Build Coastguard Worker 86*49cdfc7eSAndroid Build Coastguard WorkerComments can sometimes save you day but they can easily do more harm than 87*49cdfc7eSAndroid Build Coastguard Workergood. There has been several cases where comments and actual implementation 88*49cdfc7eSAndroid Build Coastguard Workerdrifted slowly apart which yielded into API misuses and hard to find bugs. 89*49cdfc7eSAndroid Build Coastguard WorkerRemember there is only one thing worse than no documentation, wrong 90*49cdfc7eSAndroid Build Coastguard Workerdocumentation. 91*49cdfc7eSAndroid Build Coastguard Worker 92*49cdfc7eSAndroid Build Coastguard WorkerIdeally everybody should write code that is obvious, which unfortunately isn't 93*49cdfc7eSAndroid Build Coastguard Workeralways possible. If there is a code that requires to be commented keep it 94*49cdfc7eSAndroid Build Coastguard Workershort and to the point. These comments should explain *why* and not *how* 95*49cdfc7eSAndroid Build Coastguard Workerthings are done. 96*49cdfc7eSAndroid Build Coastguard Worker 97*49cdfc7eSAndroid Build Coastguard WorkerNever ever comment the obvious. 98*49cdfc7eSAndroid Build Coastguard Worker 99*49cdfc7eSAndroid Build Coastguard WorkerIn case of LTP testcases it's customary to add an asciidoc formatted comment 100*49cdfc7eSAndroid Build Coastguard Workerparagraph with highlevel test description at the beginning of the file right 101*49cdfc7eSAndroid Build Coastguard Workerunder the GPL SPDX header. This helps other people to understand the overall 102*49cdfc7eSAndroid Build Coastguard Workergoal of the test before they dive into the technical details. It's also 103*49cdfc7eSAndroid Build Coastguard Workerexported into generated documentation hence it should mostly explain what is 104*49cdfc7eSAndroid Build Coastguard Workertested. 105*49cdfc7eSAndroid Build Coastguard Worker 106*49cdfc7eSAndroid Build Coastguard Worker1.4 DRY (Code duplication) 107*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~ 108*49cdfc7eSAndroid Build Coastguard Worker 109*49cdfc7eSAndroid Build Coastguard WorkerCopy & paste is a good servant but very poor master. If you are about to copy a 110*49cdfc7eSAndroid Build Coastguard Workerlarge part of the code from one testcase to another, think what would happen if 111*49cdfc7eSAndroid Build Coastguard Workeryou find bug in the code that has been copied all around the tree. What about 112*49cdfc7eSAndroid Build Coastguard Workermoving it to a library instead? 113*49cdfc7eSAndroid Build Coastguard Worker 114*49cdfc7eSAndroid Build Coastguard WorkerThe same goes for short but complicated parts, whenever you are about to copy & 115*49cdfc7eSAndroid Build Coastguard Workerpaste a syscall wrapper that packs arguments accordingly to machine 116*49cdfc7eSAndroid Build Coastguard Workerarchitecture or similarly complicated code, put it into a header instead. 117*49cdfc7eSAndroid Build Coastguard Worker 118*49cdfc7eSAndroid Build Coastguard Worker2 Coding style 119*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~ 120*49cdfc7eSAndroid Build Coastguard Worker 121*49cdfc7eSAndroid Build Coastguard Worker2.1 C coding style 122*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^ 123*49cdfc7eSAndroid Build Coastguard Worker 124*49cdfc7eSAndroid Build Coastguard WorkerLTP adopted Linux kernel coding style: 125*49cdfc7eSAndroid Build Coastguard Workerhttps://www.kernel.org/doc/html/latest/process/coding-style.html 126*49cdfc7eSAndroid Build Coastguard Worker 127*49cdfc7eSAndroid Build Coastguard WorkerIf you aren't familiar with its rules please read it, it's a well written 128*49cdfc7eSAndroid Build Coastguard Workerintroduction. 129*49cdfc7eSAndroid Build Coastguard Worker 130*49cdfc7eSAndroid Build Coastguard WorkerRun `make check` in the test's directory and/or use `make check-$TCID`, 131*49cdfc7eSAndroid Build Coastguard Workerit uses (among other checks) our vendored version of 132*49cdfc7eSAndroid Build Coastguard Workerhttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl[checkpatch.pl] 133*49cdfc7eSAndroid Build Coastguard Workerscript from kernel git tree. 134*49cdfc7eSAndroid Build Coastguard Worker 135*49cdfc7eSAndroid Build Coastguard WorkerNOTE: If `make check` does not report any problems, the code still may be wrong 136*49cdfc7eSAndroid Build Coastguard Worker as all tools used for checking only look for common mistakes. 137*49cdfc7eSAndroid Build Coastguard Worker 138*49cdfc7eSAndroid Build Coastguard Worker2.1.1 LTP-004: Test executable symbols are marked static 139*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 140*49cdfc7eSAndroid Build Coastguard Worker 141*49cdfc7eSAndroid Build Coastguard WorkerTest executables should not export symbols unnecessarily. This means 142*49cdfc7eSAndroid Build Coastguard Workerthat all top-level variables and functions should be marked with the 143*49cdfc7eSAndroid Build Coastguard Workerstatic keyword. The only visible symbols should be those included from 144*49cdfc7eSAndroid Build Coastguard Workershared object files. 145*49cdfc7eSAndroid Build Coastguard Worker 146*49cdfc7eSAndroid Build Coastguard Worker2.2 Shell coding style 147*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 148*49cdfc7eSAndroid Build Coastguard Worker 149*49cdfc7eSAndroid Build Coastguard WorkerWhen writing testcases in shell write in *portable shell* only, it's a good 150*49cdfc7eSAndroid Build Coastguard Workeridea to try to run the test using alternative shell (alternative to bash, for 151*49cdfc7eSAndroid Build Coastguard Workerexample dash) too. 152*49cdfc7eSAndroid Build Coastguard Worker 153*49cdfc7eSAndroid Build Coastguard Worker*Portable shell* means Shell Command Language as defined by POSIX with an 154*49cdfc7eSAndroid Build Coastguard Workerexception of few widely used extensions, namely 'local' keyword used inside of 155*49cdfc7eSAndroid Build Coastguard Workerfunctions and '-o' and '-a' test parameters (that are marked as obsolete in 156*49cdfc7eSAndroid Build Coastguard WorkerPOSIX). 157*49cdfc7eSAndroid Build Coastguard Worker 158*49cdfc7eSAndroid Build Coastguard WorkerYou can either try to run the testcases on Debian which has '/bin/sh' pointing 159*49cdfc7eSAndroid Build Coastguard Workerto 'dash' by default or install 'dash' on your favorite distribution and use 160*49cdfc7eSAndroid Build Coastguard Workerit to run the tests. If your distribution lacks 'dash' package you can always 161*49cdfc7eSAndroid Build Coastguard Workercompile it from http://gondor.apana.org.au/~herbert/dash/files/[source]. 162*49cdfc7eSAndroid Build Coastguard Worker 163*49cdfc7eSAndroid Build Coastguard WorkerRun `make check` in the test's directory and/or use `make check-$TCID.sh`, 164*49cdfc7eSAndroid Build Coastguard Workerit uses (among other checks) our vendored version of 165*49cdfc7eSAndroid Build Coastguard Workerhttps://salsa.debian.org/debian/devscripts/raw/master/scripts/checkbashisms.pl[checkbashism.pl] 166*49cdfc7eSAndroid Build Coastguard Workerfrom Debian, that is used to check for non-portable shell code. 167*49cdfc7eSAndroid Build Coastguard Worker 168*49cdfc7eSAndroid Build Coastguard WorkerNOTE: If `make check` does not report any problems, the code still may be wrong 169*49cdfc7eSAndroid Build Coastguard Worker as `checkbashisms.pl` used for checking only looks for common mistakes. 170*49cdfc7eSAndroid Build Coastguard Worker 171*49cdfc7eSAndroid Build Coastguard WorkerHere 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 175*49cdfc7eSAndroid Build Coastguard Worker* Use tabs for indentation 176*49cdfc7eSAndroid Build Coastguard Worker 177*49cdfc7eSAndroid Build Coastguard Worker* Keep things simple, avoid unnecessary subshells 178*49cdfc7eSAndroid Build Coastguard Worker 179*49cdfc7eSAndroid Build Coastguard Worker* Don't do confusing things (i.e. don't name your functions like common shell 180*49cdfc7eSAndroid Build Coastguard Worker commands, etc.) 181*49cdfc7eSAndroid Build Coastguard Worker 182*49cdfc7eSAndroid Build Coastguard Worker* Quote variables 183*49cdfc7eSAndroid Build Coastguard Worker 184*49cdfc7eSAndroid Build Coastguard Worker* Be consistent 185*49cdfc7eSAndroid Build Coastguard Worker 186*49cdfc7eSAndroid Build Coastguard Worker3 Backwards compatibility 187*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~ 188*49cdfc7eSAndroid Build Coastguard Worker 189*49cdfc7eSAndroid Build Coastguard WorkerLTP test should be as backward compatible as possible. Think of an enterprise 190*49cdfc7eSAndroid Build Coastguard Workerdistributions with long term support (more than five years since the initial 191*49cdfc7eSAndroid Build Coastguard Workerrelease) or of an embedded platform that needs to use several years old 192*49cdfc7eSAndroid Build Coastguard Workertoolchain supplied by the manufacturer. 193*49cdfc7eSAndroid Build Coastguard Worker 194*49cdfc7eSAndroid Build Coastguard WorkerTherefore LTP test for more current features should be able to cope with older 195*49cdfc7eSAndroid Build Coastguard Workersystems. It should at least compile fine and if it's not appropriate for the 196*49cdfc7eSAndroid Build Coastguard Workerconfiguration it should return 'TCONF'. 197*49cdfc7eSAndroid Build Coastguard Worker 198*49cdfc7eSAndroid Build Coastguard WorkerThere are several types of checks we use: 199*49cdfc7eSAndroid Build Coastguard Worker 200*49cdfc7eSAndroid Build Coastguard WorkerThe *configure script* is usually used to detect availability of a function 201*49cdfc7eSAndroid Build Coastguard Workerdeclarations in system headers. It's used to disable tests at compile time or 202*49cdfc7eSAndroid Build Coastguard Workerto enable fallback definitions. 203*49cdfc7eSAndroid Build Coastguard Worker 204*49cdfc7eSAndroid Build Coastguard WorkerChecking the *errno* value is another type of runtime check. Most of the 205*49cdfc7eSAndroid Build Coastguard Workersyscalls returns either 'EINVAL' or 'ENOSYS' when syscall was not implemented 206*49cdfc7eSAndroid Build Coastguard Workeror was disabled upon kernel compilation. 207*49cdfc7eSAndroid Build Coastguard Worker 208*49cdfc7eSAndroid Build Coastguard WorkerLTP has kernel version detection that can be used to disable tests at runtime, 209*49cdfc7eSAndroid Build Coastguard Workerunfortunately kernel version does not always corresponds to a well defined 210*49cdfc7eSAndroid Build Coastguard Workerfeature set as distributions tend to backport hundreds of patches while the 211*49cdfc7eSAndroid Build Coastguard Workerkernel version stays the same. Use with caution. 212*49cdfc7eSAndroid Build Coastguard Worker 213*49cdfc7eSAndroid Build Coastguard WorkerLately we added kernel '.config' parser, a test can define a boolean 214*49cdfc7eSAndroid Build Coastguard Workerexpression of kernel config variables that has to be satisfied in order for a 215*49cdfc7eSAndroid Build Coastguard Workertest to run. This is mostly used for kernel namespaces at the moment. 216*49cdfc7eSAndroid Build Coastguard Worker 217*49cdfc7eSAndroid Build Coastguard WorkerSometimes it also makes sense to define a few macros instead of creating 218*49cdfc7eSAndroid Build Coastguard Workerconfigure test. One example is Linux specific POSIX clock ids in 219*49cdfc7eSAndroid Build Coastguard Worker'include/lapi/posix_clocks.h'. 220*49cdfc7eSAndroid Build Coastguard Worker 221*49cdfc7eSAndroid Build Coastguard Worker3.1 Dealing with messed up legacy code 222*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 223*49cdfc7eSAndroid Build Coastguard Worker 224*49cdfc7eSAndroid Build Coastguard WorkerLTP still contains a lot of old and messy code and we are cleaning it up as 225*49cdfc7eSAndroid Build Coastguard Workerfast as we can but despite the decade of efforts there is still a lot. If you 226*49cdfc7eSAndroid Build Coastguard Workerstart modifying old or a messy testcase and your changes are more complicated 227*49cdfc7eSAndroid Build Coastguard Workerthan simple typo fixes you should convert the test into a new library first. 228*49cdfc7eSAndroid Build Coastguard Worker 229*49cdfc7eSAndroid Build Coastguard WorkerIt's also much easier to review the changes if you split them into a smaller 230*49cdfc7eSAndroid Build Coastguard Workerlogical groups. The same goes for moving files. If you need a rename or move 231*49cdfc7eSAndroid Build Coastguard Workerfile do it in a separate patch. 232*49cdfc7eSAndroid Build Coastguard Worker 233*49cdfc7eSAndroid Build Coastguard Worker4 License 234*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~ 235*49cdfc7eSAndroid Build Coastguard Worker 236*49cdfc7eSAndroid Build Coastguard WorkerCode contributed to LTP should be licensed under GPLv2+ (GNU GPL version 2 or 237*49cdfc7eSAndroid Build Coastguard Workerany later version). 238*49cdfc7eSAndroid Build Coastguard Worker 239*49cdfc7eSAndroid Build Coastguard WorkerUse `SPDX-License-Identifier: GPL-2.0-or-later` 240*49cdfc7eSAndroid Build Coastguard Worker 241*49cdfc7eSAndroid Build Coastguard Worker5 LTP Structure 242*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~ 243*49cdfc7eSAndroid Build Coastguard Worker 244*49cdfc7eSAndroid Build Coastguard WorkerThe structure of LTP is quite simple. Each test is a binary written either in 245*49cdfc7eSAndroid Build Coastguard Workerportable shell or C. The test gets a configuration via environment variables 246*49cdfc7eSAndroid Build Coastguard Workerand/or command line parameters, it prints additional information into the 247*49cdfc7eSAndroid Build Coastguard Workerstdout and reports overall success/failure via the exit value. 248*49cdfc7eSAndroid Build Coastguard Worker 249*49cdfc7eSAndroid Build Coastguard WorkerTests are generally placed under the 'testcases/' directory. Everything that 250*49cdfc7eSAndroid Build Coastguard Workeris a syscall or (slightly confusingly) libc syscall wrapper goes under 251*49cdfc7eSAndroid Build Coastguard Worker'testcases/kernel/syscalls/'. 252*49cdfc7eSAndroid Build Coastguard Worker 253*49cdfc7eSAndroid Build Coastguard WorkerThen there is 'testcases/open_posix_testsuite/' which is a well maintained fork 254*49cdfc7eSAndroid Build Coastguard Workerof the upstream project that has been dead since 2005 and also a number of 255*49cdfc7eSAndroid Build Coastguard Workerdirectories with tests for more specific features. 256*49cdfc7eSAndroid Build Coastguard Worker 257*49cdfc7eSAndroid Build Coastguard Worker5.1 Runtest Files 258*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^ 259*49cdfc7eSAndroid Build Coastguard Worker 260*49cdfc7eSAndroid Build Coastguard WorkerThe list of tests to be executed is stored in runtest files under the 261*49cdfc7eSAndroid Build Coastguard Worker'runtest/' directory. The default set of runtest files to be executed is 262*49cdfc7eSAndroid Build Coastguard Workerstored in 'scenario_groups/default'. When you add a test you should add 263*49cdfc7eSAndroid Build Coastguard Workercorresponding entries into some runtest file(s) as well. 264*49cdfc7eSAndroid Build Coastguard Worker 265*49cdfc7eSAndroid Build Coastguard WorkerEach line of runtest file contain one test. First item is the test name 266*49cdfc7eSAndroid Build Coastguard Worker('shell_test01', 'splice02'). All other items, separated by space will be 267*49cdfc7eSAndroid Build Coastguard Workerexecuted ('echo "SUCCESS" | shell_pipe01.sh', 'splice02 -s 20'). 268*49cdfc7eSAndroid Build Coastguard Worker 269*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 270*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 271*49cdfc7eSAndroid Build Coastguard Workershell_test01 echo "SUCCESS" | shell_pipe01.sh 272*49cdfc7eSAndroid Build Coastguard Workersplice02 splice02 -s 20 273*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 274*49cdfc7eSAndroid Build Coastguard Worker 275*49cdfc7eSAndroid Build Coastguard WorkerBlank lines and lines starting with a '#' (comments) are ignored. 276*49cdfc7eSAndroid Build Coastguard Worker 277*49cdfc7eSAndroid Build Coastguard WorkerFor syscall tests (these placed under 'testcases/kernel/syscalls/') use 278*49cdfc7eSAndroid Build Coastguard Worker'runtest/syscalls' file, for kernel related tests for memory management we 279*49cdfc7eSAndroid Build Coastguard Workerhave 'runtest/mm', etc. 280*49cdfc7eSAndroid Build Coastguard Worker 281*49cdfc7eSAndroid Build Coastguard WorkerIMPORTANT: The runtest files should have one entry per a test. Creating a 282*49cdfc7eSAndroid Build Coastguard Worker wrapper that runs all your tests and adding it as a single test 283*49cdfc7eSAndroid Build Coastguard Worker into runtest file is strongly discouraged. 284*49cdfc7eSAndroid Build Coastguard Worker 285*49cdfc7eSAndroid Build Coastguard Worker5.2 Datafiles 286*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^ 287*49cdfc7eSAndroid Build Coastguard Worker 288*49cdfc7eSAndroid Build Coastguard WorkerIf your test needs datafiles to work, these should be put into a subdirectory 289*49cdfc7eSAndroid Build Coastguard Workernamed 'datafiles' and installed into the 'testcases/data/$TCID' directory (to 290*49cdfc7eSAndroid Build Coastguard Workerdo that you have to add 'INSTALL_DIR := testcases/data/TCID' into the 291*49cdfc7eSAndroid Build Coastguard Worker'datafiles/Makefile'). 292*49cdfc7eSAndroid Build Coastguard Worker 293*49cdfc7eSAndroid Build Coastguard WorkerYou can obtain path to datafiles via $TST_DATAROOT provided by test.sh 294*49cdfc7eSAndroid Build Coastguard Worker'$TST_DATAROOT/...' 295*49cdfc7eSAndroid Build Coastguard Workeror via C function 'tst_dataroot()' provided by libltp: 296*49cdfc7eSAndroid Build Coastguard Worker 297*49cdfc7eSAndroid Build Coastguard Worker[source,c] 298*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 299*49cdfc7eSAndroid Build Coastguard Workerconst char *dataroot = tst_dataroot(); 300*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 301*49cdfc7eSAndroid Build Coastguard Worker 302*49cdfc7eSAndroid Build Coastguard WorkerDatafiles can also be accessed as '$LTPROOT/testcases/data/$TCID/...', 303*49cdfc7eSAndroid Build Coastguard Workerbut '$TST_DATAROOT' and 'tst_dataroot()' are preferred as these can be used 304*49cdfc7eSAndroid Build Coastguard Workerwhen running testcases directly in git tree as well as from install 305*49cdfc7eSAndroid Build Coastguard Workerlocation. 306*49cdfc7eSAndroid Build Coastguard Worker 307*49cdfc7eSAndroid Build Coastguard WorkerThe path is constructed according to these rules: 308*49cdfc7eSAndroid Build Coastguard Worker 309*49cdfc7eSAndroid Build Coastguard Worker1. if '$LTPROOT' is set, return '$LTPROOT/testcases/data/$TCID' 310*49cdfc7eSAndroid Build Coastguard Worker2. else if 'tst_tmpdir()' was called return '$STARTWD/datafiles' 311*49cdfc7eSAndroid Build Coastguard Worker (where '$STARTWD' is initial working directory as recorded by 'tst_tmpdir()') 312*49cdfc7eSAndroid Build Coastguard Worker3. else return '$CWD/datafiles' 313*49cdfc7eSAndroid Build Coastguard Worker 314*49cdfc7eSAndroid Build Coastguard WorkerSee 'testcases/commands/file/' for example. 315*49cdfc7eSAndroid Build Coastguard Worker 316*49cdfc7eSAndroid Build Coastguard Worker5.3 Subexecutables 317*49cdfc7eSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^ 318*49cdfc7eSAndroid Build Coastguard Worker 319*49cdfc7eSAndroid Build Coastguard WorkerIf your test needs to execute a binary, place it in the same directory as the 320*49cdfc7eSAndroid Build Coastguard Workertestcase and name the file starting with '${test_binary_name}_'. Once the 321*49cdfc7eSAndroid Build Coastguard Workertest is executed by the framework, the path to the directory with all LTP 322*49cdfc7eSAndroid Build Coastguard Workerbinaries is added to the '$PATH' and you can execute it just by its name. 323*49cdfc7eSAndroid Build Coastguard Worker 324*49cdfc7eSAndroid Build Coastguard WorkerTIP: If you need to execute such test from the LTP tree, you can add path to 325*49cdfc7eSAndroid Build Coastguard Worker current directory to '$PATH' manually with: 'PATH="$PATH:$PWD" ./foo01'. 326*49cdfc7eSAndroid Build Coastguard Worker 327*49cdfc7eSAndroid Build Coastguard Worker6 Test Contribution Checklist 328*49cdfc7eSAndroid Build Coastguard Worker------------------------------ 329*49cdfc7eSAndroid Build Coastguard Worker 330*49cdfc7eSAndroid Build Coastguard WorkerNOTE: See also 331*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Maintainer-Patch-Review-Checklist[Maintainer Patch Review Checklist]. 332*49cdfc7eSAndroid Build Coastguard Worker 333*49cdfc7eSAndroid Build Coastguard Worker1. Test compiles and runs fine (check with `-i 10` too) 334*49cdfc7eSAndroid Build Coastguard Worker2. `make check` does not emit any warnings for the test you are working on 335*49cdfc7eSAndroid Build Coastguard Worker (hint: run it in the test's directory and/or use `make check-$TCID`) 336*49cdfc7eSAndroid Build Coastguard Worker3. The runtest entries are in place 337*49cdfc7eSAndroid Build Coastguard Worker4. Test binaries are added into corresponding '.gitignore' files 338*49cdfc7eSAndroid Build Coastguard Worker5. Patches apply over the latest git 339*49cdfc7eSAndroid Build Coastguard Worker 340*49cdfc7eSAndroid Build Coastguard Worker6.1 About .gitignore files 341*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~ 342*49cdfc7eSAndroid Build Coastguard Worker 343*49cdfc7eSAndroid Build Coastguard WorkerThere are numerous '.gitignore' files in the LTP tree. Usually there is a 344*49cdfc7eSAndroid Build Coastguard Worker'.gitignore' file per a group of tests. The reason for this setup is simple. 345*49cdfc7eSAndroid Build Coastguard WorkerIt's easier to maintain a '.gitignore' file per directory with tests, rather 346*49cdfc7eSAndroid Build Coastguard Workerthan having single file in the project root directory. This way, we don't have 347*49cdfc7eSAndroid Build Coastguard Workerto update all the gitignore files when moving directories, and they get deleted 348*49cdfc7eSAndroid Build Coastguard Workerautomatically when a directory with tests is removed. 349*49cdfc7eSAndroid Build Coastguard Worker 350*49cdfc7eSAndroid Build Coastguard Worker7 Testing pre-release kernel features 351*49cdfc7eSAndroid Build Coastguard Worker------------------------------------- 352*49cdfc7eSAndroid Build Coastguard Worker 353*49cdfc7eSAndroid Build Coastguard WorkerTests for features not yet in a mainline kernel release are accepted. However 354*49cdfc7eSAndroid Build Coastguard Workerthey must only be added to the +staging+ runtest file. Once a feature is part 355*49cdfc7eSAndroid Build Coastguard Workerof the stable kernel ABI the associated test must be moved out of staging. 356*49cdfc7eSAndroid Build Coastguard Worker 357*49cdfc7eSAndroid Build Coastguard WorkerThis is primarily to help test kernel RCs by avoiding the need to download 358*49cdfc7eSAndroid Build Coastguard Workerseparate LTP patchsets. 359*49cdfc7eSAndroid Build Coastguard Worker 360*49cdfc7eSAndroid Build Coastguard Worker8 LTP C And Shell Test API Comparison 361*49cdfc7eSAndroid Build Coastguard Worker------------------------------------- 362*49cdfc7eSAndroid Build Coastguard Worker 363*49cdfc7eSAndroid Build Coastguard WorkerComparison of 364*49cdfc7eSAndroid Build Coastguard Workerhttps://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API] and 365*49cdfc7eSAndroid Build Coastguard Workerhttps://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API]. 366*49cdfc7eSAndroid Build Coastguard Worker 367*49cdfc7eSAndroid Build Coastguard Worker[options="header"] 368*49cdfc7eSAndroid Build Coastguard Worker|================================================================================ 369*49cdfc7eSAndroid Build Coastguard Worker| C API ('struct tst_test' members) | shell API ('$TST_*' environment variables) 370*49cdfc7eSAndroid Build Coastguard Worker| '.all_filesystems' | 'TST_ALL_FILESYSTEMS' 371*49cdfc7eSAndroid Build Coastguard Worker| '.bufs' | – 372*49cdfc7eSAndroid Build Coastguard Worker| '.caps' | – 373*49cdfc7eSAndroid Build Coastguard Worker| '.child_needs_reinit' | not applicable 374*49cdfc7eSAndroid Build Coastguard Worker| '.cleanup' | 'TST_CLEANUP' 375*49cdfc7eSAndroid Build Coastguard Worker| '.dev_extra_opts' | 'TST_DEV_EXTRA_OPTS' 376*49cdfc7eSAndroid Build Coastguard Worker| '.dev_fs_opts' | 'TST_DEV_FS_OPTS' 377*49cdfc7eSAndroid Build Coastguard Worker| '.dev_fs_type' | 'TST_FS_TYPE' 378*49cdfc7eSAndroid Build Coastguard Worker| '.dev_min_size' | not applicable 379*49cdfc7eSAndroid Build Coastguard Worker| '.format_device' | 'TST_FORMAT_DEVICE' 380*49cdfc7eSAndroid Build Coastguard Worker| '.max_runtime' | – 381*49cdfc7eSAndroid Build Coastguard Worker| '.min_cpus' | not applicable 382*49cdfc7eSAndroid Build Coastguard Worker| '.min_kver' | 'TST_MIN_KVER' 383*49cdfc7eSAndroid Build Coastguard Worker| '.min_mem_avail' | not applicable 384*49cdfc7eSAndroid Build Coastguard Worker| '.mnt_flags' | 'TST_MNT_PARAMS' 385*49cdfc7eSAndroid Build Coastguard Worker| '.min_swap_avail' | not applicable 386*49cdfc7eSAndroid Build Coastguard Worker| '.mntpoint', '.mnt_data' | 'TST_MNTPOINT' 387*49cdfc7eSAndroid Build Coastguard Worker| '.mount_device' | 'TST_MOUNT_DEVICE' 388*49cdfc7eSAndroid Build Coastguard Worker| '.needs_cgroup_ctrls' | – 389*49cdfc7eSAndroid Build Coastguard Worker| '.needs_checkpoints' | 'TST_NEEDS_CHECKPOINTS' 390*49cdfc7eSAndroid Build Coastguard Worker| '.needs_cmds' | 'TST_NEEDS_CMDS' 391*49cdfc7eSAndroid Build Coastguard Worker| '.needs_devfs' | – 392*49cdfc7eSAndroid Build Coastguard Worker| '.needs_device' | 'TST_NEEDS_DEVICE' 393*49cdfc7eSAndroid Build Coastguard Worker| '.needs_drivers' | 'TST_NEEDS_DRIVERS' 394*49cdfc7eSAndroid Build Coastguard Worker| '.needs_kconfigs' | 'TST_NEEDS_KCONFIGS' 395*49cdfc7eSAndroid Build Coastguard Worker| '.needs_overlay' | 396*49cdfc7eSAndroid Build Coastguard Worker| '.needs_rofs' | – 397*49cdfc7eSAndroid Build Coastguard Worker| '.needs_root' | 'TST_NEEDS_ROOT' 398*49cdfc7eSAndroid Build Coastguard Worker| '.needs_tmpdir' | 'TST_NEEDS_TMPDIR' 399*49cdfc7eSAndroid Build Coastguard Worker| '.options' | 'TST_PARSE_ARGS', 'TST_OPTS' 400*49cdfc7eSAndroid Build Coastguard Worker| '.resource_files' | – 401*49cdfc7eSAndroid Build Coastguard Worker| '.restore_wallclock' | not applicable 402*49cdfc7eSAndroid Build Coastguard Worker| '.sample' | – 403*49cdfc7eSAndroid Build Coastguard Worker| '.save_restore' | – 404*49cdfc7eSAndroid Build Coastguard Worker| '.scall' | not applicable 405*49cdfc7eSAndroid Build Coastguard Worker| '.setup' | 'TST_SETUP' 406*49cdfc7eSAndroid Build Coastguard Worker| '.skip_filesystems' | 'TST_SKIP_FILESYSTEMS' 407*49cdfc7eSAndroid Build Coastguard Worker| '.skip_in_compat' | – 408*49cdfc7eSAndroid Build Coastguard Worker| '.skip_in_lockdown' | 'TST_SKIP_IN_LOCKDOWN' 409*49cdfc7eSAndroid Build Coastguard Worker| '.skip_in_secureboot' | 'TST_SKIP_IN_SECUREBOOT' 410*49cdfc7eSAndroid Build Coastguard Worker| '.supported_archs' | not applicable 411*49cdfc7eSAndroid Build Coastguard Worker| '.tags' | – 412*49cdfc7eSAndroid Build Coastguard Worker| '.taint_check' | – 413*49cdfc7eSAndroid Build Coastguard Worker| '.tcnt' | 'TST_CNT' 414*49cdfc7eSAndroid Build Coastguard Worker| '.tconf_msg' | not applicable 415*49cdfc7eSAndroid Build Coastguard Worker| '.test', '.test_all' | 'TST_TESTFUNC' 416*49cdfc7eSAndroid Build Coastguard Worker| '.test_variants' | – 417*49cdfc7eSAndroid Build Coastguard Worker| '.timeout' | 'TST_TIMEOUT' 418*49cdfc7eSAndroid Build Coastguard Worker| '.tst_hugepage' | not applicable 419*49cdfc7eSAndroid Build Coastguard Worker| '.ulimit' | not applicable 420*49cdfc7eSAndroid Build Coastguard Worker| not applicable | 'TST_NEEDS_KCONFIGS_IFS' 421*49cdfc7eSAndroid Build Coastguard Worker| not applicable | 'TST_NEEDS_MODULE' 422*49cdfc7eSAndroid Build Coastguard Worker| not applicable | 'TST_POS_ARGS' 423*49cdfc7eSAndroid Build Coastguard Worker| not applicable | 'TST_USAGE' 424*49cdfc7eSAndroid Build Coastguard Worker|================================================================================ 425*49cdfc7eSAndroid Build Coastguard Worker 426*49cdfc7eSAndroid Build Coastguard Worker[options="header"] 427*49cdfc7eSAndroid Build Coastguard Worker|================================================================================ 428*49cdfc7eSAndroid Build Coastguard Worker| C API (other structs) | shell API ('$TST_*' environment variables) 429*49cdfc7eSAndroid Build Coastguard Worker| 'struct tst_device' | 'TST_DEVICE' 430*49cdfc7eSAndroid Build Coastguard Worker|================================================================================ 431