1

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.

C.H.Song
  • 39
  • 6
  • "_Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow_" - From [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) – Ted Lyngmo Jan 20 '21 at 19:22
  • You can filter out entire files, but I'm not sure if there's a way to filter contents of a file. Are the lines you care about in their own files? – Stephen Newell Jan 20 '21 at 19:29

2 Answers2

3

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

  • This means you have to know you way around the application code base, and modify the source code. Most testers (and their manageres) we encounter hate the idea of modifying the code for testing purposes. – Ira Baxter Jan 20 '21 at 21:31
  • @IraBaxter I doubt the tool you are ... promoting ... in your answer will let you do what OP is asking without understanding the code base at least to some extent. And it does say unit tests in the question. Those usually involve writing code dedicated to testing purposes. –  Jan 20 '21 at 22:24
  • All he has to understand with our tool is starting and stopping the program to run a trivial test case or no test case to cover initialization, and starting the program to execute a test case of specific interest. (Yes, he has to have a test case that he thinks will exercise what he wants exercised; that doesn't change what the tool has to do). The tool will collect the test coverage sets, and he can use the tool's built in calculator will compute the delta for him. Sorry if you doubt that it can be this simple. You are welcome to download the tool and try it for yourself. – Ira Baxter Jan 21 '21 at 00:12
  • Regarding "promoting": OP was clear he was interested in a solution if lcov wouldn't do it. I assume if somebody else had mentioned our tool with the same exact answer, it would be OK? – Ira Baxter Jan 21 '21 at 00:15
  • As @dratenik said, we have our code base for testing, so it can be a perfect solution for me. I've read man page before I upload the question, but I may misread that part. Thank you very much. – C.H.Song Jan 21 '21 at 02:10
1

It is important to understand that "coverage" is a set of source code locations. You can do "arithmetic" on sets: union ("add"), complement, difference ("subtract").

The key is to get a tool that will (set)subtract test coverage data sets.

Then you collect test coverage for starting/stopping your program. This covers initialization and setup. Call this set I.

Now collect test coverage for your program executing the activities of interest, e.g., the "communication" part. Call this set X.

What you want is the set computed by subtracting I from X: "X-I" in set notation.

This means you need a tool that will let you collect these sets and do this computation.

I'm sure you can collect X and I with lcov. But I don't think lcov gives you a way to compute the set difference. If it does, bingo, you're in business.

If it doesn't, you might consider using my company's test coverage tools. They provide an explicit means to collect test coverage sets, and do arbitrary set computations, e.g., set unions, set complements, set differencing, in the user interface. You don't need to change your code to do this.

See http://www.semdesigns.com/Products/TestCoverage/

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    That is also a nice suggestion for me. But I thought that modifying the source code a little bit can be a better solution because I have to learn this tool again. Thank you for your answer ! – C.H.Song Jan 21 '21 at 02:13