Skip to content

Commit

Permalink
Enable the app host feature for AnyCPU scenario as well. (#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
singhsarab authored Sep 17, 2019
1 parent 55e7e45 commit 041133f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Visible>False</Visible>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x64' AND '$(OS)' == 'Windows_NT'" >
<ItemGroup Condition=" '$(Platform)' != 'x86' AND '$(OS)' == 'Windows_NT'" >
<Content Include="$(MSBuildThisFileDirectory)x64\testhost.exe">
<Link>testhost.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
6 changes: 3 additions & 3 deletions src/vstest.console/CommandLine/InferHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internal InferHelper(IAssemblyMetadataProvider assemblyMetadataProvider)
/// <summary>
/// Determines Architecture from sources.
/// </summary>
public Architecture AutoDetectArchitecture(List<string> sources, IDictionary<string, Architecture> sourcePlatforms)
public Architecture AutoDetectArchitecture(List<string> sources, IDictionary<string, Architecture> sourcePlatforms, Architecture defaultArchitecture)
{
Architecture architecture = Constants.DefaultPlatform;
var architecture = defaultArchitecture;
try
{
if (sources != null && sources.Count > 0)
Expand Down Expand Up @@ -64,7 +64,7 @@ public Architecture AutoDetectArchitecture(List<string> sources, IDictionary<str

if (!finalArch.Equals(arch))
{
finalArch = Constants.DefaultPlatform;
finalArch = defaultArchitecture;
EqtTrace.Info("Conflict in platform architecture, using default platform:{0}", finalArch);
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sou
var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings();

settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, registrar, out Framework chosenFramework);
settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, out Architecture chosenPlatform);

// Choose default architecture based on the framework
// For .NET core, the default platform architecture should be x64.
var defaultArchitecture = chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0
|| chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0 ? Architecture.X64 : Architecture.X86;

settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform);
this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar);
settingsUpdated |= this.UpdateDesignMode(document, runConfiguration);
settingsUpdated |= this.UpdateCollectSourceInformation(document, runConfiguration);
Expand Down Expand Up @@ -460,10 +466,10 @@ private void CheckSourcesForCompatibility(Framework chosenFramework, Architectur
}
}

private bool UpdatePlatform(XmlDocument document, XPathNavigator navigator, List<string> sources, IDictionary<string, Architecture> sourcePlatforms, out Architecture chosenPlatform)
private bool UpdatePlatform(XmlDocument document, XPathNavigator navigator, List<string> sources, IDictionary<string, Architecture> sourcePlatforms, Architecture defaultArchitecture, out Architecture chosenPlatform)
{
// Get platform from sources
var inferedPlatform = inferHelper.AutoDetectArchitecture(sources, sourcePlatforms);
var inferedPlatform = inferHelper.AutoDetectArchitecture(sources, sourcePlatforms, defaultArchitecture);

// Get platform from runsettings
bool updatePlatform = IsAutoPlatformDetectRequired(navigator, out chosenPlatform);
Expand Down
29 changes: 15 additions & 14 deletions test/vstest.console.UnitTests/CommandLine/InferHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class InferHelperTests
private readonly Mock<IAssemblyMetadataProvider> mockAssemblyHelper;
private InferHelper inferHelper;
private readonly Framework defaultFramework = Framework.DefaultFramework;
private readonly Architecture DefaultArchitecture = Architecture.X64;
private readonly Framework frameworkNet45 = Framework.FromString(".NETFramework,Version=4.5");
private readonly Framework frameworkNet46 = Framework.FromString(".NETFramework,Version=4.6");
private readonly Framework frameworkNet47 = Framework.FromString(".NETFramework,Version=4.7");
Expand All @@ -38,46 +39,46 @@ public InferHelperTests()
[TestMethod]
public void AutoDetectArchitectureShouldReturnDefaultArchitectureOnNullSources()
{
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(null, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(null, sourceArchitectures, DefaultArchitecture));
}

[TestMethod]
public void AutoDetectArchitectureShouldReturnDefaultArchitectureOnEmptySources()
{
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>(0), sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>(0), sourceArchitectures, DefaultArchitecture));
}

[TestMethod]
public void AutoDetectArchitectureShouldReturnDefaultArchitectureOnNullItemInSources()
{
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>(){null}, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>(){null}, sourceArchitectures, DefaultArchitecture));
}

[TestMethod]
public void AutoDetectArchitectureShouldReturnDefaultArchitectureOnWhiteSpaceItemInSources()
{
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { " "}, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { " "}, sourceArchitectures, DefaultArchitecture));
}

[TestMethod]
public void AutoDetectArchitectureShouldReturnCorrectArchForOneSource()
{
this.mockAssemblyHelper.Setup(ah => ah.GetArchitecture(It.IsAny<string>())).Returns(Architecture.X86);
Assert.AreEqual(Architecture.X86, inferHelper.AutoDetectArchitecture(new List<string>(){"1.dll"}, sourceArchitectures));
Assert.AreEqual(Architecture.X86, inferHelper.AutoDetectArchitecture(new List<string>(){"1.dll"}, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()));
}

[TestMethod]
public void AutoDetectArchitectureShouldReturnCorrectDefaultArchForNotDotNetAssembly()
{
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { "NotDotNetAssebly.appx" }, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { "NotDotNetAssebly.appx" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Never);
}

