C + + code coverage generation

Source: Internet
Author: User
Tags gcov

There is only one source code file in the initial state

[Email protected]:testcov> lstest.c[email Protected]:testcov>
The first step: compiling, linking, executing the executable file
Gcc-o a-coverage Test.c-lgcov &&. A

The required record file (*.GCDA,*.GCNO) is generated

[Email protected]:testcov> LSA  test.c  test.gcda  test.gcno[email protected]:testcov>
Step two: Analyze the target file
[Email protected]:testcov>'test.c'Lines executed:100.00  -  'test.c.gcov'[email protected]:testcov>

This will generate *.gcov files, which may have more than one of the files we only need to open the Gcov file corresponding to the target file.

[Email protected]:testcov> vim Test.c.gcov

The results are as follows

-:0: source:test.c-:0: Graph:test.gcno-:0:D ATA:TEST.GCDA-:0: Runs:1-:0:P Rograms:1-:1: #include <stdio.h>-:2:        -:3:Charvisit[Wuyi]; -:4:intans[Wuyi]; -:5:intN; -:6:intcnt[ One]; -:7:    #####:    8:voidForemptycheck ()-:9:{    #####:   Ten: Puts (" Here"); #####:    One:}        -: A:        -: -:intSum ()-: -:{        -: the:intI, j, Sum =0;  -: -: for(i =0; i < N; ++i) { the: -:intMin =Ans[i]; 336: -: for(j = i; j < N; + +)j) { -: +:if(Ans[j] <min) {        -: -: Min =Ans[j]; -: +:            }        -: A:        }        the: at: Sum + =min; -: -:    }        -: -:    ++Cnt[sum];  -: -:returnSum; -: -:}        -: -:        -: in:voidDFS (intSintCNT)-: -:{        -: to:inti;  -: +:Charover =1;  -: -: visit[s] =1;  -: the: ans[cnt] = s +1;  the: *: for(i =0; i < N; ++i) { the: $:if(!Visit[i]) {        -:Panax Notoginseng: over =0;  -: -: DFS (i, CNT +1);  -: the: visit[i] =0; -: +:        }        -: A:    }        -: the:if(over) { -: +: for(i =0; i < N; ++i) { the: -: printf ("%d", Ans[i]); -: $:        }        -: $: printf ("\t%d\n", Sum ()); -: -:    }        -: -:}        -: the:        1: -:intMain ()-:Wuyi:{        -: the:inti; 1: -: N =4; 5: Wu: for(i =0; i < N; ++i) {4: -: DFS (I,0); 4: About: visit[i] =0; -: $:    }        8: -: for(i=4; i<=Ten; ++i)-: -:    {        7: -: printf ("%d", Cnt[i]); -: A:    }        1: +: Puts (""); 1: the:return 0; -: -:}

where Foremptycheck () is preceded by the word "#####" of the token string, indicating that the function has not been called;

Sum () preceded by a labeled number "24", indicating that the function was called 24 times, just corresponding to the 4!=24

C + + code coverage generation

Related Article

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.