Skip to content

Commit

Permalink
Merge branch 'master' into fqn
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Nov 15, 2020
2 parents 2035b97 + b5bcdfe commit f86a987
Show file tree
Hide file tree
Showing 229 changed files with 2,134 additions and 1,086 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ src/package/sign/sign.nuget.targets
# Vscode files
# ===========================
.vscode/

# ===========================
# diag log files
# ===========================
logs/
18 changes: 15 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,25 @@ jobs:
testResultsFormat: VSTest
testResultsFiles: '**\*.trx'
condition: succeededOrFailed()

- job: Linux

- job:
workspace:
clean: all
strategy:
matrix:
Ubuntu_18_04:
vmImage: ubuntu-18.04
pwsh: true
macOS_10_15_Catalina:
vmImage: macOS-10.15
pwsh: true
pool:
vmImage: 'ubuntu-18.04'
vmImage: $[ variables['vmImage'] ]
variables:
buildConfiguration: 'Release'
steps:
- script: ./build.sh -c $(buildConfiguration)
displayName: './build.sh -c $(buildConfiguration)'
- script: ./test.sh -c $(buildConfiguration)
displayName: './test.sh -c $(buildConfiguration)'

48 changes: 12 additions & 36 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,36 +226,6 @@ function Restore-Package
& $dotnetExe restore $env:TP_ROOT_DIR\src\package\external\external.csproj --packages $env:TP_PACKAGES_DIR -v:minimal -warnaserror -p:Version=$TPB_Version
Write-Log ".. .. Restore-Package: Complete."

# Fixing a problem with procdump package
# $procdumpFolder = "$env:TP_PACKAGES_DIR\procdump\0.0.1"
# if (-not (Test-Path "$procdumpFolder\bin") -and -not $CIBuild)
# {
# Add-Type -AssemblyName System.IO.Compression.FileSystem

# $zip = $null
# try {
# $zip = [System.IO.Compression.ZipFile]::Open("$procdumpFolder\procdump.0.0.1.nupkg", 0)
# $zip.Entries | Where-Object { $_.FullName.StartsWith("bin/") } | ForEach-Object {
# $file = "$procdumpFolder\$($_.FullName)"
# $fi = [System.IO.Path]::GetDirectoryName($file)
# if (-not (Test-Path $fi)) {
# New-Item -Type Directory -Path $fi -Force
# }

# if (-not (Test-Path $file)) {
# [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $file, $true)
# }
# }
# }
# finally
# {
# if ($null -ne $zip)
# {
# $zip.Dispose()
# }
# }
# }

Set-ScriptFailedOnError

Write-Log "Restore-Package: Complete. {$(Get-ElapsedTime($timer))}"
Expand Down Expand Up @@ -404,28 +374,34 @@ function Publish-Package

# Copy the .NET core x86 and x64 testhost exes from tempPublish to required folder
New-Item -ItemType directory -Path $testhostCore20PackageX64Dir -Force | Out-Null
Copy-Item $testhostCore20PackageTempX64Dir\testhost* $testhostCore20PackageX64Dir -Force -recurse
Copy-Item $testhostCore20PackageTempX64Dir\testhost* $testhostCore20PackageX64Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempX64Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore20PackageX64Dir -Force

New-Item -ItemType directory -Path $testhostCore20PackageX86Dir -Force | Out-Null
Copy-Item $testhostCore20PackageTempX86Dir\testhost.x86* $testhostCore20PackageX86Dir -Force -recurse
Copy-Item $testhostCore20PackageTempX86Dir\testhost.x86* $testhostCore20PackageX86Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempX86Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore20PackageX86Dir -Force

New-Item -ItemType directory -Path $testhostCore10PackageX64Dir -Force | Out-Null
Copy-Item $testhostCore10PackageTempX64Dir\testhost* $testhostCore10PackageX64Dir -Force -recurse
Copy-Item $testhostCore10PackageTempX64Dir\testhost* $testhostCore10PackageX64Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempX64Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore10PackageX64Dir -Force

New-Item -ItemType directory -Path $testhostCore10PackageX86Dir -Force | Out-Null
Copy-Item $testhostCore10PackageTempX86Dir\testhost.x86* $testhostCore10PackageX86Dir -Force -recurse
Copy-Item $testhostCore10PackageTempX86Dir\testhost.x86* $testhostCore10PackageX86Dir -Force -Recurse
Copy-Item $testhostCore10PackageTempX86Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore10PackageX86Dir -Force

