How to measure code coverage of the part of execution in C++

I have two C++ binaries (A and B) with socket connections between two binaries.
Binary A is listening for B. And, B connects to the A.

A accepts B’s message and executes some functions depending on message contents.
We created a kind of unit-test to test various message types.

From these tests, I would like to measure A’s executed line from our test messages.
I searched for tools to measure code coverage, and I found lcov.

However, lcov measured total executed lines of code including initialization and other useless chunks.
I may create a new code to test functionality without socket connection.
But the code structure is complex, so it takes very long time to implement tests.

So, I would like to skip those lines in lcov to obtain purely executed lines caused by our test messages.

If it is impossible and there is a better tool for this situation, please recommend suitable tools to measure this.

Thanks.

Answer

Call __gcov_reset before your testcases to discard the data collected from initialization.

Leave a Reply

Your email address will not be published. Required fields are marked *