1*49cdfc7eSAndroid Build Coastguard WorkerLTP Shell Test API 2*49cdfc7eSAndroid Build Coastguard Worker================== 3*49cdfc7eSAndroid Build Coastguard Worker 4*49cdfc7eSAndroid Build Coastguard WorkerNOTE: See also 5*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines], 6*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API]. 7*49cdfc7eSAndroid Build Coastguard Worker 8*49cdfc7eSAndroid Build Coastguard Worker1 Writing a testcase in shell 9*49cdfc7eSAndroid Build Coastguard Worker----------------------------- 10*49cdfc7eSAndroid Build Coastguard Worker 11*49cdfc7eSAndroid Build Coastguard WorkerLTP supports testcases to be written in a portable shell too. 12*49cdfc7eSAndroid Build Coastguard Worker 13*49cdfc7eSAndroid Build Coastguard WorkerThere is a shell library modeled closely to the C interface at 14*49cdfc7eSAndroid Build Coastguard Worker'testcases/lib/tst_test.sh'. 15*49cdfc7eSAndroid Build Coastguard Worker 16*49cdfc7eSAndroid Build Coastguard WorkerWARNING: All identifiers starting with 'TST_' or 'tst_' are reserved for the 17*49cdfc7eSAndroid Build Coastguard Worker test library. 18*49cdfc7eSAndroid Build Coastguard Worker 19*49cdfc7eSAndroid Build Coastguard Worker1.1 Basic test interface 20*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~ 21*49cdfc7eSAndroid Build Coastguard Worker 22*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 23*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 24*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 25*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 26*49cdfc7eSAndroid Build Coastguard Worker# This is a basic test for true shell builtin 27*49cdfc7eSAndroid Build Coastguard Worker 28*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 29*49cdfc7eSAndroid Build Coastguard Worker 30*49cdfc7eSAndroid Build Coastguard Workerdo_test() 31*49cdfc7eSAndroid Build Coastguard Worker{ 32*49cdfc7eSAndroid Build Coastguard Worker true 33*49cdfc7eSAndroid Build Coastguard Worker ret=$? 34*49cdfc7eSAndroid Build Coastguard Worker 35*49cdfc7eSAndroid Build Coastguard Worker if [ $ret -eq 0 ]; then 36*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "true returned 0" 37*49cdfc7eSAndroid Build Coastguard Worker else 38*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "true returned $ret" 39*49cdfc7eSAndroid Build Coastguard Worker fi 40*49cdfc7eSAndroid Build Coastguard Worker} 41*49cdfc7eSAndroid Build Coastguard Worker 42*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 43*49cdfc7eSAndroid Build Coastguard Workertst_run 44*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 45*49cdfc7eSAndroid Build Coastguard Worker 46*49cdfc7eSAndroid Build Coastguard WorkerTIP: To execute this test the 'tst_test.sh' library must be in '$PATH'. If you 47*49cdfc7eSAndroid Build Coastguard Worker are executing the test from a git checkout you can run it as 48*49cdfc7eSAndroid Build Coastguard Worker 'PATH="$PATH:../../lib" ./foo01.sh' 49*49cdfc7eSAndroid Build Coastguard Worker 50*49cdfc7eSAndroid Build Coastguard WorkerThe shell library expects test setup, cleanup and the test function executing 51*49cdfc7eSAndroid Build Coastguard Workerthe test in the '$TST_SETUP', '$TST_CLEANUP' and '$TST_TESTFUNC' variables. 52*49cdfc7eSAndroid Build Coastguard Worker 53*49cdfc7eSAndroid Build Coastguard WorkerBoth '$TST_SETUP' and '$TST_CLEANUP' are optional. 54*49cdfc7eSAndroid Build Coastguard Worker 55*49cdfc7eSAndroid Build Coastguard WorkerThe '$TST_TESTFUNC' may be called several times if more than one test 56*49cdfc7eSAndroid Build Coastguard Workeriteration was requested by passing right command line options to the test. 57*49cdfc7eSAndroid Build Coastguard Worker 58*49cdfc7eSAndroid Build Coastguard WorkerThe '$TST_CLEANUP' may be called even in the middle of the setup and must be 59*49cdfc7eSAndroid Build Coastguard Workerable to clean up correctly even in this situation. The easiest solution for 60*49cdfc7eSAndroid Build Coastguard Workerthis is to keep track of what was initialized and act accordingly in the 61*49cdfc7eSAndroid Build Coastguard Workercleanup. 62*49cdfc7eSAndroid Build Coastguard Worker 63*49cdfc7eSAndroid Build Coastguard WorkerWARNING: Similar to the C library, calling 'tst_brk' in the $TST_CLEANUP does 64*49cdfc7eSAndroid Build Coastguard Worker not exit the test and 'TBROK' is converted to 'TWARN'. 65*49cdfc7eSAndroid Build Coastguard Worker 66*49cdfc7eSAndroid Build Coastguard WorkerNotice also the 'tst_run' shell API function called at the end of the test that 67*49cdfc7eSAndroid Build Coastguard Workeractually starts the test. 68*49cdfc7eSAndroid Build Coastguard Worker 69*49cdfc7eSAndroid Build Coastguard WorkerWARNING: cleanup function is called only after 'tst_run' has been started. 70*49cdfc7eSAndroid Build Coastguard WorkerCalling 'tst_brk' in shell libraries, e.g. 'tst_test.sh' or 'tst_net.sh' does 71*49cdfc7eSAndroid Build Coastguard Workernot trigger calling it. 72*49cdfc7eSAndroid Build Coastguard Worker 73*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 74*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 75*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 76*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 77*49cdfc7eSAndroid Build Coastguard Worker# Example test with tests in separate functions 78*49cdfc7eSAndroid Build Coastguard Worker 79*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=test 80*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=2 81*49cdfc7eSAndroid Build Coastguard Worker 82*49cdfc7eSAndroid Build Coastguard Workertest1() 83*49cdfc7eSAndroid Build Coastguard Worker{ 84*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "Test $1 passed" 85*49cdfc7eSAndroid Build Coastguard Worker} 86*49cdfc7eSAndroid Build Coastguard Worker 87*49cdfc7eSAndroid Build Coastguard Workertest2() 88*49cdfc7eSAndroid Build Coastguard Worker{ 89*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "Test $1 passed" 90*49cdfc7eSAndroid Build Coastguard Worker} 91*49cdfc7eSAndroid Build Coastguard Worker 92*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 93*49cdfc7eSAndroid Build Coastguard Workertst_run 94*49cdfc7eSAndroid Build Coastguard Worker# output: 95*49cdfc7eSAndroid Build Coastguard Worker# foo 1 TPASS: Test 1 passed 96*49cdfc7eSAndroid Build Coastguard Worker# foo 2 TPASS: Test 2 passed 97*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 98*49cdfc7eSAndroid Build Coastguard Worker 99*49cdfc7eSAndroid Build Coastguard WorkerIf '$TST_CNT' is set, the test library looks if there are functions named 100*49cdfc7eSAndroid Build Coastguard Worker'$\{TST_TESTFUNC\}1', ..., '$\{TST_TESTFUNC\}$\{TST_CNT\}' and if these are 101*49cdfc7eSAndroid Build Coastguard Workerfound they are executed one by one. The test number is passed to it in the '$1'. 102*49cdfc7eSAndroid Build Coastguard Worker 103*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 104*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 105*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 106*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 107*49cdfc7eSAndroid Build Coastguard Worker# Example test with tests in a single function 108*49cdfc7eSAndroid Build Coastguard Worker 109*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 110*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=2 111*49cdfc7eSAndroid Build Coastguard Worker 112*49cdfc7eSAndroid Build Coastguard Workerdo_test() 113*49cdfc7eSAndroid Build Coastguard Worker{ 114*49cdfc7eSAndroid Build Coastguard Worker case $1 in 115*49cdfc7eSAndroid Build Coastguard Worker 1) tst_res TPASS "Test $1 passed";; 116*49cdfc7eSAndroid Build Coastguard Worker 2) tst_res TPASS "Test $1 passed";; 117*49cdfc7eSAndroid Build Coastguard Worker esac 118*49cdfc7eSAndroid Build Coastguard Worker} 119*49cdfc7eSAndroid Build Coastguard Worker 120*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 121*49cdfc7eSAndroid Build Coastguard Workertst_run 122*49cdfc7eSAndroid Build Coastguard Worker# output: 123*49cdfc7eSAndroid Build Coastguard Worker# foo 1 TPASS: Test 1 passed 124*49cdfc7eSAndroid Build Coastguard Worker# foo 2 TPASS: Test 2 passed 125*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 126*49cdfc7eSAndroid Build Coastguard Worker 127*49cdfc7eSAndroid Build Coastguard WorkerOtherwise, if '$TST_CNT' is set but there is no '$\{TST_TESTFUNC\}1', etc., 128*49cdfc7eSAndroid Build Coastguard Workerthe '$TST_TESTFUNC' is executed '$TST_CNT' times and the test number is passed 129*49cdfc7eSAndroid Build Coastguard Workerto it in the '$1'. 130*49cdfc7eSAndroid Build Coastguard Worker 131*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 132*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 133*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 134*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 135*49cdfc7eSAndroid Build Coastguard Worker# Example test with tests in a single function, using $TST_TEST_DATA and 136*49cdfc7eSAndroid Build Coastguard Worker# $TST_TEST_DATA_IFS 137*49cdfc7eSAndroid Build Coastguard Worker 138*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 139*49cdfc7eSAndroid Build Coastguard WorkerTST_TEST_DATA="foo:bar:d dd" 140*49cdfc7eSAndroid Build Coastguard WorkerTST_TEST_DATA_IFS=":" 141*49cdfc7eSAndroid Build Coastguard Worker 142*49cdfc7eSAndroid Build Coastguard Workerdo_test() 143*49cdfc7eSAndroid Build Coastguard Worker{ 144*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "Test $1 passed with data '$2'" 145*49cdfc7eSAndroid Build Coastguard Worker} 146*49cdfc7eSAndroid Build Coastguard Worker 147*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 148*49cdfc7eSAndroid Build Coastguard Workertst_run 149*49cdfc7eSAndroid Build Coastguard Worker# output: 150*49cdfc7eSAndroid Build Coastguard Worker# foo 1 TPASS: Test 1 passed with data 'foo' 151*49cdfc7eSAndroid Build Coastguard Worker# foo 2 TPASS: Test 1 passed with data 'bar' 152*49cdfc7eSAndroid Build Coastguard Worker# foo 3 TPASS: Test 1 passed with data 'd dd' 153*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 154*49cdfc7eSAndroid Build Coastguard Worker 155*49cdfc7eSAndroid Build Coastguard WorkerIt's possible to pass data for function with '$TST_TEST_DATA'. Optional 156*49cdfc7eSAndroid Build Coastguard Worker'$TST_TEST_DATA_IFS' is used for splitting, default value is space. 157*49cdfc7eSAndroid Build Coastguard Worker 158*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 159*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 160*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 161*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 162*49cdfc7eSAndroid Build Coastguard Worker# Example test with tests in a single function, using $TST_TEST_DATA and $TST_CNT 163*49cdfc7eSAndroid Build Coastguard Worker 164*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 165*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=2 166*49cdfc7eSAndroid Build Coastguard WorkerTST_TEST_DATA="foo bar" 167*49cdfc7eSAndroid Build Coastguard Worker 168*49cdfc7eSAndroid Build Coastguard Workerdo_test() 169*49cdfc7eSAndroid Build Coastguard Worker{ 170*49cdfc7eSAndroid Build Coastguard Worker case $1 in 171*49cdfc7eSAndroid Build Coastguard Worker 1) tst_res TPASS "Test $1 passed with data '$2'";; 172*49cdfc7eSAndroid Build Coastguard Worker 2) tst_res TPASS "Test $1 passed with data '$2'";; 173*49cdfc7eSAndroid Build Coastguard Worker esac 174*49cdfc7eSAndroid Build Coastguard Worker} 175*49cdfc7eSAndroid Build Coastguard Worker 176*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 177*49cdfc7eSAndroid Build Coastguard Workertst_run 178*49cdfc7eSAndroid Build Coastguard Worker# output: 179*49cdfc7eSAndroid Build Coastguard Worker# foo 1 TPASS: Test 1 passed with data 'foo' 180*49cdfc7eSAndroid Build Coastguard Worker# foo 2 TPASS: Test 2 passed with data 'foo' 181*49cdfc7eSAndroid Build Coastguard Worker# foo 3 TPASS: Test 1 passed with data 'bar' 182*49cdfc7eSAndroid Build Coastguard Worker# foo 4 TPASS: Test 2 passed with data 'bar' 183*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 184*49cdfc7eSAndroid Build Coastguard Worker 185*49cdfc7eSAndroid Build Coastguard Worker'$TST_TEST_DATA' can be used with '$TST_CNT'. If '$TST_TEST_DATA_IFS' not specified, 186*49cdfc7eSAndroid Build Coastguard Workerspace as default value is used. Of course, it's possible to use separate functions. 187*49cdfc7eSAndroid Build Coastguard Worker 188*49cdfc7eSAndroid Build Coastguard Worker1.2 Library environment variables and functions for shell 189*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 190*49cdfc7eSAndroid Build Coastguard Worker 191*49cdfc7eSAndroid Build Coastguard WorkerSimilarily to the C library various checks and preparations can be requested 192*49cdfc7eSAndroid Build Coastguard Workersimply by setting right '$TST_FOO'. 193*49cdfc7eSAndroid Build Coastguard Worker 194*49cdfc7eSAndroid Build Coastguard Worker[options="header"] 195*49cdfc7eSAndroid Build Coastguard Worker|============================================================================= 196*49cdfc7eSAndroid Build Coastguard Worker| Variable name | Action done 197*49cdfc7eSAndroid Build Coastguard Worker| 'TST_ALL_FILESYSTEMS' | Testing on all available filesystems 198*49cdfc7eSAndroid Build Coastguard Worker ('tst_test.all_filesystems' equivalent). 199*49cdfc7eSAndroid Build Coastguard Worker When 'TST_SKIP_FILESYSTEMS' any listed filesystem is not 200*49cdfc7eSAndroid Build Coastguard Worker included in the resulting list of supported filesystems. 201*49cdfc7eSAndroid Build Coastguard Worker| 'TST_DEV_EXTRA_OPTS' | Pass extra 'mkfs' options _after_ device name, 202*49cdfc7eSAndroid Build Coastguard Worker to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'. 203*49cdfc7eSAndroid Build Coastguard Worker| 'TST_DEV_FS_OPTS' | Pass 'mkfs' options _before_ the device name, 204*49cdfc7eSAndroid Build Coastguard Worker to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'. 205*49cdfc7eSAndroid Build Coastguard Worker| 'TST_FORMAT_DEVICE' | Format a block device with a filesystem, see 206*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]. 207*49cdfc7eSAndroid Build Coastguard Worker See also 'TST_DEV_EXTRA_OPTS', 'TST_DEV_FS_OPTS', 'TST_FS_TYPE'. 208*49cdfc7eSAndroid Build Coastguard Worker Implies 'TST_NEEDS_DEVICE=1' (no need to set it). 209*49cdfc7eSAndroid Build Coastguard Worker| 'TST_DEVICE' | Block device name for 'tst_mount' and 'tst_mkfs', see 210*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]. 211*49cdfc7eSAndroid Build Coastguard Worker| 'TST_FS_TYPE' | Override the default filesystem to be used. Also 212*49cdfc7eSAndroid Build Coastguard Worker contains currently used filesystem during looping 213*49cdfc7eSAndroid Build Coastguard Worker filesystems in 'TST_ALL_FILESYSTEMS=1' 214*49cdfc7eSAndroid Build Coastguard Worker ('tst_device->fs_type' equivalent). 215*49cdfc7eSAndroid Build Coastguard Worker| 'TST_MNTPOINT' | Holds path to mountpoint used in 'tst_mount', see 216*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]. 217*49cdfc7eSAndroid Build Coastguard Worker| 'TST_MNT_PARAMS' | Extra mount params for 'tst_mount', see 218*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]. 219*49cdfc7eSAndroid Build Coastguard Worker| 'TST_MOUNT_DEVICE' | Mount device, see 220*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#mounting-and-unmounting-filesystems[Mounting and unmounting filesystems]. 221*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_ROOT' | Exit the test with 'TCONF' unless executed under root. 222*49cdfc7eSAndroid Build Coastguard Worker Alternatively the 'tst_require_root' command can be used. 223*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it. 224*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing 225*49cdfc7eSAndroid Build Coastguard Worker device is stored in '$TST_DEVICE' variable. 226*49cdfc7eSAndroid Build Coastguard Worker The option implies 'TST_NEEDS_TMPDIR'. 227*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_CMDS' | String with command names that has to be present for 228*49cdfc7eSAndroid Build Coastguard Worker the test (see below). 229*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below). 230*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_DRIVERS' | Checks kernel drivers support for the test. 231*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_KCONFIGS' | Checks kernel kconfigs support for the test (see below). 232*49cdfc7eSAndroid Build Coastguard Worker| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable, 233*49cdfc7eSAndroid Build Coastguard Worker default value is comma, it only supports single character. 234*49cdfc7eSAndroid Build Coastguard Worker| 'TST_SKIP_FILESYSTEMS' | Comma separated list of filesystems on which test will be skipped 235*49cdfc7eSAndroid Build Coastguard Worker (tst_test.skip_filesystems equivalent). 236*49cdfc7eSAndroid Build Coastguard Worker| 'TST_TIMEOUT' | Maximum timeout set for the test in sec. Must be int >= 1, 237*49cdfc7eSAndroid Build Coastguard Worker or -1 (special value to disable timeout), default is 300. 238*49cdfc7eSAndroid Build Coastguard Worker Variable is meant be set in tests, not by user. 239*49cdfc7eSAndroid Build Coastguard Worker It's an equivalent of `tst_test.timeout` in C, can be set 240*49cdfc7eSAndroid Build Coastguard Worker via 'tst_set_timeout(timeout)' after test has started. 241*49cdfc7eSAndroid Build Coastguard Worker|============================================================================= 242*49cdfc7eSAndroid Build Coastguard Worker 243*49cdfc7eSAndroid Build Coastguard Worker[options="header"] 244*49cdfc7eSAndroid Build Coastguard Worker|============================================================================= 245*49cdfc7eSAndroid Build Coastguard Worker| Function name | Action done 246*49cdfc7eSAndroid Build Coastguard Worker| 'tst_set_timeout(timeout)' | Maximum timeout set for the test in sec. 247*49cdfc7eSAndroid Build Coastguard Worker See 'TST_TIMEOUT' variable. 248*49cdfc7eSAndroid Build Coastguard Worker|============================================================================= 249*49cdfc7eSAndroid Build Coastguard Worker 250*49cdfc7eSAndroid Build Coastguard WorkerNOTE: Network tests (see testcases/network/README.md) use additional variables 251*49cdfc7eSAndroid Build Coastguard Workerand functions in 'tst_net.sh'. 252*49cdfc7eSAndroid Build Coastguard Worker 253*49cdfc7eSAndroid Build Coastguard WorkerChecking for presence of commands 254*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++++++++++++ 255*49cdfc7eSAndroid Build Coastguard Worker 256*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 257*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 258*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 259*49cdfc7eSAndroid Build Coastguard Worker 260*49cdfc7eSAndroid Build Coastguard Worker... 261*49cdfc7eSAndroid Build Coastguard Worker 262*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="modinfo modprobe" 263*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 264*49cdfc7eSAndroid Build Coastguard Worker 265*49cdfc7eSAndroid Build Coastguard Worker... 266*49cdfc7eSAndroid Build Coastguard Worker 267*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 268*49cdfc7eSAndroid Build Coastguard Worker 269*49cdfc7eSAndroid Build Coastguard WorkerSetting '$TST_NEEDS_CMDS' to a string listing required commands will check for 270*49cdfc7eSAndroid Build Coastguard Workerexistence each of them and exits the test with 'TCONF' on first missing. 271*49cdfc7eSAndroid Build Coastguard Worker 272*49cdfc7eSAndroid Build Coastguard WorkerAlternatively the 'tst_require_cmds()' function can be used to do the same on 273*49cdfc7eSAndroid Build Coastguard Workerruntime, since sometimes we need to the check at runtime too. 274*49cdfc7eSAndroid Build Coastguard Worker 275*49cdfc7eSAndroid Build Coastguard Worker'tst_check_cmds()' can be used for requirements just for a particular test 276*49cdfc7eSAndroid Build Coastguard Workeras it doesn't exit (it issues 'tst_res TCONF'). Expected usage is: 277*49cdfc7eSAndroid Build Coastguard Worker 278*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 279*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 280*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 281*49cdfc7eSAndroid Build Coastguard Worker 282*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 283*49cdfc7eSAndroid Build Coastguard Worker 284*49cdfc7eSAndroid Build Coastguard Workerdo_test() 285*49cdfc7eSAndroid Build Coastguard Worker{ 286*49cdfc7eSAndroid Build Coastguard Worker tst_check_cmds cmd || return 287*49cdfc7eSAndroid Build Coastguard Worker cmd --foo 288*49cdfc7eSAndroid Build Coastguard Worker ... 289*49cdfc7eSAndroid Build Coastguard Worker} 290*49cdfc7eSAndroid Build Coastguard Worker 291*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 292*49cdfc7eSAndroid Build Coastguard Workertst_run 293*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 294*49cdfc7eSAndroid Build Coastguard Worker 295*49cdfc7eSAndroid Build Coastguard WorkerLocating kernel modules 296*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++ 297*49cdfc7eSAndroid Build Coastguard Worker 298*49cdfc7eSAndroid Build Coastguard WorkerThe LTP build system can build kernel modules as well, setting 299*49cdfc7eSAndroid Build Coastguard Worker'$TST_NEEDS_MODULE' to module name will cause the library to look for the 300*49cdfc7eSAndroid Build Coastguard Workermodule in a few possible paths. 301*49cdfc7eSAndroid Build Coastguard Worker 302*49cdfc7eSAndroid Build Coastguard WorkerIf module was found the path to it will be stored into '$TST_MODPATH' 303*49cdfc7eSAndroid Build Coastguard Workervariable, if module wasn't found the test will exit with 'TCONF'. 304*49cdfc7eSAndroid Build Coastguard Worker 305*49cdfc7eSAndroid Build Coastguard WorkerAlternatively the 'tst_require_module()' function can be used to do the same 306*49cdfc7eSAndroid Build Coastguard Workerat runtime. 307*49cdfc7eSAndroid Build Coastguard Worker 308*49cdfc7eSAndroid Build Coastguard Worker1.3 Optional command line parameters 309*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 310*49cdfc7eSAndroid Build Coastguard Worker 311*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 312*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 313*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 314*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 315*49cdfc7eSAndroid Build Coastguard Worker# Optional test command line parameters 316*49cdfc7eSAndroid Build Coastguard Worker 317*49cdfc7eSAndroid Build Coastguard WorkerTST_OPTS="af:" 318*49cdfc7eSAndroid Build Coastguard WorkerTST_USAGE=usage 319*49cdfc7eSAndroid Build Coastguard WorkerTST_PARSE_ARGS=parse_args 320*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 321*49cdfc7eSAndroid Build Coastguard Worker 322*49cdfc7eSAndroid Build Coastguard WorkerALTERNATIVE=0 323*49cdfc7eSAndroid Build Coastguard WorkerMODE="foo" 324*49cdfc7eSAndroid Build Coastguard Worker 325*49cdfc7eSAndroid Build Coastguard Workerusage() 326*49cdfc7eSAndroid Build Coastguard Worker{ 327*49cdfc7eSAndroid Build Coastguard Worker cat << EOF 328*49cdfc7eSAndroid Build Coastguard Workerusage: $0 [-a] [-f <foo|bar>] 329*49cdfc7eSAndroid Build Coastguard Worker 330*49cdfc7eSAndroid Build Coastguard WorkerOPTIONS 331*49cdfc7eSAndroid Build Coastguard Worker-a Enable support for alternative foo 332*49cdfc7eSAndroid Build Coastguard Worker-f Specify foo or bar mode 333*49cdfc7eSAndroid Build Coastguard WorkerEOF 334*49cdfc7eSAndroid Build Coastguard Worker} 335*49cdfc7eSAndroid Build Coastguard Worker 336*49cdfc7eSAndroid Build Coastguard Workerparse_args() 337*49cdfc7eSAndroid Build Coastguard Worker{ 338*49cdfc7eSAndroid Build Coastguard Worker case $1 in 339*49cdfc7eSAndroid Build Coastguard Worker a) ALTERNATIVE=1;; 340*49cdfc7eSAndroid Build Coastguard Worker f) MODE="$2";; 341*49cdfc7eSAndroid Build Coastguard Worker esac 342*49cdfc7eSAndroid Build Coastguard Worker} 343*49cdfc7eSAndroid Build Coastguard Worker 344*49cdfc7eSAndroid Build Coastguard Workerdo_test() 345*49cdfc7eSAndroid Build Coastguard Worker{ 346*49cdfc7eSAndroid Build Coastguard Worker ... 347*49cdfc7eSAndroid Build Coastguard Worker} 348*49cdfc7eSAndroid Build Coastguard Worker 349*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 350*49cdfc7eSAndroid Build Coastguard Workertst_run 351*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 352*49cdfc7eSAndroid Build Coastguard Worker 353*49cdfc7eSAndroid Build Coastguard WorkerThe 'getopts' string for optional parameters is passed in the '$TST_OPTS' 354*49cdfc7eSAndroid Build Coastguard Workervariable. There are a few default parameters that cannot be used by a test, 355*49cdfc7eSAndroid Build Coastguard Workerthese can be listed with passing help '-h' option to any test. 356*49cdfc7eSAndroid Build Coastguard Worker 357*49cdfc7eSAndroid Build Coastguard WorkerThe function that prints the usage is passed in '$TST_USAGE', the help for 358*49cdfc7eSAndroid Build Coastguard Workerthe options implemented in the library is appended when usage is printed. 359*49cdfc7eSAndroid Build Coastguard Worker 360*49cdfc7eSAndroid Build Coastguard WorkerLastly the function '$PARSE_ARGS' is called with the option name in the '$1' 361*49cdfc7eSAndroid Build Coastguard Workerand, if option has argument, its value in the '$2'. 362*49cdfc7eSAndroid Build Coastguard Worker 363*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 364*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 365*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 366*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 367*49cdfc7eSAndroid Build Coastguard Worker# Optional test positional parameters 368*49cdfc7eSAndroid Build Coastguard Worker 369*49cdfc7eSAndroid Build Coastguard WorkerTST_POS_ARGS=3 370*49cdfc7eSAndroid Build Coastguard WorkerTST_USAGE=usage 371*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 372*49cdfc7eSAndroid Build Coastguard Worker 373*49cdfc7eSAndroid Build Coastguard Workerusage() 374*49cdfc7eSAndroid Build Coastguard Worker{ 375*49cdfc7eSAndroid Build Coastguard Worker cat << EOF 376*49cdfc7eSAndroid Build Coastguard Workerusage: $0 [min] [max] [size] 377*49cdfc7eSAndroid Build Coastguard Worker 378*49cdfc7eSAndroid Build Coastguard WorkerEOF 379*49cdfc7eSAndroid Build Coastguard Worker} 380*49cdfc7eSAndroid Build Coastguard Worker 381*49cdfc7eSAndroid Build Coastguard Workermin="$1" 382*49cdfc7eSAndroid Build Coastguard Workermax="$2" 383*49cdfc7eSAndroid Build Coastguard Workersize="$3" 384*49cdfc7eSAndroid Build Coastguard Worker 385*49cdfc7eSAndroid Build Coastguard Workerdo_test() 386*49cdfc7eSAndroid Build Coastguard Worker{ 387*49cdfc7eSAndroid Build Coastguard Worker ... 388*49cdfc7eSAndroid Build Coastguard Worker} 389*49cdfc7eSAndroid Build Coastguard Worker 390*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 391*49cdfc7eSAndroid Build Coastguard Workertst_run 392*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 393*49cdfc7eSAndroid Build Coastguard Worker 394*49cdfc7eSAndroid Build Coastguard WorkerYou can also request a number of positional parameters by setting the 395*49cdfc7eSAndroid Build Coastguard Worker'$TST_POS_ARGS' variable. If you do, these will be available as they were 396*49cdfc7eSAndroid Build Coastguard Workerpassed directly to the script in '$1', '$2', ..., '$n'. 397*49cdfc7eSAndroid Build Coastguard Worker 398*49cdfc7eSAndroid Build Coastguard Worker1.4 Useful library functions 399*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 400*49cdfc7eSAndroid Build Coastguard Worker 401*49cdfc7eSAndroid Build Coastguard WorkerRetrieving configuration variables 402*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++++++++++++++++++ 403*49cdfc7eSAndroid Build Coastguard Worker 404*49cdfc7eSAndroid Build Coastguard WorkerYou may need to retrieve configuration values such as PAGESIZE, there is 405*49cdfc7eSAndroid Build Coastguard Worker'getconf' but as some system may not have it, you are advised to use 406*49cdfc7eSAndroid Build Coastguard Worker'tst_getconf' instead. Note that it implements subset of 'getconf' 407*49cdfc7eSAndroid Build Coastguard Workersystem variables used by the testcases only. 408*49cdfc7eSAndroid Build Coastguard Worker 409*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 410*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 411*49cdfc7eSAndroid Build Coastguard Worker# retrieve PAGESIZE 412*49cdfc7eSAndroid Build Coastguard Workerpagesize=`tst_getconf PAGESIZE` 413*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 414*49cdfc7eSAndroid Build Coastguard Worker 415*49cdfc7eSAndroid Build Coastguard WorkerSleeping for subsecond intervals 416*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++++++++++++++++ 417*49cdfc7eSAndroid Build Coastguard Worker 418*49cdfc7eSAndroid Build Coastguard WorkerAlbeit there is a sleep command available basically everywhere not all 419*49cdfc7eSAndroid Build Coastguard Workerimplementations can support sleeping for less than one second. And most of the 420*49cdfc7eSAndroid Build Coastguard Workertime sleeping for a second is too much. Therefore LTP includes 'tst_sleep' 421*49cdfc7eSAndroid Build Coastguard Workerthat can sleep for defined amount of seconds, milliseconds or microseconds. 422*49cdfc7eSAndroid Build Coastguard Worker 423*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 424*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 425*49cdfc7eSAndroid Build Coastguard Worker# sleep for 100 milliseconds 426*49cdfc7eSAndroid Build Coastguard Workertst_sleep 100ms 427*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 428*49cdfc7eSAndroid Build Coastguard Worker 429*49cdfc7eSAndroid Build Coastguard WorkerRetry a function call multiple times 430*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++++++++++++++++++++ 431*49cdfc7eSAndroid Build Coastguard Worker 432*49cdfc7eSAndroid Build Coastguard WorkerSometimes an LTP test needs to retry a function call multiple times because 433*49cdfc7eSAndroid Build Coastguard Workerthe system is not ready to process it successfully on the first try. The LTP 434*49cdfc7eSAndroid Build Coastguard Workerlibrary has useful tools to handle the call retry automatically. 435*49cdfc7eSAndroid Build Coastguard Worker'TST_RETRY_FUNC()' will keep retrying for up to 1 second. If you want a custom 436*49cdfc7eSAndroid Build Coastguard Workertime limit use 'TST_RETRY_FN_EXP_BACKOFF()'. Both methods return the value 437*49cdfc7eSAndroid Build Coastguard Workerreturned by the last 'FUNC' call. 438*49cdfc7eSAndroid Build Coastguard Worker 439*49cdfc7eSAndroid Build Coastguard WorkerThe delay between retries starts at 1 microsecond and doubles after each call. 440*49cdfc7eSAndroid Build Coastguard WorkerThe retry loop ends when the function call succeeds or when the next delay 441*49cdfc7eSAndroid Build Coastguard Workerexceeds the specified time (1 second for 'TST_RETRY_FUNC()'). The maximum 442*49cdfc7eSAndroid Build Coastguard Workerdelay is multiplied by TST_TIMEOUT_MUL. The total cumulative delay may be up 443*49cdfc7eSAndroid Build Coastguard Workerto twice as long as the adjusted maximum delay. 444*49cdfc7eSAndroid Build Coastguard Worker 445*49cdfc7eSAndroid Build Coastguard WorkerThe C version of 'TST_RETRY_FUNC()' is a macro which takes two arguments: 446*49cdfc7eSAndroid Build Coastguard Worker 447*49cdfc7eSAndroid Build Coastguard Worker* 'FUNC' is the complete function call with arguments which should be retried 448*49cdfc7eSAndroid Build Coastguard Worker multiple times. 449*49cdfc7eSAndroid Build Coastguard Worker* 'SUCCESS_CHECK' is a macro or function which will validate 'FUNC' return 450*49cdfc7eSAndroid Build Coastguard Worker value. 'FUNC' call was successful if 'SUCCESS_CHECK(ret)' evaluates to 451*49cdfc7eSAndroid Build Coastguard Worker non-zero. 452*49cdfc7eSAndroid Build Coastguard Worker 453*49cdfc7eSAndroid Build Coastguard WorkerBoth retry methods clear 'errno' before every 'FUNC' call so your 454*49cdfc7eSAndroid Build Coastguard Worker'SUCCESS_CHECK' can look for specific error codes as well. The LTP library 455*49cdfc7eSAndroid Build Coastguard Workeralso includes predefined 'SUCCESS_CHECK' macros for the most common call 456*49cdfc7eSAndroid Build Coastguard Workerconventions: 457*49cdfc7eSAndroid Build Coastguard Worker 458*49cdfc7eSAndroid Build Coastguard Worker* 'TST_RETVAL_EQ0()' - The call was successful if 'FUNC' returned 0 or NULL 459*49cdfc7eSAndroid Build Coastguard Worker* 'TST_RETVAL_NOTNULL()' - The call was successful if 'FUNC' returned any 460*49cdfc7eSAndroid Build Coastguard Worker value other than 0 or NULL. 461*49cdfc7eSAndroid Build Coastguard Worker* 'TST_RETVAL_GE0()' - The call was successful if 'FUNC' returned value >= 0. 462*49cdfc7eSAndroid Build Coastguard Worker 463*49cdfc7eSAndroid Build Coastguard Worker[source,c] 464*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 465*49cdfc7eSAndroid Build Coastguard Worker/* Keep trying for 1 second */ 466*49cdfc7eSAndroid Build Coastguard WorkerTST_RETRY_FUNC(FUNC, SUCCESS_CHECK) 467*49cdfc7eSAndroid Build Coastguard Worker 468*49cdfc7eSAndroid Build Coastguard Worker/* Keep trying for up to 2*N seconds */ 469*49cdfc7eSAndroid Build Coastguard WorkerTST_RETRY_FN_EXP_BACKOFF(FUNC, SUCCESS_CHECK, N) 470*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 471*49cdfc7eSAndroid Build Coastguard Worker 472*49cdfc7eSAndroid Build Coastguard WorkerThe shell version of 'TST_RETRY_FUNC()' is simpler and takes slightly 473*49cdfc7eSAndroid Build Coastguard Workerdifferent arguments: 474*49cdfc7eSAndroid Build Coastguard Worker 475*49cdfc7eSAndroid Build Coastguard Worker* 'FUNC' is a string containing the complete function or program call with 476*49cdfc7eSAndroid Build Coastguard Worker arguments. 477*49cdfc7eSAndroid Build Coastguard Worker* 'EXPECTED_RET' is a single expected return value. 'FUNC' call was successful 478*49cdfc7eSAndroid Build Coastguard Worker if the return value is equal to EXPECTED_RET. 479*49cdfc7eSAndroid Build Coastguard Worker 480*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 481*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 482*49cdfc7eSAndroid Build Coastguard Worker# Keep trying for 1 second 483*49cdfc7eSAndroid Build Coastguard WorkerTST_RETRY_FUNC "FUNC arg1 arg2 ..." "EXPECTED_RET" 484*49cdfc7eSAndroid Build Coastguard Worker 485*49cdfc7eSAndroid Build Coastguard Worker# Keep trying for up to 2*N seconds 486*49cdfc7eSAndroid Build Coastguard WorkerTST_RETRY_FN_EXP_BACKOFF "FUNC arg1 arg2 ..." "EXPECTED_RET" "N" 487*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 488*49cdfc7eSAndroid Build Coastguard Worker 489*49cdfc7eSAndroid Build Coastguard WorkerChecking for integers 490*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++ 491*49cdfc7eSAndroid Build Coastguard Worker 492*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 493*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 494*49cdfc7eSAndroid Build Coastguard Worker# returns zero if passed an integer parameter, non-zero otherwise 495*49cdfc7eSAndroid Build Coastguard Workertst_is_int "$FOO" 496*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 497*49cdfc7eSAndroid Build Coastguard Worker 498*49cdfc7eSAndroid Build Coastguard WorkerChecking for integers and floating point numbers 499*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++++++++++++++++++++++++++++++++ 500*49cdfc7eSAndroid Build Coastguard Worker 501*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 502*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 503*49cdfc7eSAndroid Build Coastguard Worker# returns zero if passed an integer or floating point number parameter, 504*49cdfc7eSAndroid Build Coastguard Worker# non-zero otherwise 505*49cdfc7eSAndroid Build Coastguard Workertst_is_num "$FOO" 506*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 507*49cdfc7eSAndroid Build Coastguard Worker 508*49cdfc7eSAndroid Build Coastguard WorkerObtaining random numbers 509*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++++++++ 510*49cdfc7eSAndroid Build Coastguard Worker 511*49cdfc7eSAndroid Build Coastguard WorkerThere is no '$RANDOM' in portable shell, use 'tst_random' instead. 512*49cdfc7eSAndroid Build Coastguard Worker 513*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 514*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 515*49cdfc7eSAndroid Build Coastguard Worker# get random integer between 0 and 1000 (including 0 and 1000) 516*49cdfc7eSAndroid Build Coastguard Workertst_random 0 1000 517*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 518*49cdfc7eSAndroid Build Coastguard Worker 519*49cdfc7eSAndroid Build Coastguard WorkerFormatting device with a filesystem 520*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++++++++++++++ 521*49cdfc7eSAndroid Build Coastguard Worker 522*49cdfc7eSAndroid Build Coastguard Worker'TST_FORMAT_DEVICE=1' can be used to format device before running the test. 523*49cdfc7eSAndroid Build Coastguard WorkerUses '$TST_FS_TYPE' (by default ext2), '$TST_DEVICE' a block device to be 524*49cdfc7eSAndroid Build Coastguard Workerformatted, usually prepared by the library (TST_NEEDS_DEVICE=1 must be set). 525*49cdfc7eSAndroid Build Coastguard Worker'$TST_DEV_FS_OPTS' a 'mkfs' options _before_ the device path and 526*49cdfc7eSAndroid Build Coastguard Worker'$TST_DEV_EXTRA_OPTS' extra 'mkfs'' options _after_ the device path. 527*49cdfc7eSAndroid Build Coastguard Worker 528*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 529*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 530*49cdfc7eSAndroid Build Coastguard WorkerTST_FORMAT_DEVICE=1 531*49cdfc7eSAndroid Build Coastguard WorkerTST_DEV_FS_OPTS="-b 1024 -O quota" 532*49cdfc7eSAndroid Build Coastguard WorkerTST_DEV_EXTRA_OPTS="5m" 533*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=test 534*49cdfc7eSAndroid Build Coastguard Worker 535*49cdfc7eSAndroid Build Coastguard Workertest() 536*49cdfc7eSAndroid Build Coastguard Worker{ 537*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "device formatted" 538*49cdfc7eSAndroid Build Coastguard Worker} 539*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 540*49cdfc7eSAndroid Build Coastguard Worker 541*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 542*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 543*49cdfc7eSAndroid Build Coastguard Worker# format test device with ext2 544*49cdfc7eSAndroid Build Coastguard Workertst_mkfs ext2 $TST_DEVICE 545*49cdfc7eSAndroid Build Coastguard Worker# default params are $TST_FS_TYPE $TST_DEVICE 546*49cdfc7eSAndroid Build Coastguard Workertst_mkfs 547*49cdfc7eSAndroid Build Coastguard Worker# optional parameters 548*49cdfc7eSAndroid Build Coastguard Workertst_mkfs ext4 /dev/device -T largefile 549*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 550*49cdfc7eSAndroid Build Coastguard Worker 551*49cdfc7eSAndroid Build Coastguard WorkerMounting and unmounting filesystems 552*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++++++++++++++ 553*49cdfc7eSAndroid Build Coastguard Worker 554*49cdfc7eSAndroid Build Coastguard WorkerThe 'tst_mount' and 'tst_umount' helpers are a safe way to mount/umount 555*49cdfc7eSAndroid Build Coastguard Workera filesystem. 556*49cdfc7eSAndroid Build Coastguard Worker 557*49cdfc7eSAndroid Build Coastguard WorkerThe 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to 558*49cdfc7eSAndroid Build Coastguard Worker'$TST_MNTPOINT' (defaults to mntpoint), optionally using the 559*49cdfc7eSAndroid Build Coastguard Worker'$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't 560*49cdfc7eSAndroid Build Coastguard Workerexist prior to the function call. 561*49cdfc7eSAndroid Build Coastguard Worker 562*49cdfc7eSAndroid Build Coastguard WorkerIf the path passed (optional, must be absolute path, defaults to '$TST_MNTPOINT') 563*49cdfc7eSAndroid Build Coastguard Workerto the 'tst_umount' is not mounted (present in '/proc/mounts') it's noop. 564*49cdfc7eSAndroid Build Coastguard WorkerOtherwise it retries to umount the filesystem a few times on failure. 565*49cdfc7eSAndroid Build Coastguard WorkerThis is a workaround since there are daemons dumb enough to probe all newly 566*49cdfc7eSAndroid Build Coastguard Workermounted filesystems, and prevents them from being umounted shortly after they 567*49cdfc7eSAndroid Build Coastguard Workerwere mounted. 568*49cdfc7eSAndroid Build Coastguard Worker 569*49cdfc7eSAndroid Build Coastguard WorkerROD and ROD_SILENT 570*49cdfc7eSAndroid Build Coastguard Worker++++++++++++++++++ 571*49cdfc7eSAndroid Build Coastguard Worker 572*49cdfc7eSAndroid Build Coastguard WorkerThese functions supply the 'SAFE_MACROS' used in C although they work and are 573*49cdfc7eSAndroid Build Coastguard Workernamed differently. 574*49cdfc7eSAndroid Build Coastguard Worker 575*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 576*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 577*49cdfc7eSAndroid Build Coastguard WorkerROD_SILENT command arg1 arg2 ... 578*49cdfc7eSAndroid Build Coastguard Worker 579*49cdfc7eSAndroid Build Coastguard Worker# is shorthand for: 580*49cdfc7eSAndroid Build Coastguard Worker 581*49cdfc7eSAndroid Build Coastguard Workercommand arg1 arg2 ... > /dev/null 2>&1 582*49cdfc7eSAndroid Build Coastguard Workerif [ $? -ne 0 ]; then 583*49cdfc7eSAndroid Build Coastguard Worker tst_brk TBROK "..." 584*49cdfc7eSAndroid Build Coastguard Workerfi 585*49cdfc7eSAndroid Build Coastguard Worker 586*49cdfc7eSAndroid Build Coastguard Worker 587*49cdfc7eSAndroid Build Coastguard WorkerROD command arg1 arg2 ... 588*49cdfc7eSAndroid Build Coastguard Worker 589*49cdfc7eSAndroid Build Coastguard Worker# is shorthand for: 590*49cdfc7eSAndroid Build Coastguard Worker 591*49cdfc7eSAndroid Build Coastguard WorkerROD arg1 arg2 ... 592*49cdfc7eSAndroid Build Coastguard Workerif [ $? -ne 0 ]; then 593*49cdfc7eSAndroid Build Coastguard Worker tst_brk TBROK "..." 594*49cdfc7eSAndroid Build Coastguard Workerfi 595*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 596*49cdfc7eSAndroid Build Coastguard Worker 597*49cdfc7eSAndroid Build Coastguard WorkerWARNING: Keep in mind that output redirection (to a file) happens in the 598*49cdfc7eSAndroid Build Coastguard Worker caller rather than in the ROD function and cannot be checked for 599*49cdfc7eSAndroid Build Coastguard Worker write errors by the ROD function. 600*49cdfc7eSAndroid Build Coastguard Worker 601*49cdfc7eSAndroid Build Coastguard WorkerAs a matter of a fact doing +ROD echo a > /proc/cpuinfo+ would work just fine 602*49cdfc7eSAndroid Build Coastguard Workersince the 'ROD' function will only get the +echo a+ part that will run just 603*49cdfc7eSAndroid Build Coastguard Workerfine. 604*49cdfc7eSAndroid Build Coastguard Worker 605*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 606*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 607*49cdfc7eSAndroid Build Coastguard Worker# Redirect output to a file with ROD 608*49cdfc7eSAndroid Build Coastguard WorkerROD echo foo \> bar 609*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 610*49cdfc7eSAndroid Build Coastguard Worker 611*49cdfc7eSAndroid Build Coastguard WorkerNote the '>' is escaped with '\', this causes that the '>' and filename are 612*49cdfc7eSAndroid Build Coastguard Workerpassed to the 'ROD' function as parameters and the 'ROD' function contains 613*49cdfc7eSAndroid Build Coastguard Workercode to split '$@' on '>' and redirects the output to the file. 614*49cdfc7eSAndroid Build Coastguard Worker 615*49cdfc7eSAndroid Build Coastguard WorkerEXPECT_PASS{,_BRK} and EXPECT_FAIL{,_BRK} 616*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++++++++++++++++++++ 617*49cdfc7eSAndroid Build Coastguard Worker 618*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 619*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 620*49cdfc7eSAndroid Build Coastguard WorkerEXPECT_PASS command arg1 arg2 ... [ \> file ] 621*49cdfc7eSAndroid Build Coastguard WorkerEXPECT_FAIL command arg1 arg2 ... [ \> file ] 622*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 623*49cdfc7eSAndroid Build Coastguard Worker 624*49cdfc7eSAndroid Build Coastguard Worker'EXPECT_PASS' calls 'tst_res TPASS' if the command exited with 0 exit code, 625*49cdfc7eSAndroid Build Coastguard Workerand 'tst_res TFAIL' otherwise. 'EXPECT_FAIL' does vice versa. 626*49cdfc7eSAndroid Build Coastguard Worker 627*49cdfc7eSAndroid Build Coastguard WorkerOutput redirection rules are the same as for the 'ROD' function. In addition 628*49cdfc7eSAndroid Build Coastguard Workerto that, 'EXPECT_FAIL' always redirects the command's stderr to '/dev/null'. 629*49cdfc7eSAndroid Build Coastguard Worker 630*49cdfc7eSAndroid Build Coastguard WorkerThere are also 'EXPECT_PASS_BRK' and 'EXPECT_FAIL_BRK', which works the same way 631*49cdfc7eSAndroid Build Coastguard Workerexcept breaking a test when unexpected action happen. 632*49cdfc7eSAndroid Build Coastguard Worker 633*49cdfc7eSAndroid Build Coastguard WorkerIt's possible to detect whether expected value happened: 634*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 635*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 636*49cdfc7eSAndroid Build Coastguard Workerif ! EXPECT_PASS command arg1 2\> /dev/null; then 637*49cdfc7eSAndroid Build Coastguard Worker continue 638*49cdfc7eSAndroid Build Coastguard Workerfi 639*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 640*49cdfc7eSAndroid Build Coastguard Worker 641*49cdfc7eSAndroid Build Coastguard Workertst_kvcmp 642*49cdfc7eSAndroid Build Coastguard Worker+++++++++ 643*49cdfc7eSAndroid Build Coastguard Worker 644*49cdfc7eSAndroid Build Coastguard WorkerThis command compares the currently running kernel version given conditions 645*49cdfc7eSAndroid Build Coastguard Workerwith syntax similar to the shell test command. 646*49cdfc7eSAndroid Build Coastguard Worker 647*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 648*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 649*49cdfc7eSAndroid Build Coastguard Worker# Exit the test if kernel version is older or equal to 4.0.0 650*49cdfc7eSAndroid Build Coastguard Workerif tst_kvcmp -le 4.0.0; then 651*49cdfc7eSAndroid Build Coastguard Worker tst_brk TCONF "Kernel newer than 4.0.0 is needed" 652*49cdfc7eSAndroid Build Coastguard Workerfi 653*49cdfc7eSAndroid Build Coastguard Worker 654*49cdfc7eSAndroid Build Coastguard Worker# Exit the test if kernel is newer than 3.16 and older than 4.0.1 655*49cdfc7eSAndroid Build Coastguard Workerif tst_kvcmp -gt 3.16 -a -lt 4.0.1; then 656*49cdfc7eSAndroid Build Coastguard Worker tst_brk TCONF "Kernel must be older than 3.16 or newer than 4.0.1" 657*49cdfc7eSAndroid Build Coastguard Workerfi 658*49cdfc7eSAndroid Build Coastguard Worker 659*49cdfc7eSAndroid Build Coastguard Workerif tst_kvcmp -lt "6.1 RHEL9:5.14.0-191"; then 660*49cdfc7eSAndroid Build Coastguard Worker # code for kernel < 6.1 or RHEL9 kernel < 5.14.0-191 661*49cdfc7eSAndroid Build Coastguard Workerfi 662*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 663*49cdfc7eSAndroid Build Coastguard Worker 664*49cdfc7eSAndroid Build Coastguard Worker[options="header"] 665*49cdfc7eSAndroid Build Coastguard Worker|======================================================================= 666*49cdfc7eSAndroid Build Coastguard Worker| expression | description 667*49cdfc7eSAndroid Build Coastguard Worker| -eq kver | Returns true if kernel version is equal 668*49cdfc7eSAndroid Build Coastguard Worker| -ne kver | Returns true if kernel version is not equal 669*49cdfc7eSAndroid Build Coastguard Worker| -gt kver | Returns true if kernel version is greater 670*49cdfc7eSAndroid Build Coastguard Worker| -ge kver | Returns true if kernel version is greater or equal 671*49cdfc7eSAndroid Build Coastguard Worker| -lt kver | Returns true if kernel version is lesser 672*49cdfc7eSAndroid Build Coastguard Worker| -le kver | Returns true if kernel version is lesser or equal 673*49cdfc7eSAndroid Build Coastguard Worker| -a | Does logical and between two expressions 674*49cdfc7eSAndroid Build Coastguard Worker| -o | Does logical or between two expressions 675*49cdfc7eSAndroid Build Coastguard Worker|======================================================================= 676*49cdfc7eSAndroid Build Coastguard Worker 677*49cdfc7eSAndroid Build Coastguard WorkerThe format for kernel version has to either be with one dot e.g. '2.6' or with 678*49cdfc7eSAndroid Build Coastguard Workertwo dots e.g. '4.8.1'. 679*49cdfc7eSAndroid Build Coastguard Worker 680*49cdfc7eSAndroid Build Coastguard WorkerKernel version can also be followed by a space separated list of extra versions 681*49cdfc7eSAndroid Build Coastguard Workerprefixed by distribution which when matched take precedence, e.g. '6.1 RHEL9:5.14.0-191'. 682*49cdfc7eSAndroid Build Coastguard Worker 683*49cdfc7eSAndroid Build Coastguard WorkerFor more info see 'tst_kvercmp()' and 'tst_kvercmp2()' in 684*49cdfc7eSAndroid Build Coastguard Workerhttps://github.com/linux-test-project/ltp/wiki/C-Test-API#16-runtime-kernel-version-detection[C Test API]. 685*49cdfc7eSAndroid Build Coastguard Worker 686*49cdfc7eSAndroid Build Coastguard WorkerNOTE: See also LTP 687*49cdfc7eSAndroid Build Coastguard Worker https://github.com/linux-test-project/ltp/wiki/Supported-kernel,-libc,-toolchain-versions#13-minimal-supported-kernel-version[minimal supported kernel version]. 688*49cdfc7eSAndroid Build Coastguard Worker 689*49cdfc7eSAndroid Build Coastguard Workertst_fs_has_free 690*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++ 691*49cdfc7eSAndroid Build Coastguard Worker 692*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 693*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 694*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 695*49cdfc7eSAndroid Build Coastguard Worker 696*49cdfc7eSAndroid Build Coastguard Worker... 697*49cdfc7eSAndroid Build Coastguard Worker 698*49cdfc7eSAndroid Build Coastguard Worker# whether current directory has 100MB free space at least. 699*49cdfc7eSAndroid Build Coastguard Workerif ! tst_fs_has_free . 100MB; then 700*49cdfc7eSAndroid Build Coastguard Worker tst_brkm TCONF "Not enough free space" 701*49cdfc7eSAndroid Build Coastguard Workerfi 702*49cdfc7eSAndroid Build Coastguard Worker 703*49cdfc7eSAndroid Build Coastguard Worker... 704*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 705*49cdfc7eSAndroid Build Coastguard Worker 706*49cdfc7eSAndroid Build Coastguard WorkerThe 'tst_fs_has_free' shell interface returns 0 if the specified free space is 707*49cdfc7eSAndroid Build Coastguard Workersatisfied, 1 if not, and 2 on error. 708*49cdfc7eSAndroid Build Coastguard Worker 709*49cdfc7eSAndroid Build Coastguard WorkerThe second argument supports suffixes kB, MB and GB, the default unit is Byte. 710*49cdfc7eSAndroid Build Coastguard Worker 711*49cdfc7eSAndroid Build Coastguard Workertst_retry 712*49cdfc7eSAndroid Build Coastguard Worker+++++++++ 713*49cdfc7eSAndroid Build Coastguard Worker 714*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 715*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 716*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 717*49cdfc7eSAndroid Build Coastguard Worker 718*49cdfc7eSAndroid Build Coastguard Worker... 719*49cdfc7eSAndroid Build Coastguard Worker 720*49cdfc7eSAndroid Build Coastguard Worker# Retry ping command three times 721*49cdfc7eSAndroid Build Coastguard Workertst_retry "ping -c 1 127.0.0.1" 722*49cdfc7eSAndroid Build Coastguard Worker 723*49cdfc7eSAndroid Build Coastguard Workerif [ $? -ne 0 ]; then 724*49cdfc7eSAndroid Build Coastguard Worker tst_resm TFAIL "Failed to ping 127.0.0.1" 725*49cdfc7eSAndroid Build Coastguard Workerelse 726*49cdfc7eSAndroid Build Coastguard Worker tst_resm TPASS "Successfully pinged 127.0.0.1" 727*49cdfc7eSAndroid Build Coastguard Workerfi 728*49cdfc7eSAndroid Build Coastguard Worker 729*49cdfc7eSAndroid Build Coastguard Worker... 730*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 731*49cdfc7eSAndroid Build Coastguard Worker 732*49cdfc7eSAndroid Build Coastguard WorkerThe 'tst_retry' function allows you to retry a command after waiting small 733*49cdfc7eSAndroid Build Coastguard Workeramount of time until it succeeds or until given amount of retries has been 734*49cdfc7eSAndroid Build Coastguard Workerreached (default is three attempts). 735*49cdfc7eSAndroid Build Coastguard Worker 736*49cdfc7eSAndroid Build Coastguard Worker1.5 Restarting daemons 737*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 738*49cdfc7eSAndroid Build Coastguard Worker 739*49cdfc7eSAndroid Build Coastguard WorkerRestarting system daemons is a complicated task for two reasons. 740*49cdfc7eSAndroid Build Coastguard Worker 741*49cdfc7eSAndroid Build Coastguard Worker* There are different init systems 742*49cdfc7eSAndroid Build Coastguard Worker (SysV init, systemd, etc...) 743*49cdfc7eSAndroid Build Coastguard Worker 744*49cdfc7eSAndroid Build Coastguard Worker* Daemon names are not unified between distributions 745*49cdfc7eSAndroid Build Coastguard Worker (apache vs httpd, cron vs crond, various syslog variations) 746*49cdfc7eSAndroid Build Coastguard Worker 747*49cdfc7eSAndroid Build Coastguard WorkerTo solve these problems LTP has 'testcases/lib/daemonlib.sh' library that 748*49cdfc7eSAndroid Build Coastguard Workerprovides functions to start/stop/query daemons as well as variables that store 749*49cdfc7eSAndroid Build Coastguard Workercorrect daemon name. 750*49cdfc7eSAndroid Build Coastguard Worker 751*49cdfc7eSAndroid Build Coastguard Worker.Supported operations 752*49cdfc7eSAndroid Build Coastguard Worker|============================================================================== 753*49cdfc7eSAndroid Build Coastguard Worker| start_daemon() | Starts daemon, name is passed as first parameter. 754*49cdfc7eSAndroid Build Coastguard Worker| stop_daemon() | Stops daemon, name is passed as first parameter. 755*49cdfc7eSAndroid Build Coastguard Worker| restart_daemon() | Restarts daemon, name is passed as first parameter. 756*49cdfc7eSAndroid Build Coastguard Worker| status_daemon() | Detect daemon status (exit code: 0: running, 1: not running). 757*49cdfc7eSAndroid Build Coastguard Worker|============================================================================== 758*49cdfc7eSAndroid Build Coastguard Worker 759*49cdfc7eSAndroid Build Coastguard Worker.Variables with detected names 760*49cdfc7eSAndroid Build Coastguard Worker|============================================================================== 761*49cdfc7eSAndroid Build Coastguard Worker| CROND_DAEMON | Cron daemon name (cron, crond). 762*49cdfc7eSAndroid Build Coastguard Worker| SYSLOG_DAEMON | Syslog daemon name (syslog, syslog-ng, rsyslog). 763*49cdfc7eSAndroid Build Coastguard Worker|============================================================================== 764*49cdfc7eSAndroid Build Coastguard Worker 765*49cdfc7eSAndroid Build Coastguard WorkerCron daemon restart example 766*49cdfc7eSAndroid Build Coastguard Worker+++++++++++++++++++++++++++ 767*49cdfc7eSAndroid Build Coastguard Worker 768*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 769*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 770*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 771*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 772*49cdfc7eSAndroid Build Coastguard Worker# Cron daemon restart example 773*49cdfc7eSAndroid Build Coastguard Worker 774*49cdfc7eSAndroid Build Coastguard WorkerTCID=cron01 775*49cdfc7eSAndroid Build Coastguard WorkerTST_COUNT=1 776*49cdfc7eSAndroid Build Coastguard Worker. test.sh 777*49cdfc7eSAndroid Build Coastguard Worker. daemonlib.sh 778*49cdfc7eSAndroid Build Coastguard Worker 779*49cdfc7eSAndroid Build Coastguard Worker... 780*49cdfc7eSAndroid Build Coastguard Worker 781*49cdfc7eSAndroid Build Coastguard Workerrestart_daemon $CROND_DAEMON 782*49cdfc7eSAndroid Build Coastguard Worker 783*49cdfc7eSAndroid Build Coastguard Worker... 784*49cdfc7eSAndroid Build Coastguard Worker 785*49cdfc7eSAndroid Build Coastguard Workertst_exit 786*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 787*49cdfc7eSAndroid Build Coastguard Worker 788*49cdfc7eSAndroid Build Coastguard Worker1.6 Access to the checkpoint interface 789*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 790*49cdfc7eSAndroid Build Coastguard Worker 791*49cdfc7eSAndroid Build Coastguard WorkerThe shell library provides an implementation of the checkpoint interface 792*49cdfc7eSAndroid Build Coastguard Workercompatible with the C version. All 'TST_CHECKPOINT_*' functions are available. 793*49cdfc7eSAndroid Build Coastguard Worker 794*49cdfc7eSAndroid Build Coastguard WorkerIn order to initialize checkpoints '$TST_NEEDS_CHECKPOINTS' must be set to '1' 795*49cdfc7eSAndroid Build Coastguard Workerbefore the inclusion of 'tst_test.sh': 796*49cdfc7eSAndroid Build Coastguard Worker 797*49cdfc7eSAndroid Build Coastguard Worker[source,sh] 798*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 799*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 800*49cdfc7eSAndroid Build Coastguard Worker 801*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CHECKPOINTS=1 802*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 803*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 804*49cdfc7eSAndroid Build Coastguard Worker 805*49cdfc7eSAndroid Build Coastguard WorkerSince both the implementations are compatible, it's also possible to start 806*49cdfc7eSAndroid Build Coastguard Workera child binary process from a shell test and synchronize with it. This process 807*49cdfc7eSAndroid Build Coastguard Workermust have checkpoints initialized by calling 'tst_reinit()'. 808*49cdfc7eSAndroid Build Coastguard Worker 809*49cdfc7eSAndroid Build Coastguard Worker1.7 Parsing kernel .config 810*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~ 811*49cdfc7eSAndroid Build Coastguard WorkerThe shell library provides an implementation of the kconfig parsing interface 812*49cdfc7eSAndroid Build Coastguard Workercompatible with the C version. 813*49cdfc7eSAndroid Build Coastguard Worker 814*49cdfc7eSAndroid Build Coastguard WorkerIt's possible to pass kernel kconfig list for tst_require_kconfigs API with 815*49cdfc7eSAndroid Build Coastguard Worker'$TST_NEEDS_KCONFIGS'. 816*49cdfc7eSAndroid Build Coastguard WorkerOptional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma. 817*49cdfc7eSAndroid Build Coastguard Worker 818*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 819*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 820*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y" 821*49cdfc7eSAndroid Build Coastguard Worker 822*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh 823*49cdfc7eSAndroid Build Coastguard Worker------------------------------------------------------------------------------- 824*49cdfc7eSAndroid Build Coastguard Worker 825*49cdfc7eSAndroid Build Coastguard Worker1.8 Skipping test based on system state 826*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 827*49cdfc7eSAndroid Build Coastguard WorkerTest can be skipped on various conditions: on enabled SecureBoot 828*49cdfc7eSAndroid Build Coastguard Worker('TST_SKIP_IN_SECUREBOOT=1'), lockdown ('TST_SKIP_IN_LOCKDOWN=1'). 829