xref: /aosp_15_r20/external/ltp/doc/developers/ltp_library.rst (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker.. SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker
3*49cdfc7eSAndroid Build Coastguard WorkerLTP Library guidelines
4*49cdfc7eSAndroid Build Coastguard Worker======================
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard WorkerGeneral Rules
7*49cdfc7eSAndroid Build Coastguard Worker-------------
8*49cdfc7eSAndroid Build Coastguard Worker
9*49cdfc7eSAndroid Build Coastguard WorkerWhen we extend library API, we need to apply the same general rules that we use
10*49cdfc7eSAndroid Build Coastguard Workerwhen writing tests, plus:
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard Worker#. LTP library tests must go inside :master:`lib/newlib_tests` directory
13*49cdfc7eSAndroid Build Coastguard Worker#. LTP documentation has to be updated according to API changes
14*49cdfc7eSAndroid Build Coastguard Worker
15*49cdfc7eSAndroid Build Coastguard WorkerShell API
16*49cdfc7eSAndroid Build Coastguard Worker---------
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard WorkerAPI source code is in :master:`testcases/lib/tst_test.sh`,
19*49cdfc7eSAndroid Build Coastguard Worker:master:`testcases/lib/tst_security.sh` and :master:`testcases/lib/tst_net.sh`.
20*49cdfc7eSAndroid Build Coastguard Worker
21*49cdfc7eSAndroid Build Coastguard WorkerChanges in the shell API should not introduce uncommon dependencies
22*49cdfc7eSAndroid Build Coastguard Worker(use basic commands installed everywhere by default).
23*49cdfc7eSAndroid Build Coastguard Worker
24*49cdfc7eSAndroid Build Coastguard WorkerShell libraries
25*49cdfc7eSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~
26*49cdfc7eSAndroid Build Coastguard Worker
27*49cdfc7eSAndroid Build Coastguard WorkerAside from shell API libraries in :master:`testcases/lib` directory, it's
28*49cdfc7eSAndroid Build Coastguard Workerworth putting common code for a group of tests into a shell library.
29*49cdfc7eSAndroid Build Coastguard WorkerThe filename should end with ``_lib.sh`` and the library should load
30*49cdfc7eSAndroid Build Coastguard Worker``tst_test.sh`` or ``tst_net.sh``.
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard WorkerShell libraries should have conditional expansion for ``TST_SETUP`` or
33*49cdfc7eSAndroid Build Coastguard Worker``TST_CLEANUP``, to avoid surprises when test specific setup/cleanup function is
34*49cdfc7eSAndroid Build Coastguard Workerredefined by shell library.
35*49cdfc7eSAndroid Build Coastguard Worker
36*49cdfc7eSAndroid Build Coastguard Worker.. code-block:: bash
37*49cdfc7eSAndroid Build Coastguard Worker
38*49cdfc7eSAndroid Build Coastguard Worker    # ipsec_lib.sh
39*49cdfc7eSAndroid Build Coastguard Worker    # SPDX-License-Identifier: GPL-2.0-or-later
40*49cdfc7eSAndroid Build Coastguard Worker    TST_SETUP="${TST_SETUP:-ipsec_lib_setup}"
41*49cdfc7eSAndroid Build Coastguard Worker    ...
42*49cdfc7eSAndroid Build Coastguard Worker    . tst_test.sh
43