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