Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public partial class JpegDecoderTests

private const float ProgressiveTolerance = 0.2F / 100;

static JpegDecoderTests()
{
TestEnvironment.PrepareRemoteExecutor();
}

private static ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public class ArrayPoolMemoryAllocatorTests
/// </summary>
private static MemoryAllocatorFixture StaticFixture { get; } = new MemoryAllocatorFixture();

static ArrayPoolMemoryAllocatorTests()
{
TestEnvironment.PrepareRemoteExecutor();
}

public class BufferTests : BufferTestSuite
{
public BufferTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public abstract class ImageDataAttributeBase : DataAttribute

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>
Expand Down
32 changes: 28 additions & 4 deletions tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static partial class TestEnvironment

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>
Expand Down Expand Up @@ -111,6 +116,13 @@ internal static string GetReferenceOutputFileName(string actualOutputFileName) =

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>
Expand Down Expand Up @@ -141,7 +153,7 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa
/// 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)
{
Expand All @@ -153,12 +165,11 @@ internal static void PrepareRemoteExecutor()

if (File.Exists(remoteExecutorConfigPath))
{
// already prepared
// Already initialized
return;
}

string testProjectConfigPath = TestAssemblyFile.FullName + ".config";

File.Copy(testProjectConfigPath, remoteExecutorConfigPath);

if (Is64BitProcess)
Expand All @@ -184,7 +195,17 @@ private static void EnsureRemoteExecutorIs32Bit()

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()
{
Expand All @@ -206,6 +227,9 @@ private static void EnsureRemoteExecutorIs32Bit()
$@"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();
Expand Down