Delta code UT coverage check based on LCOV implementation

Source: Internet
Author: User

Background introduction

In conjunction with the Cpputest Unit Test framework, Lcov provides a relatively complete set of engineering tools to measure UT coverage. But for some teams, the history burden is too heavy, and a lot of legacy code does not have the corresponding UT. In this case, a coverage check of the new code might be a more feasible measure for the team. Based on this objective, the following requirements are proposed:

1) Utilization of existing lcov resources;

2) UT coverage can be checked for code submitted by the specified Git cmmit;

3) can specify the need for UT coverage inspection software modules, files;

4) The UT coverage threshold can be set;

5) Visual display of inspection results, have a good user experience;

To achieve the above requirements, a ut_incremental_check.py tool has been developed. The effect of its integration in Jenkins is as follows:

Figure one: Generate new code after each build UT coverage report: Unittest-incremental Code Coverage reports

Figure Two: New code UT coverage report details

Figure Three: Click on the specific uncovered line number can directly "elevator" direct to the bank code location for viewing

Tools Introduction

The ut_incremental_check.py has 4 parameters:

<since>, .... <until>: Specify git commit sha range

<MONITOR_C_FILES>: Specifies a list of files or directories that need to be followed, and this parameter conforms to the JSON data format

<lcov_dir>:lcov generated target file directory

<THRESHOLD>: The lower limit for the new code UT coverage. The range of values is in the (0,1] range.

The overall workflow is shown in the help instructions below.

$./ut_incremental_check.py

PURPOSE:
Calculate UT coverage of Git commits ' new code

USAGE:
./ut_incremental_check.py <since>.. <until> <monitor_c_files> <lcov_dir> <threshold>
Example
./ut_incremental_check.py "227b032. 79196ba "' [" Source/soda/sp/lssp/i2c-v2/ksource "]" coverage "0.6

Work PROCESS:
Get changed file list between <since> and <until>, filter by <monitor_c_files> options;
Get changed lines per changed file;
Based on <lcov_dir>, search. gcov.html per file, and get uncover lines;
Create report file:ut_incremental_check_report.html and check <threshold> (cover lines/new lines).

Ut:
./ut_incremental_check.py UT

Jenkins Configuration Introduction

Example of the Jenkins Job shell command:

# Run UT (cpputest needs to enable Cpputest_use_gcov configuration, here the details are not related to this article, no discussion) bash-ex bspmake ut# generates UT coverage information Lcov--capture--directory tmp/unittest/i2c-v2/ksource-b source/soda/sp/lssp/i2c-v2/unittest/--output-fileCoverage.Info# Generate UT coverage HTML report genhtml coverage.Info-P $WORKSPACE--output-directory coverage# generates an incremental code UT coverage HTML report./ut_incremental_check.py $GIT _previous_successful_commit".."$GIT _commit'["Source/soda/sp/lssp/i2c-v2/ksource"]' "Coverage" 0.8# Return results exit $?

Jenkins HTML Report Configuration example:

--eof--

Delta code UT coverage check based on LCOV implementation

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.