Browse Source

implicit & safer execution of PrepareRemoteExecutor

pull/1134/head
Anton Firszov 6 years ago
parent
commit
39c993d1c0
  1. 5
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 5
      tests/ImageSharp.Tests/Memory/Allocators/ArrayPoolMemoryAllocatorTests.cs
  3. 5
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  4. 7
      tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
  5. 32
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

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

@ -27,11 +27,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
private const float ProgressiveTolerance = 0.2F / 100;
static JpegDecoderTests()
{
TestEnvironment.PrepareRemoteExecutor();
}
private static ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{

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

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

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

@ -19,11 +19,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class BokehBlurTest
{
static BokehBlurTest()
{
TestEnvironment.PrepareRemoteExecutor();
}
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

7
tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs

@ -18,6 +18,13 @@ namespace SixLabors.ImageSharp.Tests
protected readonly PixelTypes PixelTypes;
static ImageDataAttributeBase()
{
// ImageDataAttributes are used in almost all tests, thus a good place to enforce the execution of
// TestEnvironment static constructor before anything else is done.
TestEnvironment.EnsureSharedInitializersDone();
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageDataAttributeBase"/> class.
/// </summary>

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

@ -34,6 +34,11 @@ namespace SixLabors.ImageSharp.Tests
private static readonly Lazy<string> NetCoreVersionLazy = new Lazy<string>(GetNetCoreVersion);
static TestEnvironment()
{
PrepareRemoteExecutor();
}
/// <summary>
/// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.
/// </summary>
@ -111,6 +116,13 @@ namespace SixLabors.ImageSharp.Tests
internal static bool IsFramework => string.IsNullOrEmpty(NetCoreVersion);
/// <summary>
/// A dummy operation to enforce the execution of the static constructor.
/// </summary>
internal static void EnsureSharedInitializersDone()
{
}
/// <summary>
/// Creates the image output directory.
/// </summary>
@ -141,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests
/// When running in 32 bits, enforces 32 bit execution of Microsoft.DotNet.RemoteExecutor.exe
/// with the help of CorFlags.exe found in Windows SDK.
/// </summary>
internal static void PrepareRemoteExecutor()
private static void PrepareRemoteExecutor()
{
if (!IsFramework)
{
@ -153,12 +165,11 @@ namespace SixLabors.ImageSharp.Tests
if (File.Exists(remoteExecutorConfigPath))
{
// already prepared
// Already initialized
return;
}
string testProjectConfigPath = TestAssemblyFile.FullName + ".config";
File.Copy(testProjectConfigPath, remoteExecutorConfigPath);
if (Is64BitProcess)
@ -184,7 +195,17 @@ namespace SixLabors.ImageSharp.Tests
string remoteExecutorPath = Path.Combine(TestAssemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe");
string args = $"{remoteExecutorPath} /32Bit+ /Force";
string remoteExecutorTmpPath = $"{remoteExecutorPath}._tmp";
if (File.Exists(remoteExecutorTmpPath))
{
// Already initialized
return;
}
File.Copy(remoteExecutorPath, remoteExecutorTmpPath);
string args = $"{remoteExecutorTmpPath} /32Bit+ /Force";
var si = new ProcessStartInfo()
{
@ -206,6 +227,9 @@ namespace SixLabors.ImageSharp.Tests
$@"Failed to run {si.FileName} {si.Arguments}:\n STDOUT: {standardOutput}\n STDERR: {standardError}");
}
File.Delete(remoteExecutorPath);
File.Copy(remoteExecutorTmpPath, remoteExecutorPath);
static FileInfo Find(DirectoryInfo root, string name)
{
FileInfo fi = root.EnumerateFiles(name).FirstOrDefault();

Loading…
Cancel
Save