Capturing coverage from the app process
There are two ways to capture coverage from the app/service processes using the SeaLights .NET Core agent
By running the process with our agent using the run option (command wrapper).
By running the SeaLights .NET Core agent as a background listener
The Background Listener option allows you to capture coverage from any application - without changing the command used to run it, but this requires a few more steps than the run
option.
Running the process with the SeaLights .NET Core agent using run
option
run
optionTo capture coverage from a single application, you can run it with the SeaLights .NET agent, which will capture coverage from it when it runs, and tests are run against it.
./sl-dotnet-agent/SL.DotNet.exe run --buildSessionIdFile buildSessionId.txt --instrumentationMode coverage --target c:\MyApplication\App.exe --workingDir c:\WorkingDir --targetArgs "-Flag1 true MyTest.dll"
At the successful completion of this step, you will see new entries appearing in the Cockpit > Live Agents Monitor: the testListener
and a entity called Profiler
with the version details of your application.
Running the SeaLights .NET Core agent as a background listener
To capture coverage from any application without changing the command you use to run it, you can run the SeaLights .NET agent as a background process, which will capture coverage from any process with the SeaLights .NET agent defined as a profiler.
Starting the SeaLights .NET Core agent background listener
To run the background process, you need to use the startBackgroundTestListener flag and provide a unique session key:
dotnet ./sl-dotnet-agent/SL.DotNet.dll startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --testListenerSessionKey SL_CovCollectorAgent
Setting the SeaLights .NET Core agent as a profiler
Now, you need to run (all) your processes - i.e. including your application - with the SeaLights .NET Core agent defined as a profiler. This is done by setting the following environment variables in the shell used to run your process:
[Environment]::SetEnvironmentVariable("CORECLR_ENABLE_PROFILING", "1", "Machine")
[Environment]::SetEnvironmentVariable("CORECLR_PROFILER", "{01CA2C22-DC03-4FF5-8350-59E32A3536BA}", "Machine")
[Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_32", "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x86.dll", "Machine")
[Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_64", "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x64.dll", "Machine")
[Environment]::SetEnvironmentVariable("SL_CollectorId", "SL_CovCollectorAgent", "Machine")
[Environment]::SetEnvironmentVariable("SL_LogDir", "C:\Sealights\logs", "Machine")
[Environment]::SetEnvironmentVariable("SL_LogLevel", "6", "Machine")
Ensure the variables specifying the profiler path are correct, given where you installed the agent binaries (for example:
CORECLR_PROFILER_PATH_32=/usr/local/lib/libSL.DotNet.ProfilerLib.Linux.so
)You should unset the environment variables before running any process that you do not want to capture coverage from
On Windows PowerShell, the
machine
anduser
scopes both persist outside of the current process, allowing you to save a new or changed environment variable.
At the successful completion of this step, after starting your application with its regular command, you will see new entries appearing in the Cockpit > Live Agents Monitor: the testListener
and a entity called Profiler
with the version details of your application.
Stopping the SeaLights .NET Core agent background listener
Once you have finished collecting coverage from the process, you need to stop the background listener. This is done by using the stopBackgroundTestListener flag with the session key previously used
dotnet ./sl-dotnet-agent/SL.DotNet.dll stopBackgroundTestListener --buildSessionIdFile buildSessionId.txt --testListenerSessionKey SL_CovCollectorAgent
Last updated
Was this helpful?