Skip to content

Commit

Permalink
Fix to determine assembly PlatformTarget for AnyCpu assemblies (#1210)
Browse files Browse the repository at this point in the history
* Fix to determine assembly PlatformTarget for AnyCpu assemblies

* Fix perf project dependency

* update test.ps1

* Set fail fast based on trx file

* Update test for release config

* Remove AssemblyMetadataProviderPerfTests

* Remove no required friend

* Fix nit

* Add seperate project from x86 and ARM platforms

* Update acceptance tests
  • Loading branch information
smadala authored Oct 24, 2017
1 parent cfb1e22 commit bfac13d
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 191 deletions.
17 changes: 16 additions & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26913.4001
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}"
EndProject
Expand Down Expand Up @@ -157,6 +157,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{0D4DF78D-7
scripts\perf\perfconfig.csv = scripts\perf\perfconfig.csv
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vstest.console.PlatformTests", "test\vstest.console.PlatformTests\vstest.console.PlatformTests.csproj", "{8C068694-23A2-47A2-A0DD-DB82D0AF0142}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -767,6 +769,18 @@ Global
{826CD5AF-44FA-40F6-B731-3980CADED8C0}.Release|x64.Build.0 = Release|Any CPU
{826CD5AF-44FA-40F6-B731-3980CADED8C0}.Release|x86.ActiveCfg = Release|Any CPU
{826CD5AF-44FA-40F6-B731-3980CADED8C0}.Release|x86.Build.0 = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|x64.ActiveCfg = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|x64.Build.0 = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|x86.ActiveCfg = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Debug|x86.Build.0 = Debug|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|Any CPU.Build.0 = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|x64.ActiveCfg = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|x64.Build.0 = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|x86.ActiveCfg = Release|Any CPU
{8C068694-23A2-47A2-A0DD-DB82D0AF0142}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -834,6 +848,7 @@ Global
{21DB138B-85B7-479E-91FE-01E0F972EC56} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{826CD5AF-44FA-40F6-B731-3980CADED8C0} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
{0D4DF78D-7E5F-4516-B19F-E6AA71A1DBF4} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{8C068694-23A2-47A2-A0DD-DB82D0AF0142} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD}
Expand Down
117 changes: 58 additions & 59 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ $env:NUGET_PACKAGES = $env:TP_PACKAGES_DIR
#
$TPT_TargetFrameworkFullCLR = "net451"
$TPT_TargetFrameworkCore = "netcoreapp1.0"
$TPT_TargetFramework20Core = "netcoreapp2.0"
$TPT_TargetFrameworkCore20 = "netcoreapp2.0"
Write-Verbose "Setup build configuration."
$Script:TPT_Configuration = $Configuration
$Script:TPT_SourceFolders = @("test")
$Script:TPT_TargetFrameworks =@($TPT_TargetFrameworkCore, $TPT_TargetFrameworkFullCLR)
$Script:TPT_TargetFrameworks =@($TPT_TargetFrameworkCore, $TPT_TargetFrameworkFullCLR, $TPT_TargetFrameworkCore20)
$Script:TPT_TargetFramework = $TargetFramework
$Script:TPT_TargetRuntime = $TargetRuntime
$Script:TPT_SkipProjects = @("_none_");
Expand Down Expand Up @@ -119,6 +119,7 @@ function Print-FailedTests($TrxFilePath)
Write-Log "TrxFile: $TrxFilePath doesn't exists"
return
}

$xdoc = [xml] (get-content $TrxFilePath)
$FailedTestCaseDetailsDict = @{}
# Get failed testcase data from UnitTestResult tag.
Expand All @@ -141,7 +142,8 @@ function Print-FailedTests($TrxFilePath)
}

