Code Coverage for Windows Service Runs using System Account

Jul 22, 2015 at 6:48 AM
Hello,
I am trying to use OpenCppCoverage for a Windows Service which runs using System Account. How can I use command line?
Thanks.
Coordinator
Jul 22, 2015 at 9:37 PM
Hello,

Interesting use case.

From https://msdn.microsoft.com/en-us/en-en/library/d56de412%28v=vs.110%29.aspx
"you cannot immediately run a service or step into its code. Instead, you must install and start your service, and then attach a debugger to the service's process"

As you cannot attach OpenCppCoverage to a running process, I am not sure it is possible to run OpenCppCoverage for a service.

As a workaround, if it is possible for you, you can split your service into 3 projects:
  • Library projects: Contains all your code
  • Service project: Contains only the code specific for the service
  • Console project: Contains only main function that call your library
In this way, it will also be easier for debugging your service.

I will still investigate deeper in Window Service and give you more feedback.

Hope that help,

OpenCppCoverage
Coordinator
Aug 2, 2015 at 10:16 AM
Hello,

As a service is run directly by the system (service.exe), you cannot run OpenCppCoverage on a service.
In the same idea as the workaround in the previous message, you can add a command line argument that runs directly the code of your service and skips the service initialization parts.

Hope that help,

OpenCppCoverage
Marked as answer by OpenCppCoverage on 11/15/2015 at 3:37 AM