-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for architecture switch feature
- Loading branch information
1 parent
d39826a
commit 71d8605
Showing
10 changed files
with
556 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
329 changes: 329 additions & 0 deletions
329
test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
test/Microsoft.TestPlatform.SmokeTests/DotnetHostArchitectureVerifierTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.SmokeTests | ||
{ | ||
using Microsoft.TestPlatform.TestUtilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
[TestClass] | ||
// On Linux/Mac we don't download the same .NET SDK bundles | ||
[TestCategory("Windows-Review")] | ||
public class DotnetHostArchitectureVerifierTests : IntegrationTestBase | ||
{ | ||
[TestMethod] | ||
[DataRow("X64")] | ||
[DataRow("X86")] | ||
public void VerifyHostArchitecture(string architecture) | ||
{ | ||
using (Workspace workSpace = new Workspace(GetResultsDirectory())) | ||
{ | ||
string dotnetPath = GetDownloadedDotnetMuxerFromTools(architecture); | ||
var vstestConsolePath = GetDotnetRunnerPath(); | ||
var dotnetRunnerPath = workSpace.CreateDirectory("dotnetrunner"); | ||
workSpace.CopyAll(new DirectoryInfo(Path.GetDirectoryName(vstestConsolePath)), dotnetRunnerPath); | ||
|
||
// Patch the runner | ||
string sdkVersion = GetLatestSdkVersion(dotnetPath); | ||
string runtimeConfigFile = Path.Combine(dotnetRunnerPath.FullName, "vstest.console.runtimeconfig.json"); | ||
JObject patchRuntimeConfig = JObject.Parse(File.ReadAllText(runtimeConfigFile)); | ||
patchRuntimeConfig["runtimeOptions"]["framework"]["version"] = sdkVersion; | ||
File.WriteAllText(runtimeConfigFile, patchRuntimeConfig.ToString()); | ||
|
||
var environmentVariables = new Dictionary<string, string> | ||
{ | ||
["DOTNET_MULTILEVEL_LOOKUP"] = "0", | ||
["ExpectedArchitecture"] = $"{architecture}" | ||
}; | ||
|
||
this.ExecuteApplication(dotnetPath, "new mstest", out string stdOut, out string stdError, out int exitCode, environmentVariables, workSpace.Path); | ||
|
||
// Patch test file | ||
File.WriteAllText(Path.Combine(workSpace.Path, "UnitTest1.cs"), | ||
@" | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
namespace cfebbc5339cf4c22854e79824e938c74; | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
Assert.AreEqual(Environment.GetEnvironmentVariable(""ExpectedArchitecture""), System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString()); | ||
} | ||
}"); | ||
|
||
|
||
this.ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\"", out stdOut, out stdError, out exitCode, environmentVariables, workSpace.Path); | ||
Assert.AreEqual(0, exitCode, stdOut); | ||
} | ||
} | ||
|
||
private string GetLatestSdkVersion(string dotnetPath) | ||
=> Path.GetFileName(Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(dotnetPath), @"shared/Microsoft.NETCore.App")).OrderByDescending(x => x).First()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace Microsoft.TestPlatform.TestUtilities | ||
{ | ||
public class Workspace : IDisposable | ||
{ | ||
public Workspace(string path) | ||
{ | ||
Path = path; | ||
} | ||
|
||
public string Path { get; } | ||
|
||
public void Dispose() | ||
{ | ||
if (!string.IsNullOrEmpty(Path)) | ||
{ | ||
try | ||
{ | ||
if (Directory.Exists(Path)) | ||
Directory.Delete(Path, true); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
} | ||
} | ||
|
||
public DirectoryInfo CreateDirectory(string dir) => Directory.CreateDirectory(System.IO.Path.Combine(Path, dir)); | ||
|
||
public void CopyAll(DirectoryInfo source, DirectoryInfo target) | ||
{ | ||
Directory.CreateDirectory(target.FullName); | ||
|
||
// Copy each file into the new directory. | ||
foreach (FileInfo fi in source.GetFiles()) | ||
{ | ||
fi.CopyTo(System.IO.Path.Combine(target.FullName, fi.Name), true); | ||
} | ||
|
||
// Copy each subdirectory using recursion. | ||
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) | ||
{ | ||
DirectoryInfo nextTargetSubDir = | ||
target.CreateSubdirectory(diSourceSubDir.Name); | ||
CopyAll(diSourceSubDir, nextTargetSubDir); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/TestAssets/ArchitectureSwitch/ArchitectureSwitch.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net6.0;net5.0</TargetFrameworks> | ||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net6.0;netcoreapp3.1</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0-preview-20211130-02" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.0.2" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Runtime.InteropServices; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace TestProjectNetcore | ||
{ | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
foreach(DictionaryEntry envVar in Environment.GetEnvironmentVariables()) | ||
{ | ||
if(envVar.Key.ToString().StartsWith("DOTNET_ROOT")) | ||
{ | ||
Console.WriteLine($"{envVar.Key}: {envVar.Value.ToString()}"); | ||
} | ||
} | ||
|
||
Console.WriteLine("OSArchitecture: " + RuntimeInformation.OSArchitecture.ToString()); | ||
Console.WriteLine("ProcessArchitecture: " + RuntimeInformation.ProcessArchitecture.ToString()); | ||
Console.WriteLine("Runtime location: " + typeof(object).Assembly.Location); | ||
Assert.IsTrue(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "6.0.200-preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters