X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Andrew Wall" Newsgroups: comp.os.msdos.djgpp Subject: Trouble with gpp/gcov Date: Sat, 31 Jul 2004 19:30:39 +0100 Lines: 80 Message-ID: <2n26qfFsa6knU1@uni-berlin.de> X-Trace: news.uni-berlin.de zALmyVDhNUFmNozEb6HE9AsXjXsPy0s/70KdJ07XrpI7riaydp X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi, I'm trying to use gcov to show the coverage my unit tests manage on my software. I'm using Windows XP and gpp/gcov 3.4.1 I can get make/gpp to compile and link and the executables run OK, but gcov doesn't always report the correct coverage. I find that destructors of static class instances are not counted, but are executed. Here's an example: testctor.cpp: #include using namespace std; class Test { public: Test(void){ cout<< "In Test ctor" << endl; } ~Test(void){ cout<< "In Test dtor" << endl; } }T1; int main(void){ // Test T2; cout<< "In main" << endl; return 0; } Batch file to build, run and report coverage: gpp -o testctor.exe testctor.cpp -fprofile-arcs -ftest-coverage -lgcov testctor.exe gcov testctor.cpp The output of the run of testctor.exe: In Test ctor In main In Test dtor This means that the ctor is called before main and the dtor is called after main exits. So far, so good. The output of gcov: File `testctor.cpp' Lines executed:72.73% of 11 testctor.cpp:creating `testctor.cpp.gcov' selected parts of testctor.cpp.gcov: function _ZN4TestD1Ev called 0 returned 0% blocks executed 0% #####: 9: ~Test(void){ #####: 10: cout<< "In Test dtor" << endl; -: 11: } function _Z41__static_initialization_and_destruction_0ii called 1 returned 100% blocks executed 76% 2: 18:} function _GLOBAL__I_T1 called 1 returned 100% blocks executed 100% 2: 19:/*EOF*/ function _GLOBAL__D_T1 called 0 returned 0% blocks executed 0% #####: 20:/*EOF*/ It seems that 3 out of 11 lines did not execute. Notice the commented out line in main: // Test T2; If I uncomment this line and rerun then gcov reports 100% line coverage, but I'm sure some of the individual counts are wrong: 4: 9: ~Test(void){ function _GLOBAL__D_T1 called 0 returned 0% blocks executed 0% 1: 10: cout<< "In Test dtor" << endl; -: 11: } What does the count of 4 mean on line 9. The count of 1 on line 10 should be 2. Any ideas anyone? -- Andrew Wall