Browse Source

workaround RemoteExecutor assembly redirect issue on 472,

run BokehBlurTests in separate process
pull/1089/head
Anton Firszov 6 years ago
parent
commit
1b6cc28dca
  1. 25
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 5
      tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs
  3. 62
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  4. 34
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

25
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -4,11 +4,12 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
@ -23,8 +24,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector;
private const float BaselineTolerance = 0.001F / 100;
private const float ProgressiveTolerance = 0.2F / 100;
static JpegDecoderTests()
{
TestEnvironment.InitRemoteExecutorAssemblyRedirects();
}
private static ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -88,23 +95,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void JpegDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
if (SkipTest(provider))
{
return;
}
// For 32 bit test environments:
provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling();
using (Image<TPixel> image = provider.GetImage(JpegDecoder))
static void RunTest(string providerDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
using Image<TPixel> image = provider.GetImage(JpegDecoder);
image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance), provider, appendPixelTypeToFileName: false);
}
provider.Configuration.MemoryAllocator.ReleaseRetainedResources();
string dump = BasicSerializer.Serialize(provider);
RemoteExecutor.Invoke(RunTest, dump).Dispose();
}
// DEBUG ONLY!

5
tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs

@ -29,6 +29,11 @@ namespace SixLabors.ImageSharp.Memory.Tests
/// </summary>
private static MemoryAllocatorFixture StaticFixture { get; } = new MemoryAllocatorFixture();
static ArrayPoolMemoryAllocatorTests()
{
TestEnvironment.InitRemoteExecutorAssemblyRedirects();
}
public class BufferTests : BufferTestSuite
{
public BufferTests()

62
tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

@ -6,11 +6,12 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Convolution;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
using Xunit.Abstractions;
@ -18,6 +19,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class BokehBlurTest
{
static BokehBlurTest()
{
TestEnvironment.InitRemoteExecutorAssemblyRedirects();
}
private static readonly string Components10x2 = @"
[[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
-0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j
@ -124,10 +130,22 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(
x => x.BokehBlur(value.Radius, value.Components, value.Gamma),
testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false);
static void RunTest(string providerDump, string infoDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest(
x => x.BokehBlur(value.Radius, value.Components, value.Gamma),
testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
}
[Theory]
@ -137,9 +155,18 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor_WorksWithAllPixelTypes<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(
x => x.BokehBlur(8, 2, 3),
appendSourceFileOrDescription: false);
static void RunTest(string providerDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.RunValidatingProcessorTest(
x => x.BokehBlur(8, 2, 3),
appendSourceFileOrDescription: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider))
.Dispose();
}
@ -148,15 +175,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor_Bounded<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(
x =>
static void RunTest(string providerDump, string infoDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest(
x =>
{
Size size = x.GetCurrentSize();
var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2);
x.BokehBlur(value.Radius, value.Components, value.Gamma, bounds);
},
testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false);
testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
}
}
}

34
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests
return directory.FullName;
}
private static string GetFullPath(string relativePath) =>
private static string GetFullPath(string relativePath) =>
Path.Combine(SolutionDirectoryFullPath, relativePath)
.Replace('\\', Path.DirectorySeparatorChar);
@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Tests
/// Gets the correct full path to the Input Images directory.
/// </summary>
internal static string InputImagesDirectoryFullPath => GetFullPath(InputImagesRelativePath);
/// <summary>
/// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.)
/// </summary>
@ -100,13 +100,15 @@ namespace SixLabors.ImageSharp.Tests
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar);
internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194
internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
internal static bool Is64BitProcess => IntPtr.Size == 8;
internal static bool IsFramework => string.IsNullOrEmpty(NetCoreVersion);
/// <summary>
/// Creates the image output directory.
/// </summary>
@ -132,6 +134,30 @@ namespace SixLabors.ImageSharp.Tests
return path;
}
/// <summary>
/// Need to create Microsoft.DotNet.RemoteExecutor.exe.config on .NET 4.7.2 (-_-)
/// </summary>
internal static void InitRemoteExecutorAssemblyRedirects()
{
if (!IsFramework)
{
return;
}
var assemblyFile = new FileInfo(typeof(TestEnvironment).GetTypeInfo().Assembly.Location);
string remoteExecutorConfigPath =
Path.Combine(assemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe.config");
if (File.Exists(remoteExecutorConfigPath))
{
return;
}
string testProjectConfigPath = assemblyFile.FullName + ".config";
File.Copy(testProjectConfigPath, remoteExecutorConfigPath);
}
/// <summary>
/// Solution borrowed from:
/// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100
@ -146,4 +172,4 @@ namespace SixLabors.ImageSharp.Tests
return "";
}
}
}
}

Loading…
Cancel
Save