[TestMethod]
public void AutoDetectArchitectureShouldSetAnyCpuArchForNotDotNetAssembly()
{
inferHelper.AutoDetectArchitecture(new List<string>() { "NotDotNetAssebly.appx" }, sourceArchitectures);
inferHelper.AutoDetectArchitecture(new List<string>() { "NotDotNetAssebly.appx" }, sourceArchitectures, DefaultArchitecture);
Assert.AreEqual(Architecture.AnyCPU, sourceArchitectures["NotDotNetAssebly.appx"]);
}

Expand All @@ -86,7 +87,7 @@ public void AutoDetectArchitectureShouldReturnDefaultArchForAllAnyCpuAssemblies(
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU).Returns(Architecture.AnyCPU).Returns(Architecture.AnyCPU);
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "AnyCPU2.exe", "AnyCPU3.dll" }, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "AnyCPU2.exe", "AnyCPU3.dll" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(3));
}

Expand All @@ -95,7 +96,7 @@ public void AutoDetectArchitectureShouldReturnX86ArchIfOneX86AssemblyAndRestAnyC
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU).Returns(Architecture.AnyCPU).Returns(Architecture.X86);
Assert.AreEqual(Architecture.X86, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "AnyCPU2.exe", "x86.dll" }, sourceArchitectures));
Assert.AreEqual(Architecture.X86, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "AnyCPU2.exe", "x86.dll" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(3));
}

Expand All @@ -104,7 +105,7 @@ public void AutoDetectArchitectureShouldReturnARMArchIfOneARMAssemblyAndRestAnyC
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.ARM).Returns(Architecture.ARM).Returns(Architecture.ARM);
Assert.AreEqual(Architecture.ARM, inferHelper.AutoDetectArchitecture(new List<string>() { "ARM1.dll", "ARM2.dll", "ARM3.dll" }, sourceArchitectures));
Assert.AreEqual(Architecture.ARM, inferHelper.AutoDetectArchitecture(new List<string>() { "ARM1.dll", "ARM2.dll", "ARM3.dll" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(3));
}

Expand All @@ -113,7 +114,7 @@ public void AutoDetectArchitectureShouldReturnX64ArchIfOneX64AssemblyAndRestAnyC
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU).Returns(Architecture.AnyCPU).Returns(Architecture.X64);
Assert.AreEqual(Architecture.X64, inferHelper.AutoDetectArchitecture(new List<string>() { "x64.dll", "AnyCPU2.exe", "x64.dll" }, sourceArchitectures));
Assert.AreEqual(Architecture.X64, inferHelper.AutoDetectArchitecture(new List<string>() { "x64.dll", "AnyCPU2.exe", "x64.dll" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(3));
}

Expand All @@ -122,7 +123,7 @@ public void AutoDetectArchitectureShouldReturnDefaultArchOnConflictArches()
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU).Returns(Architecture.X64).Returns(Architecture.X86);
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "x64.exe", "x86.dll" }, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "x64.exe", "x86.dll" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(3));
}

Expand All @@ -132,7 +133,7 @@ public void AutoDetectArchitectureShouldPoulateSourceArchitectureDictionary()
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU).Returns(Architecture.X64).Returns(Architecture.X86);

Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "x64.exe", "x86.dll" }, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "x64.exe", "x86.dll" }, sourceArchitectures, DefaultArchitecture));
Assert.AreEqual(3, sourceArchitectures.Count);
Assert.AreEqual(Architecture.AnyCPU, sourceArchitectures["AnyCPU1.dll"]);
Assert.AreEqual(Architecture.X64, sourceArchitectures["x64.exe"]);
Expand All @@ -146,7 +147,7 @@ public void AutoDetectArchitectureShouldReturnDefaultArchIfthereIsNotDotNetAssem
{
this.mockAssemblyHelper.SetupSequence(ah => ah.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.AnyCPU);
Assert.AreEqual(Constants.DefaultPlatform, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "NotDotNetAssebly.appx" }, sourceArchitectures));
Assert.AreEqual(DefaultArchitecture, inferHelper.AutoDetectArchitecture(new List<string>() { "AnyCPU1.dll", "NotDotNetAssebly.appx" }, sourceArchitectures, DefaultArchitecture));
this.mockAssemblyHelper.Verify(ah => ah.GetArchitecture(It.IsAny<string>()), Times.Exactly(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void DiscoverTestsShouldCollectMetrics()

var payload = new DiscoveryRequestPayload()
{
Sources = new List<string>() { "a", "b" },
Sources = new List<string>() { "a.dll", "b.dll" },
RunSettings = @"<RunSettings>
<RunConfiguration>
<MaxCpuCount>2</MaxCpuCount>
Expand Down Expand Up @@ -1063,7 +1063,7 @@ public void RunTestsShouldCollectMetrics()

var payload = new TestRunRequestPayload()
{
Sources = new List<string>() { "a" },
Sources = new List<string>() { "a.dll" },
RunSettings = @"<RunSettings>
<RunConfiguration>
<MaxCpuCount>2</MaxCpuCount>
Expand Down

0 comments on commit 041133f

Please sign in to comment.