LTP first chapter LTP Introduction and internal mechanism

Source: Internet
Author: User
Tags echo command git clone cve automake

LTP Series Links:

Chapter I introduction and internal mechanism of LTP

Chapter II Development of Shell test set

Chapter III development system call test set

The fourth chapter develops _exit () test set

The fifth chapter develops IO operation Test set

The sixth chapter develops IO blocking test set

1.1 LTP Introduction 1.1.1 Function test 1.1.2 regression test 1.1.3 Stress Test 1.2 LTP Environment Deployment 1.2.1 Download LTP 1.2.2 Deploy LTP 1.3 directory structure 1.3.1 Source Package 1.3.2 installation Package 1.4 test Framework 1.4.1 Overall test process 1.4.2 test Case Execution Process 1.4.3 Test Library 1.5 test Execution 1.5.1 Overall test 1.5.2 separate Test 1.5.2.1 installation package Test 1.5.2.2 Source package Test 1.6 His experiment 1.6.1 validation sqrt () function 1.6 .2 Verify Echo command

Source Address: Https://github.com/jitwxs/blog_sample 1.1 LTP Introduction

LTP (Linux Test project) is an open source Community cooperation project based on the GPL protocol. Launched in 2000 by SGI, IBM, osdl and Bull and other companies to participate, 2001 years later by the SuSE, Fujitsu, Red Hat, Oracle Common development and maintenance.

Verify the reliability, stability, and robustness of the Linux system through functional, stress, and regression tests. The entire project has about 4,000 test cases, most of which use C or shell.

LTP not only tests the kernel, but also tests the overall system environment, and tests the return and processing of function failures. 1.1.1 Functional Testing

The features described in the 1, 8 command and 2 system calls in man pages are mainly validated. 1.1.2 Regression Test

After you have modified the old code, you have confirmed that the modification did not introduce a new error or cause other code to produce an error. 1.1.3 Pressure test

The stability and reliability of the system are tested under heavy load pressure. 1.2 LTP Environment Deployment 1.2.1 Download LTP

LTP Project currently located in GitHub, Project address: HTTPS://GITHUB.COM/LINUX-TEST-PROJECT/LTP

Get the latest version to perform the following command: Git clone https://github.com/linux-test-project/ltp.git 1.2.2 Deployment LTP

The following command is used first to install the related packages (installed to skip):

#CentOS
sudo yum install autoconf  automake  autotools-dev M4

#Ubuntu
sudo apt-get install  Automake  Autotools-dev M4

In the previous section I downloaded the LTP project to the WXS user's home directory (/HOME/WXS), as shown in the figure:

[Wxs@bogon ~]$ cd ltp/
[wxs@bogon ltp]$ ls
aclocal.m4 configure.ac INSTALL           pan                   testcases
autom4te.cache  conflknw6u    install-sh        readme.kernel_config  testscripts
CONFC20WZW      copying       lib               readme.md             TODO
config.guess    doc           ltpmenu           runltp                Tools
Config.log      EXECLTP       M4                runltplite.sh   utils    config.status Makefile          runtest               ver_linux
config.sub      idcheck.sh  makefile.release Groups       version
Configure       include       missing           scripts               version

Enter LTP directory : cd LTP

Build Auto Tool : Make Autotools

System Environment Configuration :./configure

compiling : make-j$ (GETCONF_NPROCESSORS_ONLN)

installation : sudo make install

After executing the above command sequentially, LTP has been properly installed on your Linux system, and the default installation is located in/opt/ltp/.

[Wxs@bogon ltp]$ cd/opt/ltp/
[wxs@bogon ltp]$ ls
bin         runltp  runtest Share-testscripts Version
idcheck.sh  runltplite.sh  scenario_groups  testcases  ver_linux

Note that the LTP folder in the home directory that we downloaded through the git clone command is the LTP source folder , which I will refer to as the source package in the following text.

By performing a series of commands to install the LTP folder under the/opt directory for LTP installation folder , I will briefly refer to the following text for the installation package . 1.3 directory Structure 1.3.1 Source Pack

The LTP source package directory structure is described as follows:

