Linux Kernel testing and debugging (1)
Automatic Testing Tool
Here are some test tools that can meet your needs. This section is just a brief introduction and does not provide detailed operation instructions.
AuToTest
AuToTest is a fully automated testing framework. It mainly aims to test the Linux kernel. It can also be used to test other things, such as whether a new hardware can work stably. AuToTest is an open-source software that is authorized by GPL and runs in the server-client architecture (namely, the C/S architecture ). You can configure the server to initialize, run, and monitor the system running the client, or run the client on the target system. In addition, you can add test cases for this test framework. For more information, see the AuToTest White Paper.
Linaro automatic Validation Architecture
The LAVA automated testing framework is used for automatic installation and running testing. For example, you only need to run a few commands in LAVA to run LTPLCTT: Linux Test Project. Chinese is the Linux Test plan. SGI is initiated and maintained by IBM, the objective is to provide a test suite for the open-source community to verify the reliability, robustness, and stability of Linux ). The LAVA command can automatically install all the dependent packages required by LTP, download the source code, compile the code, and install LTP in a separate place, so that all binary files can be removed when LTP is uninstalled. After LTP is installed, you can run the ltp test task by adding the 'ltp 'option when running the LAVA command. It saves the test results as files, the file name contains the test name and timestamp. These test results are retained for future reference. This is a good way to find software degradation if the software degrades. The following lists some commands used by LAVA in combination with LTP:
Display the test list supported by LAVA:
- lava-test list-tests
Install the test suite:
- lava-test install ltp
Run the test:
- lava-test run ltp
View results:
- lava-test results show ltp-timestamp.0
Uninstall test suite:
- lava-test uninstall ltp
Kernel debugging
The Linux kernel contains many debugging functions, such as kmemcheck and kmemleak.
Kmemcheck
Kmemcheck is a dynamic check tool that detects uninitialized memory LCTT and issues a warning. Its function is similar to Valgrind, but Valgrind runs in the user State, while kmemchecke runs in the kernel state. When compiling the kernel, add the CONFIG_KMEMCHECK option to enable the kmemcheck debugging function. You can read Documentation/kmemcheck.txt to learn how to configure and use this function and how to understand the debugging results.
Kmemleak
Kmemleak detects whether the kernel has a memory leakage problem through a function similar to the garbage collector. The difference between kmemleak and the garbage collector is that the former will not release the orphan target LCTT: memory areas that will no longer be used and should be released but not released ), instead, print them to the/sys/kernel/debug/kmemleak file. User-mode Valgrind also has a similar function. The -- leak-check option can be used to detect and report Memory leakage problems, but this orphan memory is not released. When compiling the kernel, use the CONFIG_DEBUG_KMEMLEAK option to enable the kmemcleak debugging function. Read Documentation/kmemleak.txt to learn how to use this tool and read the debugging results.
Kernel debugging Interface
The Linux kernel supports dynamic or static debugging through configuration options, APIs for debugging, interfaces, and frameworks. Now let's take a good look at these awesome functions, starting with static compilation options.
Debugging configuration options: static Compilation
Most Linux kernels and kernel modules contain debugging options. You only need to add this static debugging option when compiling the kernel or kernel module. debugging information will be generated after the program runs, and recorded in dmesg cache.
API for debugging
A good example of API debugging is DMA-debug, which is used to debug whether the driver uses the APIS provided by DMA incorrectly. It will track the ing relationship between each device and check whether the program has attempted to perform the "un ing" operation for some non-existent mappings, detects the possible "ing loss" error after the Code establishes a DMA ing. Kernel configuration options: CONFIG_HAVE_DMA_APT_DEBUG and CONFIG_DMA_API_DEBUG can provide this function for the kernel. When the CONFIG_DMA_API_DEBUG option is enabled, the kernel also calls the dma api and the Debug-dma interface. For example, when a driver calls the dma_map_page () function to map a DMA cache, dma_map_page () calls the debug_dma_map_page () function to track the cache until the driver calls dma_unmap_page () to cancel the ing. For details, see use the DMA debugging API to detect potential data pollution and Memory leakage.