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