From 298e489cb2435d33b5b76684e8d396543d1a31f2 Mon Sep 17 00:00:00 2001 From: Marcel Koester Date: Thu, 2 Mar 2023 15:50:14 +0100 Subject: [PATCH] Added core ILGPU Velocity tests. --- .gitignore | 1 + Src/ILGPU.Tests.Velocity/Configurations.tt | 51 +++++++++++++++++ .../ILGPU.Tests.Velocity.csproj | 57 +++++++++++++++++++ Src/ILGPU.Tests.Velocity/TestContext.cs | 44 ++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 Src/ILGPU.Tests.Velocity/Configurations.tt create mode 100644 Src/ILGPU.Tests.Velocity/ILGPU.Tests.Velocity.csproj create mode 100644 Src/ILGPU.Tests.Velocity/TestContext.cs diff --git a/.gitignore b/.gitignore index c8b76afd19..dae0ab9c46 100644 --- a/.gitignore +++ b/.gitignore @@ -338,6 +338,7 @@ Src/ILGPU.Tests/.test.runsettings Src/ILGPU.Tests.CPU/Configurations.cs Src/ILGPU.Tests.Cuda/Configurations.cs Src/ILGPU.Tests.OpenCL/Configurations.cs +Src/ILGPU.Tests.Velocity/Configurations.cs # Generated test source files (Algorithms) Src/ILGPU.Algorithms.Tests/Generic/ConfigurationBase.cs diff --git a/Src/ILGPU.Tests.Velocity/Configurations.tt b/Src/ILGPU.Tests.Velocity/Configurations.tt new file mode 100644 index 0000000000..3290ac5804 --- /dev/null +++ b/Src/ILGPU.Tests.Velocity/Configurations.tt @@ -0,0 +1,51 @@ +// --------------------------------------------------------------------------------------- +// ILGPU +// Copyright (c) 2023 ILGPU Project +// www.ilgpu.net +// +// File: Configurations.tt/Configurations.cs +// +// This file is part of ILGPU and is distributed under the University of Illinois Open +// Source License. See LICENSE.txt for details. +// --------------------------------------------------------------------------------------- + +<#@ template debug="false" hostspecific="true" language="C#" #> +<#@ include file="../ILGPU.Tests/Generic/ConfigurationBase.tt" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.IO" #> +using Xunit; +using Xunit.Abstractions; + +<# +var configurationFile = Host.ResolvePath("../ILGPU.Tests/Configurations.txt"); +var configurations = TestConfig.Parse(configurationFile); +#> +namespace ILGPU.Tests.Velocity +{ +<# foreach (var (test, level, collection) in configurations) { #> +<# var name = $"Velocity{test}_{level}"; #> + [Collection("VelocityContextCollection<#= collection #>")] + public sealed partial class <#= name #> : <#= test #> + { + public <#= name #>( + ITestOutputHelper output, + VelocityTestContext<#= collection #> testContext) + : base(output, testContext) + { } + } + +<# } #> +<# foreach (var (config, level) in TestConfig.AllConfigurations) { #> + public class VelocityTestContext<#= config #> : VelocityTestContext + { + public VelocityTestContext<#= config #>() + : base(OptimizationLevel.<#= level #>) + { } + } + + [CollectionDefinition("VelocityContextCollection<#= config #>")] + public class VelocityContextCollection<#= config #> : + ICollectionFixture> { } + +<# } #> +} \ No newline at end of file diff --git a/Src/ILGPU.Tests.Velocity/ILGPU.Tests.Velocity.csproj b/Src/ILGPU.Tests.Velocity/ILGPU.Tests.Velocity.csproj new file mode 100644 index 0000000000..ad568c5fad --- /dev/null +++ b/Src/ILGPU.Tests.Velocity/ILGPU.Tests.Velocity.csproj @@ -0,0 +1,57 @@ + + + + $(LibraryUnitTestTargetFrameworks) + false + + + + $(MSBuildProjectDirectory)\..\ILGPU.Tests\.test.runsettings + + + + true + AllEnabledByDefault + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + True + True + Configurations.tt + + + + + + TextTemplatingFileGenerator + Configurations.cs + + + + + + True + True + Configurations.tt + + + diff --git a/Src/ILGPU.Tests.Velocity/TestContext.cs b/Src/ILGPU.Tests.Velocity/TestContext.cs new file mode 100644 index 0000000000..880e2358d0 --- /dev/null +++ b/Src/ILGPU.Tests.Velocity/TestContext.cs @@ -0,0 +1,44 @@ +// --------------------------------------------------------------------------------------- +// ILGPU +// Copyright (c) 2023 ILGPU Project +// www.ilgpu.net +// +// File: TestContext.cs +// +// This file is part of ILGPU and is distributed under the University of Illinois Open +// Source License. See LICENSE.txt for details. +// --------------------------------------------------------------------------------------- + +using ILGPU.Runtime.Velocity; +using System; + +namespace ILGPU.Tests.Velocity +{ + /// + /// An abstract test context for Velocity accelerators. + /// + public abstract class VelocityTestContext : TestContext + { + /// + /// Creates a new test context instance. + /// + /// The optimization level to use. + /// The context preparation handler. + protected VelocityTestContext( + OptimizationLevel optimizationLevel, + Action prepareContext) + : base( + optimizationLevel, + builder => prepareContext(builder.Velocity()), + context => context.CreateVelocityAccelerator()) + { } + + /// + /// Creates a new test context instance. + /// + /// The optimization level to use. + protected VelocityTestContext(OptimizationLevel optimizationLevel) + : this(optimizationLevel, _ => { }) + { } + } +}