The Gtest white Box test tool is used on the embedded platform , which covers the measured function, but does not know the effect of the test, test line coverage, function coverage, branch coverage data.
began to study Gcov whether this code coverage tool can be used to check the effect of white-box testing, and to guide the direction of testing improvements. After many attempts and studies,
The Gcov tool can be used on an embedded platform , but the operation is slightly more complex.
Environmental requirements:
1. The source code of the component under test
2. The cross compiler of the corresponding platform must contain the Gcov function
3. Installation of Lcov Tools
4, the corresponding embedded equipment
Using Gcov/lcov to test code coverage is a total of four steps:
1, add gcov compilation parameters in component compilation, then compile Debug version, generate gcno file at the same time
2. using components to add compilation parameters in Gtest compilation
3, execute the generated program, generate code Overwrite file gcda
4. Use Lcov tool to parse Gcno and gcda files, generate HTML report file
The following is a detailed description of how the four steps work:
1. Adding compilation parameters to component compilation
We are testing the component, which is either a static library (. A) or a dynamic library (. So). In order to measure the code coverage of the test, we need to add the following parameters at compile time.
The compilation parameters that need to be added are:-fprofile-arcs-ftest-coverage; add the corresponding library Lgcov
After the addition is complete, compile. Then locate and locate the generated suffix named gcno file, which indicates success.
Important: The path generated by the Gcno file is typically determined by the different paths specified by the makefile script, sometimes with the source code, and sometimes with the intermediate files.
But regardless of where the gcno path is, remember this path. Subsequent useful.
2. using components with Gcov in gtest compilation
A, modify the compilation script, add -lgcov compilation parameters
B. Replace the library file with the component that added the Gcov compilation parameter
(How to use gtest in embedded platforms, refer to http://www.cnblogs.com/StitchSun/p/4430362.html)
3. Execute gtest test procedure
Test the compiled test program on the corresponding device, execute no error, then view the directory of the embedded device, and locate the gcda file in the same directory as the generated GCNO path.
The gcda file generation path is the path to build gcno at compile time, but Gcno is on the compile server, GCDA is on the embedded device that the program is running on.
4. Use Lcov to parse gcda and gcno files
Download the device's gcda file to the compile server, and copy the Gcno file generated at compile time to the same directory.
For files with the same name as the previous names, thegcda and gcno files must be in the same directory.
To use the Lcov tool, you can download the latest version in http://ltp.sourceforge.net/coverage/lcov.php.
However, this tool does not directly parse the GCNO and GCDA-formatted files generated by the embedded platform and needs to be modified in one place.
That is, this tool defaults to using the Gcov that comes with the Linux system and needs to be modified to use the Cross compiler's Gcov tool.
The modified file is: Bin/geninfo, the original Gcov modified to cross-compiled Gcov.
Modify complete, save exit.
To use the isi3518 cross compiler as an example, execute the following command:
A/opt/lcov_test/hisi3518/lcov-1.9/bin/lcov-d. -T ' Test '-o ' test.info '-B. -C
B/opt/lcov_test/hisi3518/lcov-1.9/bin/genhtml-o result Test.info
See the above tips to show that the execution was successful. Download the result folder to windows and open the index inside to see the results.
Problems:
1, Geninfo:error: ...: Reached unexpected end of file
Note that Lcov is best to use version 1.9 and above, or you may experience the following error:
Geninfo:error: ...: Reached unexpected end of file
2. Gcov solve stamp mismatch with graph file
Parse Xxx.gcno and XXX.GCDA files separately using the Hexdump-e '%x\n '-s8-n4 command
If the generated code is inconsistent, then gcno and GCDA are not compiled once and need to be recompiled.
Commands are used as follows:
Hexdump-e ' "%x\n" '-s8-n4 dns_shell.gcno
3. Source code not found
When parsing gcno and GCDA, the source code is on a server, and the source code path is generated after Gcno and GCDA
Have not changed. Otherwise, you will be prompted not to find the source code.
Reference:
In the study, the following links are of great help. expressed thanks.
Http://blog.sina.com.cn/s/blog_7e4ac8b501018b27.html
The third step in this reference Gcov generates the report information: test.c.gcov does not need to execute
Embedded Platform Components white box test Gcov, Lcov, and genhtml use guide