name Description
INSTALL LTP Installation Configuration Guidance Document
Readme LTP Introduction
Credits A person who records a great contribution to LTP.
Copying GNU Public License
Changelog Describe version changes
Ltpmenu Planning for the implementation of LTP graphical interface interface
Makefile LTP Top Directory makefile, responsible for compiling and installing pan, testcases and tools
runalltests.sh Script that runs all test cases sequentially and reports the results
doc/* Engineering documentation contains tools and library function manuals that describe various tests
include/* Common Header file Directory
lib/* Common function Directory
testcases/* Contains all test cases and links under the LTP Run and Bin directory
testscripts/* Test scripts for grouping
runtest/* Provide a list of commands for automated tests
pan/* A test driver that has the ability to do random and parallel testing
scratch/* Storing fragmented tests
tools/* Storing automated test scripts and assistive tools

The LTP test suite contains the following:

[Wxs@bogon ~]$ cd ltp/testcases/
[wxs@bogon testcases]$ ls
commands  Demoa kernel Makefile Network               Realtime
CVE       kdump  lib     misc      open_posix_testsuite

The directory structure is described as follows:

name Description
Commands Common Command test
Kernel Kernel module and its related modules
Kdump Kernel now crash dump test
Network Network test
Realtime Real-time testing of the system
Open_posix_testsuite POSIX standard test
Misc Crashes, core spin out, floating-point operations, etc. tests
1.3.2 Installation Package

The LTP installation package directory structure is described as follows:

name Description
Bin Some secondary scripts to store LTP tests
Results Test results Default Storage directory
Testcases Test item Set
Output Test log Default Storage directory
Share Script Usage Description Directory
Runtest Test driver (used to link test scripts and testcases test projects within TestScripts)
Lib Common Library Function Directory
1.4 Test Framework 1.4.1 Overall testing process

The RUNLTP script in LTP installation package root directory is the entrance to LTP Automatic test system, which provides a series of parameter options, allows the user to set test environment to develop test set, control test result output way and path, etc., run RUNLTP will generate the specified test list and invoke test drive pan to start the test. Generate reports based on the results returned by the pan after completion.

The pan is a group of LTP test drivers that are responsible for the execution of the actual test, performing the tests sequentially according to the parameters and test lists passed by RUNLTP, outputting the details of the execution, counting the execution results of each test case, and returning the overall test results to RUNLTP.

1.4.2 test Case Execution Process

The output types of the test results are as follows:

Type Description
Brok An error occurred midway through the program and the tests were compromised
CONF Skip execution when test environment is not satisfied
WARN An exception occurred midway through the test
INFO Output Generic Test information
Pass Test successful
FAIL Test failed
1.4.3 Test Library

LTP is currently testing inventory in the new and old test library Alternately, this article adopts the framework of the New test library , the specific update instructions can refer to the updated document an update on the Linux test Project.

Old
Library New Library
A test case invokes the API of the test library at execution time Callback test cases in child processes maintained by the test library
In Setup (), call the API to complete the test preparation Test properties in Setup () are defined as struct variables
Main () is defined in each test case Main () is defined in the test library
Safe function cannot be invoked in cleanup () Allow the safe function to be invoked in cleanup ()

Here take umount02 as an example to compare the differences between the old and new frames:

Old Frame code:

Example using the old LTP library//https://lwn.net/articles/708250/#include <errno.h> #include <sys/mount.h > #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> #include <pwd.h> #
Include "Test.h" #include "safe_macros.h" static void Setup (void);

static void Cleanup (void);

Char *tcid = "umount02"; #define Dir_mode S_irwxu | S_irwxg | S_iroth | S_ixoth #define File_mode S_irwxu | S_irwxg |
S_irwxo #define MNTPOINT "Mntpoint" static char Long_path[path_max + 2];
static int mount_flag;

static int fd;

static const char *device;
    static struct test_case_t {char *err_desc;
    Char *mntpoint;
    int Exp_errno;
Char *exp_retval; } testcases[] = {{"Already mounted/busy", Mntpoint, Ebusy, "Ebusy"}, {"Invalid address spaces", NULL, Efault, "EFA
    ULT "}, {" Directory not Found "," nonexistent ", Enoent," Enoent "}, {" Invalid device ","./", Einval," Einval "}, {"Pathname too long", Long_path,Enametoolong, "Enametoolong"}};

int tst_total = array_size (testcases);

    int main (int ac, char **av) {int LC, I;

    Tst_parse_opts (AC, AV, NULL, NULL);

    Setup (); for (LC = 0; Test_looping (LC);

        lc++) {tst_count = 0;

            for (i = 0; i < tst_total ++i) {TEST (Umount (testcases[i].mntpoint)); if ((Test_return = = 1) && (Test_errno = = Testcases[i].exp_errno)) {Tst_resm (Tpass, "Umount (2) ex pected failure;
                            "" Got errno-%s:%s ", Testcases[i].exp_retval,
            TESTCASES[I].ERR_DESC); else {tst_resm (Tfail, "Umount (2) failed to produce" "expected error; %d, errno:%s got%d ", Testcases[i].exp_errno, Testcases[i].exp_ret
            Val, Test_errno);
    }} cleanup ();
Tst_exit (); static void Setup (Void) {const char *fs_type;

    Tst_sig (FORK, Def_handler, Cleanup);

    Tst_require_root ();

    Tst_tmpdir ();
    Fs_type = Tst_dev_fs_type ();

    device = Tst_acquire_device (cleanup);

    if (!device) tst_brkm (tconf, Cleanup, "Failed to obtain block device");

    TST_MKFS (cleanup, device, fs_type, NULL, NULL);

    memset (Long_path, ' a ', Path_max + 1);

    Safe_mkdir (cleanup, mntpoint, Dir_mode); if (Mount (device, Mntpoint, Fs_type, 0, NULL)) tst_brkm (Tbrok |

    Terrno, Cleanup, "Mount () failed");

    Mount_flag = 1; FD = Safe_open (cleanup, mntpoint "/file", O_creat |

    O_RDWR);
Test_pause; } static void Cleanup (void) {if (fd > 0 && Close (FD)) Tst_resm (Twarn |

    Terrno, "Failed to close File"); if (Mount_flag && tst_umount (mntpoint)) Tst_resm (Twarn |

    Terrno, "Umount () failed");

    if (device) tst_release_device (device);
Tst_rmdir (); }

New Frame code:

Example using the new LTP library//https://lwn.net/articles/708251/#include <errno.h> #include <string.h&gt
; #include <sys/mount.h> #include "tst_test.h" #define Mntpoint "mntpoint" static char Long_path[path_max + 2
];
static int mount_flag;

static int fd;
        static struct Tcase {const char *err_desc;
        const char *mntpoint;
int Exp_errno; } tcases[] = {{"Already mounted/busy", Mntpoint, ebusy}, {"Invalid address", NULL, Efault}, {"Dir Ectory not found "," nonexistent ", enoent}, {" Invalid device ","./", einval}, {" Pathname too long ", long_p

Ath, Enametoolong}};

        static void Verify_umount (unsigned int n) {struct Tcase *TC = &tcases[n];

        TEST (Umount (tc->mntpoint));
                if (Test_return!=-1) {Tst_res (Tfail, "Umount () succeeds unexpectedly");
        Return } if (Tc->exp_errno!= test_errno) {tst_res (Tfail | TTerrno, "umount () should fail with%s", Tst_strerrno (Tc->exp_errno));
        Return } tst_res (Tpass |
Tterrno, "Umount () fails as expected:%s", TC-&GT;ERR_DESC);

        static void Setup (void) {memset (Long_path, ' a ', Path_max + 1);
        SAFE_MKFS (Tst_device->dev, tst_device->fs_type, NULL, NULL);
        Safe_mkdir (Mntpoint, 0775);
        Safe_mount (Tst_device->dev, Mntpoint, Tst_device->fs_type, 0, NULL);

        Mount_flag = 1;
FD = Safe_creat (mntpoint "/file", 0777); } static void Cleanup (void) {if (fd > 0 && Close (FD)) Tst_res (Twarn |

        Terrno, "Failed to close File");
if (Mount_flag) Tst_umount (mntpoint); 
        static struct Tst_test test = {. Tid = "umount02",. tcnt = Array_size (tcases),. needs_root = 1, . Needs_tmpdir = 1,. Needs_device = 1,. Setup = Setup,. Cleanup =Cleanup,. test = Verify_umount,}; 
1.5 test Execution 1.5.1 Overall Test

We can test all the test sets, run the RUNLTP command directly will test all the test sets in Ltp/scenario_groups/default, one test for about 2-3 hours.

[Wxs@bogon ltp]$ cd/opt/ltp
[Wxs@bogon ltp]$ sudo./runltp

Of course we can only test a test set, the test set can be viewed under ltp/runtest/.

[Wxs@bogon ltp]$ ls runtest/admin_tools IPC NET_STRESS.IPSEC_UDP can Kernel_mi SC net_stress.multicast cap_bounds ltp-aiodio.part1 net_stress.route commands Ltp-aio Dio.part2 Net.tcp_cmds connectors Ltp-aiodio.part3 net.tirpc_tests Containers
T4 network_commands controllers Ltp-aio-stress.part1 NPTL cpuhotplug ltp-aio-stress.part2 Numa                 Crashme ltplite pipes CVE lvm.part1 power_management_tests Lvm.part2 power_management_tests_exclusive Dma_thread_diotest Math pty fcntl- locktests mm Quickhit filecaps Modules Sched FS NET.FEA           Tures scsi_debug.part1 fs_bind Net.ipv6 securebits FS_EXT4 Smack fs_perms_sImple net.multicast stress.part1 fs_readonly net.nfs stress.part2               Net.rpc stress.part3 hugetlb net.rpc_tests syscalls hyperthreading SYSCALLS-IPC ima net_stress.appl Timers input NET_STRESS.BROKEN_IP Tpm_too LS io net_stress.interface tracing io_cd net_stress.ipsec_icmp io_floppy Net_st ress.ipsec_tcp [Wxs@bogon ltp]$ sudo./runltp-f modules

It should be noted that if we test a test set, RUNLTP needs to specify the-f argument. 1.5.2 Separate test

If we do not want to test a test set, just want to test a separate test, you can use the installation package test or the source code package test. Take access01 as an example to explain the individual tests. 1.5.2.1 installation package Test

Enter the installation package and execute the following command.

[Wxs@bogon ltp]$ cd/opt/ltp/
[Wxs@bogon ltp]$ sudo./runltp-s access01

It should be noted that if we test a test, RUNLTP needs to specify the-s parameter. 1.5.2.2 Source Pack test

Enter the source package, find the location of the access01, direct execution./access01.

[Wxs@bogon access]$ cd ~/ltp/testcases/kernel/syscalls/access/
[Wxs@bogon access]$ sudo./access01

We see that ACCESS01 is located in the Testcases directory, in fact testcases directory each file is a complete executable program, can be directly executed in the compiled source path. 1.6 His experiment

The projects involved in this section are located in the testcases Demoa folder under the source code package. Test methods are used test set test (c implementation of the test cases can be used source code test and test set test, shell implementation of the test cases can only be used test set test).

[Wxs@bogon ~]$ cd ~/ltp/testcases/
[Wxs@bogon testcases]$ mkdir Demoa
[wxs@bogon testcases]$ cd demoa/
[ Wxs@bogon demoa]$ pwd
/home/wxs/ltp/testcases/demoa
1.6.1 Validation sqrt () function

Refer to the sample code given in section 1.3.3 to write test case SQRT.C:

#include <errno.h>
#include <string.h>
#include <sys/mount.h>
#include "tst_test.h"

static struct Tcase {
    const int input;
    const int output;
Tcases[] = {
        { -1,1},
        {9,3}}
;

static void testsqrt (unsigned int n) {
    struct tcase *TC = &tcases[n];

    TEST (sqrt (tc->input));

    if (Test_return!= tc->output) {
        tst_res (tfail, "sqrt () failed");
        return;
    }
    Tst_res (Tpass, "sqrt () succeeds");
}

static struct Tst_test test = {
        . tid = "Testsqrt",
        . tcnt = Array_size (tcases),
        . Test = testsqrt,
};

Refer to the other makefile files in the testcases directory to write makefile:

Top_srcdir? =.. /..

Include $ (top_srcdir)/include/mk/testcases.mk

include $ (top_srcdir)/include/mk/generic_leaf_target.mk

SQRT:  ldlibs + +-LM

Note that the top_srcdir refers to the LTP directory because the Demoa directory is located on the two floor of the LTP directory, so it uses the. /..。

It is also important to note that the-LM parameter must be appended to the successful use of the SQRT command, which is already reflected in makefile.

Execute make command to generate executable file sqrt:

[wxs@bogon demoa]$ make Make-c "/home/wxs/ltp/lib"-F "/home/wxs/ltp/lib/makefile" all make[1
]: Enter directory "/home/wxs/ltp/lib" make[2]: Enter directory "/home/wxs/ltp/lib/newlib_tests" make[2]: no need to do anything with "all".
MAKE[2]: Leave directory "/home/wxs/ltp/lib/newlib_tests" make[2: Enter Directory "/home/wxs/ltp/lib/tests" make[2]: no need to do anything with "all". MAKE[2]: Leave the directory "/home/wxs/ltp/lib/tests" make[1]: Leave the directory "/home/wxs/ltp/lib" Gcc-g-o2-g L-w-wold-style-definition-d_fortify_source=2-i. /.. /include-i.. /.. /include-i.. /.. /include/old/-L. /..
  /lib sqrt.c-lltp-lm-o sqrt sqrt.c: in function ' testsqrt ': sqrt.c:17:2: Warning: Implicit declaration of function ' sqrt ' [-wimplicit-function-declaration]
  TEST (sqrt (tc->input)); ^ in file included from Sqrt.c:4:0:sqrt.c:17:7: Warning: Implicit declaration and built-in function ' sq 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.