# Copy over the Full CLR built testhost package assemblies to the Core CLR and Full CLR package folder.
$coreCLRFull_Dir = "TestHost"
$fullDestDir = Join-Path $coreCLR20PackageDir $coreCLRFull_Dir
New-Item -ItemType directory -Path $fullDestDir -Force | Out-Null
Copy-Item $testhostFullPackageDir\* $fullDestDir -Force -recurse
Copy-Item $testhostFullPackageDir\* $fullDestDir -Force -Recurse

Set-ScriptFailedOnError

# Copy over the Full CLR built datacollector package assemblies to the Core CLR package folder along with testhost
Publish-PackageInternal $dataCollectorProject $TPB_TargetFramework472 $fullDestDir

New-Item -ItemType directory -Path $fullCLRPackage451Dir -Force | Out-Null
Copy-Item $testhostFullPackageDir\* $fullCLRPackage451Dir -Force -recurse
Copy-Item $testhostFullPackageDir\* $fullCLRPackage451Dir -Force -Recurse

Set-ScriptFailedOnError

Expand Down
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>16.9.0-preview-4189539</TestPlatformExternalsVersion>
<CodeCoverageExternalsVersion>16.9.0-beta.20552.5</CodeCoverageExternalsVersion>
<CodeCoverageExternalsVersion>16.9.0-beta.20563.1</CodeCoverageExternalsVersion>
<MicrosoftFakesVersion>16.8.0-beta.20420.2</MicrosoftFakesVersion>

<MicrosoftBuildPackageVersion>16.0.461</MicrosoftBuildPackageVersion>
Expand Down
8 changes: 4 additions & 4 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ done
#
# Variables
#
PROJECT_NAME_PATTERNS=**Unit*bin*$CONFIGURATION*netcoreapp1.0*UnitTests*dll
PROJECT_NAME_PATTERNS=**Unit*bin*$CONFIGURATION*netcoreapp2.1*UnitTests*dll
TP_ROOT_DIR=$(cd "$(dirname "$0")"; pwd -P)
TP_TOOLS_DIR="$TP_ROOT_DIR/tools"
TP_PACKAGES_DIR="$TP_ROOT_DIR/packages"
Expand All @@ -67,7 +67,7 @@ DOTNET_CLI_VERSION="latest"
# Build configuration
#
TPB_Solution="TestPlatform.sln"
TPB_TargetFrameworkCore="netcoreapp2.0"
TPB_TargetFrameworkCore="netcoreapp2.1"
TPB_Configuration=$CONFIGURATION
TPB_TargetRuntime=$TARGET_RUNTIME
TPB_Verbose=$VERBOSE
Expand Down Expand Up @@ -111,15 +111,15 @@ function invoke_test()
local dotnet=$(_get_dotnet_path)
local vstest=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore/vstest.console.dll

find ./test -path $PROJECT_NAME_PATTERNS | xargs --verbose $dotnet $vstest --parallel
find ./test -path $PROJECT_NAME_PATTERNS | xargs $dotnet $vstest --parallel --testcasefilter:"TestCategory!=Windows"
}

#
# Privates
#
_get_dotnet_path()
{
echo "$TP_TOOLS_DIR/dotnet/dotnet"
echo "$TP_TOOLS_DIR/dotnet-linux/dotnet"
}

