Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 26 Next »

There are two ways to capture coverage from windows processes using the SeaLights .NET agent

  1. By running the process with our agent using the testListener option

  2. By running the SeaLights .NET agent as a background listener

The Background Listener option allows you to capture coverage from any application without changing the command you use to run it but requires few more steps than testListener option.

Prerequisites

Microsoft run-time components

Install Microsoft Visual C++ Redistributable for Visual Studio 2017 from: https://www.visualstudio.com/downloads/

You can use the PowerShell commands below to install these prerequisites via a script

iwr -OutFile vc_redist.x86.exe -UseBasicParsing -Uri https://go.microsoft.com/fwlink/?LinkId=746571 
Start-Process -FilePath vc_redist.x86.exe -ArgumentList "/Q" -Wait
iwr -OutFile vc_redist.x64.exe -UseBasicParsing -Uri https://go.microsoft.com/fwlink/?LinkId=746572 
Start-Process -FilePath vc_redist.x64.exe -ArgumentList "/Q" -Wait

Agent Token and Proxy settings

If needed, configure the coverage collector service by editing the SL.DotNet.CoverageCollectorService.exe.config file:

  • If you have not placed the sltoken.txt in the agents' folder, then in Sealights.Token put the token you've received from SeaLights

  • If a proxy is used, add a key named 'Sealights.Proxy' and set the value to a URL like "http://127.0.0.1:8888"

Running the process with the SeaLights .NET agent using the testListener option

To 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.exe testListener --buildSessionIdFile buildSessionId.txt --target c:\MyApplication\App.exe --workingDir c:\WorkingDir --targetArgs "-Flag1 true MyTest.dll"

The sample command above is replacing the regular command used to startup the application captured: c:\MyApplication\App.exe -Flag1 true MyTest.dll executed from the c:\WorkingDir directory

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 agent as a background listener

To capture coverage from any application without changing the command you run, you can execute the SeaLights .NET agent as a background process, which will capture coverage from any process with the SeaLights .NET agent attached as a profiler.

The expected steps are then:

  1. Start the Sealights .NET background listener

  2. Set up the environment variable to enable the Sealights .NET Profiler

  3. Start your application

Starting the SeaLights .NET agent background listener

To run the background process, you use the startBackgroundTestListener flag and provide a unique session key:

SL.DotNet.exe startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --testListenerSessionKey SL_CovCollectorAgent

Setting the SeaLights .NET agent as a profiler

Now, you need to run (all) your processes - i.e., including your application - with the SeaLights .NET agent defined as a profiler before starting your application.
This is done by setting the following environment variables in the shell used to run your process:

  • Cor_Profiler set to {01CA2C22-DC03-4FF5-8350-59E32A3536BA}

  • Cor_Enable_Profiling set to 1

  • Cor_Profiler_Path_32 set to the path of SL.DotNet.ProfilerLib_x86.dll

  • Cor_Profiler_Path_64 set to the path of SL.DotNet.ProfilerLib_x64.dll

  • SL_CollectorId set to the same session key provided to the startBackgroundTestListener command

You should unset the environment variables before running any process that you do not want to capture coverage from

Setting the environment variables for the Profiler agent

You can use the following PowerShell commands to declare the environment variables required by the agent to attach to your application as a Profiler

$Cor_Profiler="{01CA2C22-DC03-4FF5-8350-59E32A3536BA}"
$Cor_Enable_Profiling="1"
$Cor_Profiler_Path_32="C:\Sealights\SL.DotNet\x86\SL.DotNet.ProfilerLib_x86.dll"
$Cor_Profiler_Path_64="C:\Sealights\SL.DotNet\x64\SL.DotNet.ProfilerLib_x64.dll"
$SL_CollectorId="SL_CovCollectorAgent"
#SL_LogDir="C:\Sealights\logs"
#SL_LogLevel="6"

In order to validate the environment variables were properly set you can execute the following PowerShell command: Get-Variable *Cor_*,*SL_*,*Sealights_*

 Setting the profiler in Windows Command prompt

If you’re using CMD, you can use the following commands

set Cor_Profiler={01CA2C22-DC03-4FF5-8350-59E32A3536BA}
set Cor_Enable_Profiling=1
set Cor_Profiler_Path_32=c:\sealights\x64\SL.DotNet.ProfilerLib_x86.dll
set Cor_Profiler_Path_64=c:\sealights\x64\SL.DotNet.ProfilerLib_x64.dll
set SL_CollectorId=SL_CovCollectorAgent
 Setting the profiler in Team City

In TeamCity, you can use the dedicated service message in your build script to dynamically update these build parameters right from a build step so that the following build steps will run with a modified set of build parameters.

echo "##teamcity[setParameter name='env.Cor_Profiler' value='{01CA2C22-DC03-4FF5-8350-59E32A3536BA}']"
echo "##teamcity[setParameter name='env.Cor_Enable_Profiling' value='1']"
echo "##teamcity[setParameter name='env.Cor_Profiler_Path_32' value='c:\sealights\x64\SL.DotNet.ProfilerLib_x86.dll']"
echo "##teamcity[setParameter name='env.Cor_Profiler_Path_64' value='c:\sealights\x64\SL.DotNet.ProfilerLib_x64.dll']"
echo "##teamcity[setParameter name='env.SL_CollectorId' value='SL_CovCollectorAgent']"

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 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

SL.DotNet.exe stopBackgroundTestListener --buildSessionIdFile buildSessionId.txt --testListenerSessionKey SL_CovCollectorAgent

See 'SeaLights .NET - command reference' for full parameter details of all the commands listed above.

  • No labels