microsoft / codecoverage

MIT License
73 stars 12 forks source link

No blocks covered using static instrumentation #120

Closed KavenBreton-eaton closed 1 month ago

KavenBreton-eaton commented 2 months ago

Hello,

Since we have a lot of Windows services running from which we want to gather code coverage, we decided to instrument all our binaries using dotnet-coverage instrument -s "C:\dev\localCoverageTest\codecoverage.runsettings" -id "Project.CodeCoverage" "c:\file\path" We are then starting collection using dotnet-coverage collect -id "Project.CodeCoverage" --server-mode -s "C:\dev\localCoverageTest\codecoverage.runsettings" Our runsettings file looks like this `<?xml version="1.0" encoding="utf-8"?>

All All Info C:\dev\localCoverageTest\dotnet-coverage-collect.log C:\dev\localCoverageTest\fam.coverage coverage True True True False False False False True True C:\dev\GitHub\etn-utilities\fam-solution\bin\Release\pdb False C:\dev\localCoverageTest\file-log.log All ` When loading the resulting .coverage file, I can see a bunch of blocks detected but nothing was covered. [dotnet-coverage-collect.log](https://github.com/microsoft/codecoverage/files/15325509/dotnet-coverage-collect.log) Am I missing something in the logs that could indicate the problem?
KavenBreton-eaton commented 2 months ago

I forgot to add that our project is in C# .NET Framework 4.8

fhnaseer commented 2 months ago

Is this the same service you mentioned here? https://github.com/microsoft/codecoverage/issues/96

From the logs, I can see that dlls are being loaded and eventually added in the final report. Can you please check if server and service are running under same credentials? Administrator mode?

KavenBreton-eaton commented 2 months ago

Yes, same as #96 I think it might be related to the user since our services are running under Local System. Is it possible to do or would I have to make our services run under another user? Do both the command prompt from where I start the collection and the service need to be in Administrator mode?

KavenBreton-eaton commented 2 months ago

After more testing, I was able to get coverage from our client application but not our services. Even if I make our services runs as the same user, I never get a block covered for them. I also tried starting the collection in a not elevated command prompt. l also tried starting a command prompt using the Local System user.

fhnaseer commented 2 months ago

Do you have Visual Studio Enterprise? If yes, then can you please try using Microsoft.CodeCoverage.Console.exe from VS? It has same commands as of dotnet-coverage. You can specify users in the runsettings file. https://github.com/microsoft/codecoverage/blob/967a10da1decde0f185c88aaba0d586fbd51ae34/docs/configuration.md?plain=1#L97 https://learn.microsoft.com/en-us/visualstudio/test/microsoft-code-coverage-console-tool?view=vs-2022

KavenBreton-eaton commented 1 month ago

I am going to test it. Is there anything really different from dotnet-coverage itsefl?

fhnaseer commented 1 month ago

Microsoft.CodeCoverage.Console.exe is built against net framework while dotnet-coverage is net core.

This could be because of security features available in net framework but not available in net core.

KavenBreton-eaton commented 1 month ago

https://learn.microsoft.com/en-us/answers/questions/1470826/how-do-i-use-microsoft-codecoverage-console-exe-in It was asked here but it seems like I won't be able to use that tool on our test VMs anyway. Is it worth trying anyway?

fhnaseer commented 1 month ago

https://learn.microsoft.com/en-us/answers/questions/1470826/how-do-i-use-microsoft-codecoverage-console-exe-in It was asked here but it seems like I won't be able to use that tool on our test VMs anyway. Is it worth trying anyway?

You can use it if you install dotnet framework on VM.

KavenBreton-eaton commented 1 month ago

Thank you. Using the Microsoft CodeCoverage console allowed us to gather the coverage from our services.