views:

516

answers:

1

Hi,

my microsoft-based development environment looks like this: - huge native c++ codebase, seperated into 10 projects - each project has a dependent test project (GoogleTest unit tests), the sources to test are simply referenced.

I generated the coverage-report using vsinstr and vsperfmon (the visual studio tools for instrumenting/monitoring executeables and dlls), but that wasn't as satisfying as i expected because the report shows only the coverage of the unit-test lines, not of the sources under test (I instrumented the testsuite-executeable Sample_Project_Test.exe).

For example if i have a method like this:

(Sample_Project/add_ints.cpp)

int add(int a, int b){
  return a+b;
}

int add2(int a, int b){
  if (a == b)
    return a * 2;
  else
    return a+b;
}

and the unit test is like this:

(Sample_Project_Test/int_adds_tests.cpp)    

TEST(AddTest, ReturnsCorrectSum) 
{
  EXPECT_EQ(4, add(2,2));
}

I get a line coverage of 100% because ONLY the add-part in add_ints.cpp is measured, add2 seemes to be completely removed because it is not touched. As far as I did not understand the whole coverage thing wrong this seems not correct?

Thanks in advance!

+1  A: 

Do you have any optimization enabled in your build settings?
Maybe those links would help you: /GL (Whole Program Optimization) and /LTCG (Link-time Code Generation)

Dmitry
thanks for that hint but enabling/disabling the flags didn't change anything. I think that points in the right direction, the code seems either to be not listed because its percentage is 0% or 'removed' from the executeable so that it can't be instrumented.
lakai