Merge pull request #315 from Sergio0694/dev/native-libs-tests
Improve test infrastructure, add Pix tests
このコミットが含まれているのは:
17ファイル変更
+654
-285
検索条件に一致するファイルはありません
+92
-14
@@ -251,23 +251,101 @@ jobs:
|
||||
with:
|
||||
name: nuget_preview
|
||||
path: artifacts
|
||||
- name: Build ComputeSharp.Sample.NuGet (.NET 6)
|
||||
run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release -f net6.0
|
||||
- name: Build ComputeSharp.NuGet (.NET 6)
|
||||
run: dotnet build tests\ComputeSharp.NuGet\ComputeSharp.NuGet.csproj -c Release -f net6.0
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Sample.NuGet (.NET 6)
|
||||
run: dotnet samples\ComputeSharp.Sample.NuGet\bin\Release\net6.0\ComputeSharp.Sample.NuGet.dll
|
||||
- name: Run ComputeSharp.NuGet (.NET 6)
|
||||
run: dotnet tests\ComputeSharp.NuGet\bin\Release\net6.0\ComputeSharp.NuGet.dll
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Sample.NuGet (.NET Core 3.1)
|
||||
run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release -f netcoreapp3.1 -r win-x64
|
||||
- name: Build ComputeSharp.NuGet (.NET Core 3.1)
|
||||
run: dotnet build tests\ComputeSharp.NuGet\ComputeSharp.NuGet.csproj -c Release -f netcoreapp3.1 -r win-x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Sample.NuGet (.NET Core 3.1)
|
||||
run: samples\ComputeSharp.Sample.NuGet\bin\Release\netcoreapp3.1\win-x64\ComputeSharp.Sample.NuGet.exe
|
||||
- name: Run ComputeSharp.NuGet (.NET Core 3.1)
|
||||
run: tests\ComputeSharp.NuGet\bin\Release\netcoreapp3.1\win-x64\ComputeSharp.NuGet.exe
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Sample.NuGet (.NET Framework 4.7.2)
|
||||
run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release -f net472 /p:Platform=x64
|
||||
- name: Build ComputeSharp.NuGet (.NET Framework 4.7.2)
|
||||
run: dotnet build tests\ComputeSharp.NuGet\ComputeSharp.NuGet.csproj -c Release -f net472 /p:Platform=x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Sample.NuGet (.NET Framework 4.7.2)
|
||||
run: samples\ComputeSharp.Sample.NuGet\bin\x64\Release\net472\ComputeSharp.Sample.NuGet.exe
|
||||
- name: Run ComputeSharp.NuGet (.NET Framework 4.7.2)
|
||||
run: tests\ComputeSharp.NuGet\bin\x64\Release\net472\ComputeSharp.NuGet.exe
|
||||
shell: cmd
|
||||
|
||||
# Download the NuGet packages and test the ComputeSharp.Dynamic dependency
|
||||
verify-packages-dynamic:
|
||||
if: success()
|
||||
needs: [build-packages]
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Git checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup .NET 6 SDK
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 6.0.x
|
||||
- name: Create local NuGet feed
|
||||
run: mkdir artifacts
|
||||
shell: cmd
|
||||
- name: Download package artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: nuget_preview
|
||||
path: artifacts
|
||||
- name: Build ComputeSharp.Dynamic.NuGet (.NET 6)
|
||||
run: dotnet build tests\ComputeSharp.Dynamic.NuGet\ComputeSharp.Dynamic.NuGet.csproj -c Release -f net6.0
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Dynamic.NuGet (.NET 6)
|
||||
run: dotnet tests\ComputeSharp.Dynamic.NuGet\bin\Release\net6.0\ComputeSharp.Dynamic.NuGet.dll
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Dynamic.NuGet (.NET Core 3.1)
|
||||
run: dotnet build tests\ComputeSharp.Dynamic.NuGet\ComputeSharp.Dynamic.NuGet.csproj -c Release -f netcoreapp3.1 -r win-x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Dynamic.NuGet (.NET Core 3.1)
|
||||
run: tests\ComputeSharp.Dynamic.NuGet\bin\Release\netcoreapp3.1\win-x64\ComputeSharp.Dynamic.NuGet.exe
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Dynamic.NuGet (.NET Framework 4.7.2)
|
||||
run: dotnet build tests\ComputeSharp.Dynamic.NuGet\ComputeSharp.Dynamic.NuGet.csproj -c Release -f net472 /p:Platform=x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Dynamic.NuGet (.NET Framework 4.7.2)
|
||||
run: tests\ComputeSharp.Dynamic.NuGet\bin\x64\Release\net472\ComputeSharp.Dynamic.NuGet.exe
|
||||
shell: cmd
|
||||
|
||||
# Download the NuGet packages and test the ComputeSharp.Pix dependency
|
||||
verify-packages-pix:
|
||||
if: success()
|
||||
needs: [build-packages]
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Git checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup .NET 6 SDK
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 6.0.x
|
||||
- name: Create local NuGet feed
|
||||
run: mkdir artifacts
|
||||
shell: cmd
|
||||
- name: Download package artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: nuget_preview
|
||||
path: artifacts
|
||||
- name: Build ComputeSharp.Pix.NuGet (.NET 6)
|
||||
run: dotnet build tests\ComputeSharp.Pix.NuGet\ComputeSharp.Pix.NuGet.csproj -c Release -f net6.0
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Pix.NuGet (.NET 6)
|
||||
run: dotnet tests\ComputeSharp.Pix.NuGet\bin\Release\net6.0\ComputeSharp.Pix.NuGet.dll
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Pix.NuGet (.NET Core 3.1)
|
||||
run: dotnet build tests\ComputeSharp.Pix.NuGet\ComputeSharp.Pix.NuGet.csproj -c Release -f netcoreapp3.1 -r win-x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Pix.NuGet (.NET Core 3.1)
|
||||
run: tests\ComputeSharp.Pix.NuGet\bin\Release\netcoreapp3.1\win-x64\ComputeSharp.Pix.NuGet.exe
|
||||
shell: cmd
|
||||
- name: Build ComputeSharp.Pix.NuGet (.NET Framework 4.7.2)
|
||||
run: dotnet build tests\ComputeSharp.Pix.NuGet\ComputeSharp.Pix.NuGet.csproj -c Release -f net472 /p:Platform=x64
|
||||
shell: cmd
|
||||
- name: Run ComputeSharp.Pix.NuGet (.NET Framework 4.7.2)
|
||||
run: tests\ComputeSharp.Pix.NuGet\bin\x64\Release\net472\ComputeSharp.Pix.NuGet.exe
|
||||
shell: cmd
|
||||
|
||||
# Run the extra tests to validate a number of build and publishing configurations.
|
||||
@@ -290,7 +368,7 @@ jobs:
|
||||
|
||||
# Publish the packages to GitHub packages
|
||||
publish-nightlies-github:
|
||||
needs: [ run-dx12-tests, run-d2d1-tests, run-dx12-samples, verify-packages, verify-package-native-libs ]
|
||||
needs: [run-dx12-tests, run-d2d1-tests, run-dx12-samples, verify-packages, verify-packages-dynamic, verify-packages-pix, verify-package-native-libs]
|
||||
runs-on: windows-2022
|
||||
if: ${{github.event_name == 'push'}}
|
||||
steps:
|
||||
@@ -306,7 +384,7 @@ jobs:
|
||||
|
||||
# Publish the packages to Azure DevOps
|
||||
publish-nightlies-azure-devops:
|
||||
needs: [ run-dx12-tests, run-d2d1-tests, run-dx12-samples, verify-packages, verify-package-native-libs ]
|
||||
needs: [run-dx12-tests, run-d2d1-tests, run-dx12-samples, verify-packages, verify-packages-dynamic, verify-packages-pix, verify-package-native-libs]
|
||||
runs-on: windows-2022
|
||||
if: ${{github.event_name == 'push'}}
|
||||
steps:
|
||||
|
||||
+25
-1
@@ -28,7 +28,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_Solution
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SourceGenerators", "src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj", "{EB52CB67-4162-4722-874B-44EA8DA5450E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{FB17EF84-9208-47AC-921F-680CB1DAD8BA}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{FB17EF84-9208-47AC-921F-680CB1DAD8BA}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
src\ComputeSharp.Core.Package\ComputeSharp.Core.Package.msbuildproj = src\ComputeSharp.Core.Package\ComputeSharp.Core.Package.msbuildproj
|
||||
src\ComputeSharp.D2D1.Package\ComputeSharp.D2D1.Package.msbuildproj = src\ComputeSharp.D2D1.Package\ComputeSharp.D2D1.Package.msbuildproj
|
||||
@@ -103,6 +103,27 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Tests.Ass
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Pix", "src\ComputeSharp.Pix\ComputeSharp.Pix.csproj", "{14EF12A3-90E6-4683-BD71-9896AF87026B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ComputeSharp.Dynamic.NuGet", "ComputeSharp.Dynamic.NuGet", "{CBA545B4-31EF-4E9F-A1A8-2A1290B54046}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
tests\ComputeSharp.Dynamic.NuGet\ComputeSharp.Dynamic.NuGet.csproj = tests\ComputeSharp.Dynamic.NuGet\ComputeSharp.Dynamic.NuGet.csproj
|
||||
tests\ComputeSharp.Dynamic.NuGet\nuget.config = tests\ComputeSharp.Dynamic.NuGet\nuget.config
|
||||
tests\ComputeSharp.Dynamic.NuGet\Program.cs = tests\ComputeSharp.Dynamic.NuGet\Program.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ComputeSharp.Pix.NuGet", "ComputeSharp.Pix.NuGet", "{C0B903AA-F32C-4760-B4B6-199AC4FE1C5A}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
tests\ComputeSharp.Pix.NuGet\ComputeSharp.Pix.NuGet.csproj = tests\ComputeSharp.Pix.NuGet\ComputeSharp.Pix.NuGet.csproj
|
||||
tests\ComputeSharp.Pix.NuGet\nuget.config = tests\ComputeSharp.Pix.NuGet\nuget.config
|
||||
tests\ComputeSharp.Pix.NuGet\Program.cs = tests\ComputeSharp.Pix.NuGet\Program.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ComputeSharp.NuGet", "ComputeSharp.NuGet", "{E3403F19-A0D8-4317-8A54-322C7A13F2A2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
tests\ComputeSharp.NuGet\ComputeSharp.NuGet.csproj = tests\ComputeSharp.NuGet\ComputeSharp.NuGet.csproj
|
||||
tests\ComputeSharp.NuGet\nuget.config = tests\ComputeSharp.NuGet\nuget.config
|
||||
tests\ComputeSharp.NuGet\Program.cs = tests\ComputeSharp.NuGet\Program.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -454,6 +475,9 @@ Global
|
||||
{3ACACF03-6B20-40BA-B8EC-11AC1624D2C9} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA}
|
||||
{209C95A3-FA53-431B-B688-3299CA6C29D2} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{94178D51-0097-4AD2-B3D0-827E40D62F2E} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{CBA545B4-31EF-4E9F-A1A8-2A1290B54046} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{C0B903AA-F32C-4760-B4B6-199AC4FE1C5A} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{E3403F19-A0D8-4317-8A54-322C7A13F2A2} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
|
||||
|
||||
-2
@@ -12,6 +12,4 @@
|
||||
<PackageReference Include="ComputeSharp.Dynamic" Version="$(PackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using ComputeSharp;
|
||||
|
||||
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
|
||||
// Create the graphics buffer
|
||||
using ReadWriteBuffer<float> gpuBuffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
GraphicsDevice.Default.For(100, new MultiplyByTwo(gpuBuffer));
|
||||
|
||||
// Get the data back
|
||||
float[] result = gpuBuffer.ToArray();
|
||||
|
||||
// Validate results
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
Trace.Assert(result[i] == array[i] * 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sample kernel that requires dynamic compilation, as it's not precompiled.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MultiplyByTwo : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
差分なしでファイル名を変更。
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComputeSharp.Core" Version="$(PackageVersion)" />
|
||||
<PackageReference Include="ComputeSharp" Version="$(PackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using ComputeSharp;
|
||||
|
||||
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
|
||||
// Create the graphics buffer
|
||||
using ReadWriteBuffer<float> gpuBuffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
GraphicsDevice.Default.For(100, new MultiplyByTwo(gpuBuffer));
|
||||
|
||||
// Get the data back
|
||||
float[] result = gpuBuffer.ToArray();
|
||||
|
||||
// Validate results
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
Trace.Assert(result[i] == array[i] * 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sample kernel that is precompiled.
|
||||
/// </summary>
|
||||
[EmbeddedBytecode(DispatchAxis.X)]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MultiplyByTwo : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
|
||||
<!-- This source is for the local NuGet packages, which are all generated in the centralized artifacts root folder -->
|
||||
<add key="artifacts" value="..\..\artifacts" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComputeSharp.Core" Version="$(PackageVersion)" />
|
||||
<PackageReference Include="ComputeSharp" Version="$(PackageVersion)" />
|
||||
<PackageReference Include="ComputeSharp.Pix" Version="$(PackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using ComputeSharp;
|
||||
|
||||
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
|
||||
// Create the graphics buffer
|
||||
using ReadWriteBuffer<float> gpuBuffer = GraphicsDevice.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
using (var context = GraphicsDevice.Default.CreateComputeContext())
|
||||
{
|
||||
context.Log("Dispatching shader");
|
||||
context.BeginEvent("Dispatching event");
|
||||
context.For(100, new MultiplyByTwo(gpuBuffer));
|
||||
context.EndEvent();
|
||||
}
|
||||
|
||||
// Get the data back
|
||||
float[] result = gpuBuffer.ToArray();
|
||||
|
||||
// Validate results
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
Trace.Assert(result[i] == array[i] * 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sample kernel that is precompiled.
|
||||
/// </summary>
|
||||
[EmbeddedBytecode(DispatchAxis.X)]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MultiplyByTwo : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
|
||||
<!-- This source is for the local NuGet packages, which are all generated in the centralized artifacts root folder -->
|
||||
<add key="artifacts" value="..\..\artifacts" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
+5
@@ -11,4 +11,9 @@
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Project\*" />
|
||||
<None Include="Project\*" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using ComputeSharp.Tests.NativeLibrariesResolver.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.NativeLibrariesResolver;
|
||||
|
||||
[TestClass]
|
||||
public class DynamicNativeLibrariesResolverTests : NativeLibrariesResolverTestsBase
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string SampleProjectName => "ComputeSharp.Dynamic.NuGet";
|
||||
|
||||
/// <summary>
|
||||
/// Performs static initialization for the assembly before any unit tests are run.
|
||||
/// </summary>
|
||||
/// <param name="_">The <see cref="TestContext"/> for the test runner instance in use.</param>
|
||||
[ClassInitialize]
|
||||
public static void InitializeDynamicDependencies(TestContext _)
|
||||
{
|
||||
string path = Path.GetDirectoryName(typeof(DynamicNativeLibrariesResolverTests).Assembly.Location)!;
|
||||
|
||||
while (Path.GetFileName(path) is not "ComputeSharp")
|
||||
{
|
||||
path = Path.GetDirectoryName(path)!;
|
||||
}
|
||||
|
||||
string corePackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Core", "ComputeSharp.Core.msbuildproj");
|
||||
string packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj");
|
||||
string dynamicPackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Dynamic.Package", "ComputeSharp.Dynamic.Package.msbuildproj");
|
||||
|
||||
// Run dotnet pack and on the packaging projects, to ensure the local NuGet packages are available
|
||||
Process.Start("dotnet", $"pack {corePackagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {dynamicPackagingProjectPath} -c Release").WaitForExit();
|
||||
}
|
||||
}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.NativeLibrariesResolver.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A base class to implement native libraries tests.
|
||||
/// </summary>
|
||||
public abstract class NativeLibrariesResolverTestsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the test project.
|
||||
/// </summary>
|
||||
protected abstract string SampleProjectName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directory containing the current test project.
|
||||
/// </summary>
|
||||
private string SampleProjectDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
string path = Path.GetDirectoryName(typeof(NativeLibrariesResolverTestsBase).Assembly.Location)!;
|
||||
|
||||
while (Path.GetFileName(path) is not "tests")
|
||||
{
|
||||
path = Path.GetDirectoryName(path)!;
|
||||
}
|
||||
|
||||
return Path.Combine(path, SampleProjectName);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetRunWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, "dotnet", $"run -c {configuration} -f net6.0 {ToOption(rid)}"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningDotnetHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string realtivePathToDll = Path.Combine("bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}", $"{SampleProjectName}.dll");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, "dotnet", realtivePathToDll));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningDotnetHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string pathToDllDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToDllDirectory, "dotnet", $"{SampleProjectName}.dll"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningAppHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string relativePathToAppHost = Path.Combine("bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}", $"{SampleProjectName}.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, relativePathToAppHost, ""));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningAppHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string pathToAppHostDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToAppHostDirectory, $"{SampleProjectName}.exe", ""));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.Multiassembly, NativeLibrariesDeploymentMode.NotApplicable)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.Multiassembly, NativeLibrariesDeploymentMode.NotApplicable)]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.CopyToApplicationDirectory)]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.CopyToApplicationDirectory)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory)]
|
||||
public void DotnetPublishWorks(PublishMode publishMode, DeploymentMode deploymentMode, NativeLibrariesDeploymentMode nativeLibsDeploymentMode)
|
||||
{
|
||||
// Publishing without specifying a RID is not supported.
|
||||
// Furthermore, only publishing in Release mode is tested.
|
||||
CleanSampleProject(Configuration.Release, RID.Win_x64);
|
||||
|
||||
Exec(SampleProjectDirectory, "dotnet", $"publish -c Release -f net6.0 -r win-x64 {ToOption(publishMode)} {ToOption(deploymentMode)} {ToOption(nativeLibsDeploymentMode)} /bl");
|
||||
|
||||
string pathToAppHost = Path.Combine("bin", $"Release", "net6.0", "win-x64", "publish", $"{SampleProjectName}.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, pathToAppHost, ""));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans the sample project's artifacts for a specific configuration and target runtime.
|
||||
/// This method is called at the start of each test method to work around bugs around some up-to-date checks
|
||||
/// Causing certain targets to not run and effectively corrupting the build output.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration for which the output is cleaned.</param>
|
||||
/// <param name="rid">The RID for which the output is cleaned.</param>
|
||||
private void CleanSampleProject(Configuration configuration, RID rid)
|
||||
{
|
||||
Exec(SampleProjectDirectory, "dotnet", $"clean -c {configuration} {ToOption(rid)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the sample project with a specific configuration and target runtime.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to use to build the project.</param>
|
||||
/// <param name="rid">The RID to use to build the project.</param>
|
||||
private void BuildSampleProject(Configuration configuration, RID rid)
|
||||
{
|
||||
Exec(SampleProjectDirectory, "dotnet", $"build -c {configuration} {ToOption(rid)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a specified process from the command line and returns the exit code.
|
||||
/// </summary>
|
||||
/// <param name="workingDirectory">The working directory to execute the process.</param>
|
||||
/// <param name="filePath">The target file path for the process to execute.</param>
|
||||
/// <param name="arguments">The arguments to invoke the process.</param>
|
||||
/// <returns>The exit code for the executed process.</returns>
|
||||
private static int Exec(string workingDirectory, string filePath, string arguments)
|
||||
{
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
FileName = filePath,
|
||||
Arguments = arguments,
|
||||
WorkingDirectory = workingDirectory
|
||||
};
|
||||
|
||||
using Process process = Process.Start(startInfo)!;
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToOption(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
RID.Win_x64 => "-r win-x64",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="PublishMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="publishMode">The input <see cref="PublishMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="publishMode"/>.</returns>
|
||||
private static string ToOption(PublishMode publishMode) => publishMode switch
|
||||
{
|
||||
PublishMode.FrameworkDependent => "--self-contained false",
|
||||
PublishMode.SelfContained => "--self-contained true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(publishMode), (int)publishMode, typeof(PublishMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="DeploymentMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="deploymentMode">The input <see cref="DeploymentMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="deploymentMode"/>.</returns>
|
||||
private static string ToOption(DeploymentMode deploymentMode) => deploymentMode switch
|
||||
{
|
||||
DeploymentMode.Multiassembly => "/p:PublishSingleFile=false",
|
||||
DeploymentMode.SingleFile => "/p:PublishSingleFile=true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(DeploymentMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="NativeLibrariesDeploymentMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="deploymentMode">The input <see cref="NativeLibrariesDeploymentMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="deploymentMode"/>.</returns>
|
||||
private static string ToOption(NativeLibrariesDeploymentMode deploymentMode) => deploymentMode switch
|
||||
{
|
||||
NativeLibrariesDeploymentMode.NotApplicable => "",
|
||||
NativeLibrariesDeploymentMode.CopyToApplicationDirectory => "/p:IncludeNativeLibrariesForSelfExtract=false",
|
||||
NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory => "/p:IncludeNativeLibrariesForSelfExtract=true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(NativeLibrariesDeploymentMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the build folder for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToDirectory(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
RID.Win_x64 => "win-x64",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A build configuration.
|
||||
/// </summary>
|
||||
public enum Configuration
|
||||
{
|
||||
Debug,
|
||||
Release
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A runtime identifier.
|
||||
/// </summary>
|
||||
public enum RID
|
||||
{
|
||||
None,
|
||||
Win_x64
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how should the application carry the framework with itself.
|
||||
/// </summary>
|
||||
public enum PublishMode
|
||||
{
|
||||
FrameworkDependent,
|
||||
SelfContained
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how should the application be packaged. Notably, these tests employ .NET 6 style SingleFile,
|
||||
/// aka SuperHost. It does not affect native libraries packaging in .NET 6, but may in the future.
|
||||
/// </summary>
|
||||
public enum DeploymentMode
|
||||
{
|
||||
Multiassembly,
|
||||
SingleFile
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the deployment mode for application's native dependencies.
|
||||
/// Not applicable to multiassembly deployment mode.
|
||||
/// </summary>
|
||||
public enum NativeLibrariesDeploymentMode
|
||||
{
|
||||
NotApplicable,
|
||||
ExtractToTemporaryDirectory,
|
||||
CopyToApplicationDirectory
|
||||
}
|
||||
@@ -1,291 +1,35 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)]
|
||||
using ComputeSharp.Tests.NativeLibrariesResolver.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.NativeLibrariesResolver;
|
||||
|
||||
[TestClass]
|
||||
public class NativeLibrariesResolverTests
|
||||
public class NativeLibrariesResolverTests : NativeLibrariesResolverTestsBase
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string SampleProjectName => "ComputeSharp.NuGet";
|
||||
|
||||
/// <summary>
|
||||
/// Performs static initialization for the assembly before any unit tests are run.
|
||||
/// </summary>
|
||||
/// <param name="_">The <see cref="TestContext"/> for the test runner instance in use.</param>
|
||||
[AssemblyInitialize]
|
||||
public static void Initialize(TestContext _)
|
||||
[ClassInitialize]
|
||||
public static void InitializeDynamicDependencies(TestContext _)
|
||||
{
|
||||
string path = Path.GetDirectoryName(typeof(NativeLibrariesResolverTests).Assembly.Location)!;
|
||||
string path = Path.GetDirectoryName(typeof(DynamicNativeLibrariesResolverTests).Assembly.Location)!;
|
||||
|
||||
while (Path.GetFileName(path) is not "ComputeSharp")
|
||||
{
|
||||
path = Path.GetDirectoryName(path)!;
|
||||
}
|
||||
|
||||
SampleProjectDirectory = Path.Combine(path, "samples", "ComputeSharp.Sample.NuGet");
|
||||
|
||||
string corePackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Core", "ComputeSharp.Core.msbuildproj");
|
||||
string packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj");
|
||||
string dynamicPackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Dynamic.Package", "ComputeSharp.Dynamic.Package.msbuildproj");
|
||||
|
||||
// Run dotnet pack and on the packaging projects, to ensure the local NuGet packages are available
|
||||
Process.Start("dotnet", $"pack {corePackagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {dynamicPackagingProjectPath} -c Release").WaitForExit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directory of the ComputeSharp.Sample.NuGet project.
|
||||
/// </summary>
|
||||
private static string? SampleProjectDirectory { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetRunWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory!, "dotnet", $"run -c {configuration} -f net6.0 {ToOption(rid)}"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningDotnetHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string realtivePathToDll = Path.Combine("bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.dll");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory!, "dotnet", realtivePathToDll));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningDotnetHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string pathToDllDirectory = Path.Combine(SampleProjectDirectory!, "bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToDllDirectory, "dotnet", "ComputeSharp.Sample.NuGet.dll"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningAppHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string relativePathToAppHost = Path.Combine("bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory!, relativePathToAppHost, ""));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(Configuration.Debug, RID.None)]
|
||||
[DataRow(Configuration.Debug, RID.Win_x64)]
|
||||
[DataRow(Configuration.Release, RID.None)]
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetBuildWithRunningAppHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
CleanSampleProject(configuration, rid);
|
||||
BuildSampleProject(configuration, rid);
|
||||
|
||||
string pathToAppHostDirectory = Path.Combine(SampleProjectDirectory!, "bin", $"{configuration}", "net6.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToAppHostDirectory, "ComputeSharp.Sample.NuGet.exe", ""));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.Multiassembly, NativeLibrariesDeploymentMode.NotApplicable)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.Multiassembly, NativeLibrariesDeploymentMode.NotApplicable)]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.CopyToApplicationDirectory)]
|
||||
[DataRow(PublishMode.SelfContained, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.CopyToApplicationDirectory)]
|
||||
[DataRow(PublishMode.FrameworkDependent, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory)]
|
||||
public void DotnetPublishWorks(PublishMode publishMode, DeploymentMode deploymentMode, NativeLibrariesDeploymentMode nativeLibsDeploymentMode)
|
||||
{
|
||||
// Publishing without specifying a RID is not supported.
|
||||
// Furthermore, only publishing in Release mode is tested.
|
||||
CleanSampleProject(Configuration.Release, RID.Win_x64);
|
||||
|
||||
Exec(SampleProjectDirectory!, "dotnet", $"publish -c Release -f net6.0 -r win-x64 {ToOption(publishMode)} {ToOption(deploymentMode)} {ToOption(nativeLibsDeploymentMode)} /bl");
|
||||
|
||||
string pathToAppHost = Path.Combine("bin", $"Release", "net6.0", "win-x64", "publish", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory!, pathToAppHost, ""));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans the sample project's artifacts for a specific configuration and target runtime.
|
||||
/// This method is called at the start of each test method to work around bugs around some up-to-date checks
|
||||
/// Causing certain targets to not run and effectively corrupting the build output.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration for which the output is cleaned.</param>
|
||||
/// <param name="rid">The RID for which the output is cleaned.</param>
|
||||
private static void CleanSampleProject(Configuration configuration, RID rid)
|
||||
{
|
||||
Exec(SampleProjectDirectory!, "dotnet", $"clean -c {configuration} {ToOption(rid)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the sample project with a specific configuration and target runtime.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to use to build the project.</param>
|
||||
/// <param name="rid">The RID to use to build the project.</param>
|
||||
private static void BuildSampleProject(Configuration configuration, RID rid)
|
||||
{
|
||||
Exec(SampleProjectDirectory!, "dotnet", $"build -c {configuration} {ToOption(rid)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a specified process from the command line and returns the exit code.
|
||||
/// </summary>
|
||||
/// <param name="workingDirectory">The working directory to execute the process.</param>
|
||||
/// <param name="filePath">The target file path for the process to execute.</param>
|
||||
/// <param name="arguments">The arguments to invoke the process.</param>
|
||||
/// <returns>The exit code for the executed process.</returns>
|
||||
private static int Exec(string workingDirectory, string filePath, string arguments)
|
||||
{
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
FileName = filePath,
|
||||
Arguments = arguments,
|
||||
WorkingDirectory = workingDirectory
|
||||
};
|
||||
|
||||
using Process process = Process.Start(startInfo)!;
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToOption(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
RID.Win_x64 => "-r win-x64",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="PublishMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="publishMode">The input <see cref="PublishMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="publishMode"/>.</returns>
|
||||
private static string ToOption(PublishMode publishMode) => publishMode switch
|
||||
{
|
||||
PublishMode.FrameworkDependent => "--self-contained false",
|
||||
PublishMode.SelfContained => "--self-contained true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(publishMode), (int)publishMode, typeof(PublishMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="DeploymentMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="deploymentMode">The input <see cref="DeploymentMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="deploymentMode"/>.</returns>
|
||||
private static string ToOption(DeploymentMode deploymentMode) => deploymentMode switch
|
||||
{
|
||||
DeploymentMode.Multiassembly => "/p:PublishSingleFile=false",
|
||||
DeploymentMode.SingleFile => "/p:PublishSingleFile=true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(DeploymentMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the command line argument for the given <see cref="NativeLibrariesDeploymentMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="deploymentMode">The input <see cref="NativeLibrariesDeploymentMode"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="deploymentMode"/>.</returns>
|
||||
private static string ToOption(NativeLibrariesDeploymentMode deploymentMode) => deploymentMode switch
|
||||
{
|
||||
NativeLibrariesDeploymentMode.NotApplicable => "",
|
||||
NativeLibrariesDeploymentMode.CopyToApplicationDirectory => "/p:IncludeNativeLibrariesForSelfExtract=false",
|
||||
NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory => "/p:IncludeNativeLibrariesForSelfExtract=true",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(NativeLibrariesDeploymentMode))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the build folder for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToDirectory(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
RID.Win_x64 => "win-x64",
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A build configuration.
|
||||
/// </summary>
|
||||
public enum Configuration
|
||||
{
|
||||
Debug,
|
||||
Release
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A runtime identifier.
|
||||
/// </summary>
|
||||
public enum RID
|
||||
{
|
||||
None,
|
||||
Win_x64
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how should the application carry the framework with itself.
|
||||
/// </summary>
|
||||
public enum PublishMode
|
||||
{
|
||||
FrameworkDependent,
|
||||
SelfContained
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how should the application be packaged. Notably, these tests employ .NET 6 style SingleFile,
|
||||
/// aka SuperHost. It does not affect native libraries packaging in .NET 6, but may in the future.
|
||||
/// </summary>
|
||||
public enum DeploymentMode
|
||||
{
|
||||
Multiassembly,
|
||||
SingleFile
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the deployment mode for application's native dependencies.
|
||||
/// Not applicable to multiassembly deployment mode.
|
||||
/// </summary>
|
||||
public enum NativeLibrariesDeploymentMode
|
||||
{
|
||||
NotApplicable,
|
||||
ExtractToTemporaryDirectory,
|
||||
CopyToApplicationDirectory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using ComputeSharp.Tests.NativeLibrariesResolver.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.NativeLibrariesResolver;
|
||||
|
||||
[TestClass]
|
||||
public class PixNativeLibrariesResolverTests : NativeLibrariesResolverTestsBase
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override string SampleProjectName => "ComputeSharp.Pix.NuGet";
|
||||
|
||||
/// <summary>
|
||||
/// Performs static initialization for the assembly before any unit tests are run.
|
||||
/// </summary>
|
||||
/// <param name="_">The <see cref="TestContext"/> for the test runner instance in use.</param>
|
||||
[ClassInitialize]
|
||||
public static void InitializeDynamicDependencies(TestContext _)
|
||||
{
|
||||
string path = Path.GetDirectoryName(typeof(PixNativeLibrariesResolverTests).Assembly.Location)!;
|
||||
|
||||
while (Path.GetFileName(path) is not "ComputeSharp")
|
||||
{
|
||||
path = Path.GetDirectoryName(path)!;
|
||||
}
|
||||
|
||||
string corePackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Core", "ComputeSharp.Core.msbuildproj");
|
||||
string packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj");
|
||||
string pixPackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Pix.Package", "ComputeSharp.Pix.Package.msbuildproj");
|
||||
|
||||
// Run dotnet pack and on the packaging projects, to ensure the local NuGet packages are available
|
||||
Process.Start("dotnet", $"pack {corePackagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit();
|
||||
Process.Start("dotnet", $"pack {pixPackagingProjectPath} -c Release").WaitForExit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
[assembly: DoNotParallelize]
|
||||
新しいイシューから参照
ユーザーをブロックする