Browse Source

workaround RemoteExecutor assembly redirect issue on 472,

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

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

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

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

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

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

@ -6,11 +6,12 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Processing.Processors.Convolution;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -18,6 +19,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{ {
public class BokehBlurTest public class BokehBlurTest
{ {
static BokehBlurTest()
{
TestEnvironment.InitRemoteExecutorAssemblyRedirects();
}
private static readonly string Components10x2 = @" private static readonly string Components10x2 = @"
[[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j [[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
-0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j -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) public void BokehBlurFilterProcessor<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
static void RunTest(string providerDump, string infoDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest( provider.RunValidatingProcessorTest(
x => x.BokehBlur(value.Radius, value.Components, value.Gamma), x => x.BokehBlur(value.Radius, value.Components, value.Gamma),
testOutputDetails: value.ToString(), testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false); appendPixelTypeToFileName: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
} }
[Theory] [Theory]
@ -137,17 +155,32 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor_WorksWithAllPixelTypes<TPixel>(TestImageProvider<TPixel> provider) public void BokehBlurFilterProcessor_WorksWithAllPixelTypes<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
static void RunTest(string providerDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.RunValidatingProcessorTest( provider.RunValidatingProcessorTest(
x => x.BokehBlur(8, 2, 3), x => x.BokehBlur(8, 2, 3),
appendSourceFileOrDescription: false); appendSourceFileOrDescription: false);
} }
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider))
.Dispose();
}
[Theory] [Theory]
[WithFileCollection(nameof(TestFiles), nameof(BokehBlurValues), PixelTypes.Rgba32)] [WithFileCollection(nameof(TestFiles), nameof(BokehBlurValues), PixelTypes.Rgba32)]
public void BokehBlurFilterProcessor_Bounded<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value) public void BokehBlurFilterProcessor_Bounded<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
static void RunTest(string providerDump, string infoDump)
{
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest( provider.RunValidatingProcessorTest(
x => x =>
{ {
@ -158,5 +191,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
testOutputDetails: value.ToString(), testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false); appendPixelTypeToFileName: false);
} }
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
}
} }
} }

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

@ -107,6 +107,8 @@ namespace SixLabors.ImageSharp.Tests
internal static bool Is64BitProcess => IntPtr.Size == 8; internal static bool Is64BitProcess => IntPtr.Size == 8;
internal static bool IsFramework => string.IsNullOrEmpty(NetCoreVersion);
/// <summary> /// <summary>
/// Creates the image output directory. /// Creates the image output directory.
/// </summary> /// </summary>
@ -132,6 +134,30 @@ namespace SixLabors.ImageSharp.Tests
return path; 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> /// <summary>
/// Solution borrowed from: /// Solution borrowed from:
/// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100 /// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100

Loading…
Cancel
Save