Set-ScriptFailed
if ($Script:TPT_FailFast) {
if ($Script:TPT_FailFast)
{
Write-Log ".. Stop execution since fail fast is enabled."
continue
}
Expand All @@ -155,7 +157,8 @@ function Invoke-Test

Write-Log "Invoke-Test: Start test."

foreach ($src in $Script:TPT_SourceFolders) {
foreach ($src in $Script:TPT_SourceFolders)
{
Write-Log ".. Test: Computing sources"
Get-ChildItem -Recurse -Path $src -Include *.csproj | Where-Object { $_.FullName -inotmatch "TestAssets" } | ForEach-Object {
$testContainerName = $_.Directory.Name
Expand All @@ -164,102 +167,102 @@ function Invoke-Test

$skip = "False"

foreach ($project in $Script:TPT_SkipProjects) {
foreach ($project in $Script:TPT_SkipProjects)
{
if($_.Name.Contains($project))
{
$skip="True"
break
}
}

if ($skip -eq "True") {
if ($skip -eq "True")
{
Write-Log ".. . $testContainerName is in skipped test list."
} elseif (!($testContainerName -match $Script:TPT_Pattern)) {
}
elseif (!($testContainerName -match $Script:TPT_Pattern))
{
Write-Log ".. . $testContainerName doesn't match test container pattern '$($Script:TPT_Pattern)'. Skipped from run."
} else {
}
else
{
$testContainers += ,"$testContainerPath"
}
}

# Invoke test for each project since we want a custom output path
foreach ($fx in $Script:TPT_TargetFrameworks) {
foreach ($fx in $Script:TPT_TargetFrameworks)
{
Write-Log ".. Start run ($fx)"
if ($Script:TPT_TargetFramework -ne "" -and $fx -ne $Script:TPT_TargetFramework) {
if ($Script:TPT_TargetFramework -ne "" -and $fx -ne $Script:TPT_TargetFramework)
{
Write-Log ".. . Skipped framework based on user setting."
continue;
}

# Tests are only built for x86 at the moment, though we don't have architecture requirement
$testAdapterPath = Get-TestAdapterPath
$testArchitecture = ($Script:TPT_TargetRuntime).Split("-")[-1]
if (-not [System.String]::IsNullOrEmpty($TPT_TestFilter))
{
$testFilter = "/testCaseFilter:`"$TPT_TestFilter`""
}

if($fx -eq $TPT_TargetFrameworkCore)
if($fx -eq $TPT_TargetFrameworkCore -or $fx -eq $TPT_TargetFrameworkCore20)
{
$testFrameWork = ".NETCoreApp,Version=v1.0"
$vstestConsoleFileName = "vstest.console.dll"
$targetRunTime = ""
$vstestConsolePath = Join-Path (Get-PackageDirectory $TPT_TargetFramework20Core $targetRuntime) $vstestConsoleFileName
} else {

$testFrameWork = ".NETFramework,Version=v4.5.1"
$vstestConsolePath = Join-Path (Get-PackageDirectory $TPT_TargetFrameworkCore20 $targetRuntime) $vstestConsoleFileName
}
else
{
$vstestConsoleFileName = "vstest.console.exe"
$targetRunTime = $Script:TPT_TargetRuntime
$vstestConsolePath = Join-Path (Get-PackageDirectory $TPT_TargetFrameworkFullCLR $targetRuntime) $vstestConsoleFileName
}

if (!(Test-Path $vstestConsolePath)) {
if (!(Test-Path $vstestConsolePath))
{
Write-Log "Unable to find $vstestConsoleFileName at $vstestConsolePath. Did you run build.cmd?"
Write-Error "Test aborted."
}

if ($TPT_Parallel) {
if ($TPT_Parallel)
{
# Fill in the framework in test containers
$testContainerSet = $testContainers | % {
$testContainerPath = [System.String]::Format($_, $fx)
if (Test-Path $testContainerPath) {
if (Test-Path $testContainerPath)
{
$testContainerPath
}
}
$trxLogFileName = [System.String]::Format("Parallel_{0}_{1}", $fx, $Script:TPT_DefaultTrxFileName)

# Remove already existed trx file name as due to which warning will get generated and since we are expecting result in a particular format, that will break
$fullTrxFilePath = Join-Path $Script:TPT_TestResultsDir $trxLogFileName
if([System.IO.File]::Exists($fullTrxFilePath)) {
if([System.IO.File]::Exists($fullTrxFilePath))
{
Remove-Item $fullTrxFilePath
}

Set-TestEnvironment
if($fx -eq $TPT_TargetFrameworkFullCLR) {
if($fx -eq $TPT_TargetFrameworkFullCLR)
{

Write-Verbose "$vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel /logger:`"trx;LogFileName=$trxLogFileName`" $testFilter"
$output = & $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;LogFileName=$trxLogFileName" $testFilter
} else {
Write-Verbose "$vstestConsolePath $testContainerSet /parallel /logger:`"trx;LogFileName=$trxLogFileName`" $testFilter"
& $vstestConsolePath $testContainerSet /parallel /logger:"trx;LogFileName=$trxLogFileName" $testFilter
}
else
{

Write-Verbose "$dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel /logger:`"trx;LogFileName=$trxLogFileName`" $testFilter"
$output = & $dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;LogFileName=$trxLogFileName" $testFilter
Write-Verbose "$dotNetPath $vstestConsolePath $testContainerSet /parallel /logger:`"trx;LogFileName=$trxLogFileName`" $testFilter"
& $dotNetPath $vstestConsolePath $testContainerSet /parallel /logger:"trx;LogFileName=$trxLogFileName" $testFilter
}

Reset-TestEnvironment

if ($output[-3].Contains("Test Run Successful.")) {
Write-Log ".. . $($output[-4])"
} else {
Write-Log ".. . $($output[-3])"
Write-Log ".. . Failed tests:" $Script:TPT_ErrorMsgColor
Print-FailedTests (Join-Path $Script:TPT_TestResultsDir $trxLogFileName)

Set-ScriptFailed

if ($Script:TPT_FailFast) {
Write-Log ".. Stop execution since fail fast is enabled."
continue
}
}
} else {
Print-FailedTests (Join-Path $Script:TPT_TestResultsDir $trxLogFileName)
}
else
{
$testContainers | % {
# Fill in the framework in test containers
$testContainer = [System.String]::Format($_, $fx)
Expand All @@ -274,22 +277,25 @@ function Invoke-Test

# Remove already existed trx file name as due to which warning will get generated and since we are expecting result in a particular format, that will break
$fullTrxFilePath = Join-Path $Script:TPT_TestResultsDir $trxLogFileName
if([System.IO.File]::Exists($fullTrxFilePath)) {
if([System.IO.File]::Exists($fullTrxFilePath))
{
Remove-Item $fullTrxFilePath
}

Write-Log ".. Container: $testContainer"

Set-TestEnvironment

if($fx -eq $TPT_TargetFrameworkFullCLR) {

Write-Verbose "$vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /logger:`"trx;LogFileName=$trxLogFileName`" $ConsoleLogger $testFilter"
& $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;LogFileName=$trxLogFileName" $ConsoleLogger $testFilter
} else {
if($fx -eq $TPT_TargetFrameworkFullCLR)
{

Write-Verbose "$dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /logger:`"trx;LogFileName=$trxLogFileName`" $ConsoleLogger $testFilter"
& $dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;LogFileName=$trxLogFileName" $ConsoleLogger $testFilter
Write-Verbose "$vstestConsolePath $testContainer /logger:`"trx;LogFileName=$trxLogFileName`" $ConsoleLogger $testFilter"
& $vstestConsolePath $testContainer /logger:"trx;LogFileName=$trxLogFileName" $ConsoleLogger $testFilter
}
else
{
Write-Verbose "$dotNetPath $vstestConsolePath $testContainer /logger:`"trx;LogFileName=$trxLogFileName`" $ConsoleLogger $testFilter"
& $dotNetPath $vstestConsolePath $testContainer /logger:"trx;LogFileName=$trxLogFileName" $ConsoleLogger $testFilter
}

Reset-TestEnvironment
Expand All @@ -312,13 +318,6 @@ function Get-PackageDirectory($framework, $targetRuntime)
return $(Join-Path $env:TP_OUT_DIR "$($Script:TPT_Configuration)\$($framework)\$($targetRuntime)")
}

function Get-TestAdapterPath
{
[xml]$dependencyProps = Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props

return "$env:TP_PACKAGES_DIR\MSTest.TestAdapter\$($dependencyProps.Project.PropertyGroup.MSTestAdapterVersion)\build\_common"
}

function Start-Timer
{
return [System.Diagnostics.Stopwatch]::StartNew()
Expand Down
2 changes: 1 addition & 1 deletion src/package/package/package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<TargetFrameworks>net451;netcoreapp2.0;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net451;netcoreapp2.0</TargetFrameworks>
<AssemblyName>package</AssemblyName>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
Expand Down
22 changes: 16 additions & 6 deletions src/vstest.console/CommandLine/AssemblyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FrameworkName GetFrameWork(string filePath)

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Determined framework:'{0}' for source: '{1}'", frameworkName, filePath);
EqtTrace.Info("AssemblyMetadataProvider.GetFrameWork: Determined framework:'{0}' for source: '{1}'", frameworkName, filePath);
}

return frameworkName;
Expand All @@ -52,24 +52,34 @@ public Architecture GetArchitecture(string assemblyPath)
try
{
// AssemblyName won't load the assembly into current domain.
archType = MapToArchitecture(new AssemblyName(assemblyPath).ProcessorArchitecture);
var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
archType = MapToArchitecture(assemblyName.ProcessorArchitecture);
}
catch (Exception)
catch (Exception ex)
{
// AssemblyName will thorw Exception if assembly contains native code or no manifest.

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("AssemblyMetadataProvider.GetArchitecture: Failed get ProcessorArchitecture using AssemblyName API with exception: {0}", ex);
}

try
{
archType = GetArchitectureForSource(assemblyPath);
}
catch (Exception ex)
catch (Exception e)
{
EqtTrace.Error("Failed to determine Assembly Architecture: {0}", ex);
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("AssemblyMetadataProvider.GetArchitecture: Failed to determine Assembly Architecture with exception: {0}", e);
}
}
}

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("GetArchitecture: determined architecture:{0} info for assembly: {1}", archType,
EqtTrace.Info("AssemblyMetadataProvider.GetArchitecture: Determined architecture:{0} info for assembly: {1}", archType,
assemblyPath);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vstest.console/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#region Test Assemblies

[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.PerformanceTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.PlatformTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

#endregion
2 changes: 1 addition & 1 deletion src/vstest.console/vstest.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>vstest.console</AssemblyName>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0;net451</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net451</TargetFrameworks>
<WarningsAsErrors>true</WarningsAsErrors>
<OutputType>Exe</OutputType>
<PlatformTarget Condition="'$(TargetFramework)' == 'net451'">AnyCPU</PlatformTarget>
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ public void IncompatibleSourcesWarningShouldBeDisplayedInTheConsole(RunnerInfo r
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var expectedWarningContains = @"Following DLL(s) do not match framework/platform settings.SimpleTestProject3.dll is built for Framework 4.5.1 and Platform X64";
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll", "SimpleTestProject2.dll").Trim('\"');
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll", "SimpleTestProjectx86.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /testcasefilter:PassingTest2");
arguments = string.Concat(arguments, " /testcasefilter:PassingTestx86");

this.InvokeVsTest(arguments);

Expand Down
Loading

0 comments on commit bfac13d

Please sign in to comment.