invoke_test
4 changes: 2 additions & 2 deletions scripts/verify-nupkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ function Verify-Nuget-Packages($packageDirectory)
{
Write-Log "Starting Verify-Nuget-Packages."
$expectedNumOfFiles = @{
"Microsoft.CodeCoverage" = 43;
"Microsoft.CodeCoverage" = 44;
"Microsoft.NET.Test.Sdk" = 18;
"Microsoft.TestPlatform" = 488;
"Microsoft.TestPlatform.Build" = 19;
"Microsoft.TestPlatform.CLI" = 350;
"Microsoft.TestPlatform.Extensions.TrxLogger" = 33;
"Microsoft.TestPlatform.ObjectModel" = 178;
"Microsoft.TestPlatform.Portable" = 566;
"Microsoft.TestPlatform.TestHost" = 213;
"Microsoft.TestPlatform.TestHost" = 212;
"Microsoft.TestPlatform.TranslationLayer" = 121}

$nugetPackages = Get-ChildItem -Filter "*.nupkg" $packageDirectory | % { $_.FullName}
Expand Down
4 changes: 4 additions & 0 deletions scripts/verify-sign.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function Verify-Assemblies
elseif ($signature.SignerCertificate.Thumbprint -eq "899FA016DEE8E665FF2A315A1151C43FB96C430B") {
Write-Log "Valid (Prod Signed): $($_.FullName)."
}
# Microsoft 3rd Party Application Component
elseif ($signature.SignerCertificate.Thumbprint -eq "709133ECC53CBF386F4A5ECB782AEEF499F0F8CA") {
Write-Log "Valid (Prod Signed): $($_.FullName)."
}
else {
Write-FailLog "Incorrect certificate. File: $($_.FullName). Certificate: $($signature.SignerCertificate.Thumbprint)."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ public class DynamicCoverageDataCollector : BaseDataCollector
private const string ClrIeDisableCodeSignatureValidationVariable = @"MicrosoftInstrumentationEngine_DisableCodeSignatureValidation";
private const string ClrieFileLogPathVariable = @"MicrosoftInstrumentationEngine_FileLogPath";

private const string InjectDotnetAdditionalDepsSettingName = "InjectDotnetAdditionalDeps";
private const string VanguardDotnetAdditionalDepsVariable = "VANGUARD_DOTNET_ADDITIONAL_DEPS";

private readonly IEnvironment environment;
private bool useClrIeInstrumentationForNetCore;
private bool useClrIeInstrumentationForNetFramework;
private bool injectDotnetAdditionalDeps;

/// <summary>
/// Data collector implementation
Expand Down Expand Up @@ -116,6 +120,7 @@ protected override void OnInitialize(XmlElement configurationElement)
{
this.useClrIeInstrumentationForNetCore = IsClrInstrumentationEnabled(configurationElement, ClrIeInstrumentationForNetCoreSettingName, ClrIeInstrumentationForNetCoreVariable);
this.useClrIeInstrumentationForNetFramework = IsClrInstrumentationEnabled(configurationElement, ClrIeInstrumentationForNetFrameworkSettingName, ClrIeInstrumentationForNetFrameworkVariable);
this.injectDotnetAdditionalDeps = GetConfigurationValue(configurationElement, InjectDotnetAdditionalDepsSettingName) ?? true;

this.implementation.Initialize(configurationElement, this.DataSink, this.Logger);
this.Events.SessionStart += this.SessionStart;
Expand Down Expand Up @@ -177,6 +182,11 @@ protected override IEnumerable<KeyValuePair<string, string>> GetEnvironmentVaria
envVaribles.Add(new KeyValuePair<string, string>(ClrieFileLogPathVariable, Path.Combine(Path.GetTempPath(), this.implementation.GetSessionName(), Guid.NewGuid() + ".log")));
}

if (this.injectDotnetAdditionalDeps && !string.IsNullOrEmpty(this.implementation.CodeCoverageDepsJsonFilePath))
{
envVaribles.Add(new KeyValuePair<string, string>(VanguardDotnetAdditionalDepsVariable, this.implementation.CodeCoverageDepsJsonFilePath));
}

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("DynamicCoverageDataCollector.GetEnvironmentVariables: Returning following environment variables: {0}", string.Join(",", envVaribles));
Expand All @@ -194,10 +204,9 @@ protected override IEnumerable<KeyValuePair<string, string>> GetEnvironmentVaria
/// <returns>If CLR IE should be enabled</returns>
private static bool IsClrInstrumentationEnabled(XmlElement configurationElement, string configurationSettingName, string environmentVariableName)
{
XmlElement configurationSetting = configurationElement != null ? configurationElement[configurationSettingName] : null;
string configurationSettingValue = configurationSetting != null ? configurationSetting.InnerText : null;
var clrInstrumentationEnabledByConfiguration = GetConfigurationValue(configurationElement, configurationSettingName);

if (bool.TryParse(configurationSettingValue, out var clrInstrumentationEnabled) && clrInstrumentationEnabled)
if (clrInstrumentationEnabledByConfiguration == true)
{
return true;
}
Expand All @@ -211,6 +220,22 @@ private static bool IsClrInstrumentationEnabled(XmlElement configurationElement,
return int.TryParse(environmentVariableValue, out var environmentVariableIntValue) && environmentVariableIntValue > 0;
}

/// <summary>
/// Check flag in configuration
/// </summary>
/// <param name="configurationElement">Configuration</param>
/// <param name="configurationSettingName">Configuration setting name</param>
/// <returns>Flag value in configuration. Null if not present.</returns>
private static bool? GetConfigurationValue(XmlElement configurationElement, string configurationSettingName)
{
if (bool.TryParse(configurationElement?[configurationSettingName]?.InnerText, out var settingValue))
{
return settingValue;
}

return null;
}

/// <summary>
/// On session end
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,70 @@ internal class DynamicCoverageDataCollectorImpl : IDynamicCoverageDataCollectorI
/// </summary>
private const string VanguardConfigFileName = "CodeCoverage.config";

/// <summary>
/// File name of deps.json file with reference to Microsoft.VisualStudio.CodeCoverage.Shim.dll.
/// </summary>
private const string CodeCoverageDepsJsonFileName = "CodeCoverage.deps.json";

/// <summary>
/// Name of element for custom coverage filename.
/// </summary>
private const string CoverageFileSettingName = "CoverageFileName";

private const string CodeCoverageDepsJsonTemplate = @"
{{
""runtimeTarget"": {{
""name"": ""codecoverage"",
""signature"": """"
}},
""targets"": {{
""codecoverage"": {{
""Microsoft.VisualStudio.CodeCoverage.Shim/15.0.0.0"": {{
""runtime"": {{
""{0}"": {{ }}
}}
}}
}}
}},
""libraries"": {{
""Microsoft.VisualStudio.CodeCoverage.Shim/15.0.0.0"": {{
""type"": ""reference"",
""serviceable"": false,
""sha512"": """"
}}
}}
}}
";

/// <summary>
/// Coverage file name
/// Directory helper
/// </summary>
private string coverageFileName;
private readonly IDirectoryHelper directoryHelper;

/// <summary>
/// Logger
/// Profilers location provider
/// </summary>
private IDataCollectionLogger logger;
private readonly IProfilersLocationProvider profilersLocationProvider;

/// <summary>
/// Data sink
/// File helper
/// </summary>
private TraceCollector.IDataCollectionSink dataSink;
private readonly IFileHelper fileHelper;

/// <summary>
/// Directory helper
/// Coverage file name
/// </summary>
private IDirectoryHelper directoryHelper;
private string coverageFileName;

/// <summary>
/// File helper
/// Logger
/// </summary>
private IDataCollectionLogger logger;

/// <summary>
/// Data sink
/// </summary>
private IFileHelper fileHelper;
private TraceCollector.IDataCollectionSink dataSink;

/// <summary>
/// Folder to store temporary files
Expand All @@ -71,17 +106,23 @@ internal class DynamicCoverageDataCollectorImpl : IDynamicCoverageDataCollectorI
private string coverageFilePath;

public DynamicCoverageDataCollectorImpl()
: this(new Vanguard(), new DirectoryHelper(), new FileHelper())
: this(new Vanguard(), new DirectoryHelper(), new FileHelper(), new ProfilersLocationProvider())
{
}

internal DynamicCoverageDataCollectorImpl(IVanguard vanguard, IDirectoryHelper directoryHelper, IFileHelper fileHelper)
internal DynamicCoverageDataCollectorImpl(IVanguard vanguard, IDirectoryHelper directoryHelper, IFileHelper fileHelper, IProfilersLocationProvider profilersLocationProvider)
{
this.Vanguard = vanguard;
this.directoryHelper = directoryHelper;
this.fileHelper = fileHelper;
this.profilersLocationProvider = profilersLocationProvider;
}

/// <summary>
/// Gets path to deps.json file with reference to Microsoft.VisualStudio.CodeCoverage.Shim.dll.
/// </summary>
public string CodeCoverageDepsJsonFilePath { get; private set; }

/// <summary>
/// Gets or sets session name
/// </summary>
Expand Down Expand Up @@ -295,9 +336,12 @@ private void PrepareVanguardProcess(XmlElement configurationElement)
?? DynamicCoverageDataCollectorImpl.GetDefaultConfiguration()[ConfigCodeCoverageElementName];

string configurationFileName = Path.Combine(this.sessionDirectory, VanguardConfigFileName);

this.fileHelper.WriteAllText(configurationFileName, config.OuterXml);

this.CodeCoverageDepsJsonFilePath = Path.Combine(this.sessionDirectory, CodeCoverageDepsJsonFileName);
var codeCoverageDepsJsonContent = this.profilersLocationProvider.GetCodeCoverageShimPath()?.Replace(@"\", "/");
this.fileHelper.WriteAllText(this.CodeCoverageDepsJsonFilePath, string.Format(CodeCoverageDepsJsonTemplate, codeCoverageDepsJsonContent));

EqtTrace.Info("DynamicCoverageDataCollectorImpl.PrepareVanguardProcess: Initializing with config: {0}.", config.OuterXml);
this.Vanguard.Initialize(this.SessionName, configurationFileName, this.logger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.VisualStudio.Coverage.Interfaces
/// </summary>
internal interface IDynamicCoverageDataCollectorImpl : IDisposable
{
string CodeCoverageDepsJsonFilePath { get; }

string GetSessionName();

void Initialize(
Expand Down
Loading

0 comments on commit f86a987

Please sign in to comment.