• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Codejie's C++ Space

            Using C++

            Why the inline function can not be covered?


            Please have a look the following codes, they include two source files (source.h, source.c), one test file (test_source.c) and one makefile file.

            //source.h
             1 #ifndef __SOURCE_H__
             2 #define __SOURCE_H__
             3 
             4 #include <stdio.h>
             5 
             6 inline void inline_test()
             7 {
             8     printf("\nthis is the inline function.");
             9 }
            10 
            11 void normal_test();
            12 
            13 #endif

            //source.c
            1 #include "source.h"
            2 
            3 void normal_test()
            4 {
            5     printf("\nThis is a normal function.");
            6 }

            //test_source.c
             1 #include "source.h"
             2 
             3 void test_inline() 
             4 {
             5     inline_test();
             6 }
             7 
             8 void test_normal()
             9 {
            10     normal_test();
            11 }
            12 
            13 int main()
            14 {
            15     test_inline();
            16     test_normal();
            17     
            18     return 0;
            19 }


            //makefile
             1 TEST = test_source.o
             2 
             3 TARGET = a.exe
             4 
             5 all: $(TARGET)
             6 
             7 $(TARGET):$(SOURCE) $(TEST)
             8     gcc -Xlinker --allow-multiple-definition $^ -fprofile-arcs -ftest-coverage -o $(TARGET)    
             9 
            10 $(SOURCE): %.o:%.c
            11     gcc -MM -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
            12     gcc -c $< -o $@ -fprofile-arcs -ftest-coverage
            13     
            14 $(TEST): %.o:%.c
            15     gcc -MM -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
            16     gcc -c $< -o $@   
            17  
            18 clean:
            19     -rm -rf $(DIR_COVERAGE)
            22     -rm -rf *.d *.o *.gcda *.gcno $(TARGET)

            ...

            My purpose is that get the UT line coverage report of source files by running the test file. I guess I should get the below report of line coverage, because I have called every functions of source file in test file, include the inline function and the normal function.

            But after run test file, I got the report is just 50%, the inline function has not been covered. Why? Why it is not be covered? I am sure it is called in test file.
            OK, Calming down. If it is not covered, there are two reason, one is that the inline function is not be called, of course it is impossible, because we did it. So the root cause must be the second one that gcov/lcov tools do not process those lines of inline function. Have any idea? gcov/lcov tools process all files with compilation parameters '-fprofile-arcs -ftest-coverage', so let's check makefile file again.
            Look here, source files have the compilation paraments, but why normal function has been coverage, but inline function not?

            $(SOURCE): %.o:%.c
                gcc -MM -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
                gcc -c $< -o $@ -fprofile-arcs -ftest-coverage

            Thinking again, as we knew, the difference between inline function and normal function is just that inline function will be inserted source code while compiling period. Yes, the answer is here! While compiling, the inline function is put into test file, but the test file has not '-fprofile-arcs -ftest-coverage' paramenter. So, so it was not covered.

            $(TEST): %.o:%.c
                gcc -MM -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
                gcc -c $< -o $@

            To fix it, just add the parameter to test file while compiling. OK, let's update the makefile file like the below line.

            $(TEST): %.o:%.c
                gcc -MM -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
                gcc -c $< -o $@ -fprofile-arcs -ftest-coverage    

            Done, enjoy it!

            posted on 2012-09-21 17:45 codejie 閱讀(2861) 評(píng)論(2)  編輯 收藏 引用 所屬分類: C++ 、隨筆而已

            評(píng)論

            # re: Why the inline function can not be coveraged? 2012-09-26 19:35 smagle

            gcov原理分析詳細(xì)可參考:http://sdet.org/?p=212  回復(fù)  更多評(píng)論   

            # re: Why the inline function can not be coveraged?[未登錄] 2012-09-26 22:16 codejie

            @smagle
            very great article. thanks!  回復(fù)  更多評(píng)論   

            公告

            Using C++

            導(dǎo)航

            統(tǒng)計(jì)

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲中文久久精品无码ww16| 久久精品国产精品国产精品污| 99精品久久久久久久婷婷| 久久99精品久久久久久水蜜桃| 亚洲伊人久久综合中文成人网| 亚洲精品国产字幕久久不卡| 9999国产精品欧美久久久久久| 狠狠色丁香久久婷婷综合蜜芽五月| 精品国产VA久久久久久久冰| 三级片免费观看久久| 精品国产91久久久久久久 | 少妇高潮惨叫久久久久久 | 一本久久综合亚洲鲁鲁五月天| 亚洲国产欧洲综合997久久| 久久国产成人亚洲精品影院| 久久天天躁狠狠躁夜夜96流白浆| 久久这里有精品视频| 国产精品免费久久久久久久久| 精品久久久久久久无码| 久久AV无码精品人妻糸列| 精品无码人妻久久久久久| 久久91精品国产91久久户| 久久精品国产亚洲AV无码娇色 | 久久久久久久综合日本| 久久91亚洲人成电影网站| 久久99精品国产麻豆| 亚洲精品国产美女久久久| 中文字幕日本人妻久久久免费| 亚洲精品久久久www| 久久久久久亚洲精品影院| 性高朝久久久久久久久久| 午夜精品久久久久成人| 久久久精品人妻无码专区不卡| 久久久国产精品| 四虎影视久久久免费观看| 日本久久久久久久久久| 亚洲国产高清精品线久久| 亚洲午夜久久久| 亚洲色欲久久久综合网东京热| 久久久久久国产精品无码超碰| 国产精品久久久久久福利漫画 |