diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 22df9966b2..90caea387d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg static JpegDecoderTests() { - TestEnvironment.InitRemoteExecutorAssemblyRedirects(); + TestEnvironment.PrepareRemoteExecutor(); } private static ImageComparer GetImageComparer(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs b/tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs index d2ed56a373..227d627784 100644 --- a/tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs +++ b/tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs @@ -4,9 +4,11 @@ // ReSharper disable InconsistentNaming using System; using System.Buffers; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.DotNet.RemoteExecutor; +using Microsoft.Win32; using SixLabors.ImageSharp.Tests; using Xunit; @@ -31,7 +33,7 @@ namespace SixLabors.ImageSharp.Memory.Tests static ArrayPoolMemoryAllocatorTests() { - TestEnvironment.InitRemoteExecutorAssemblyRedirects(); + TestEnvironment.PrepareRemoteExecutor(); } public class BufferTests : BufferTestSuite diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs index 42b5de376e..34b0165139 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { static BokehBlurTest() { - TestEnvironment.InitRemoteExecutorAssemblyRedirects(); + TestEnvironment.PrepareRemoteExecutor(); } private static readonly string Components10x2 = @" diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 3b6c8c0643..cf5f536aeb 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -135,9 +136,11 @@ namespace SixLabors.ImageSharp.Tests } /// - /// Need to create Microsoft.DotNet.RemoteExecutor.exe.config on .NET 4.7.2 (-_-) + /// Creates Microsoft.DotNet.RemoteExecutor.exe.config for .NET framework, + /// When running in 32 bits, enforces 32 bit execution of Microsoft.DotNet.RemoteExecutor.exe + /// with the help of corflags.exe found in Windows SDK. /// - internal static void InitRemoteExecutorAssemblyRedirects() + internal static void PrepareRemoteExecutor() { if (!IsFramework) { @@ -156,6 +159,64 @@ namespace SixLabors.ImageSharp.Tests string testProjectConfigPath = assemblyFile.FullName + ".config"; File.Copy(testProjectConfigPath, remoteExecutorConfigPath); + + if (Is64BitProcess) + { + return; + } + + string windowsSdksDir = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(x86)"), + "Microsoft SDKs", "Windows"); + + FileInfo corFlagsFile = Find(new DirectoryInfo(windowsSdksDir), "corflags.exe"); + + string remoteExecutorPath = Path.Combine(assemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe"); + + string args = $"{remoteExecutorPath} /32Bit+ /Force"; + + var si = new ProcessStartInfo() + { + FileName = corFlagsFile.FullName, + Arguments = args, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true + }; + + try + { + using var proc = Process.Start(si); + proc.WaitForExit(); + string standardOutput = proc.StandardOutput.ReadToEnd(); + string standardError = proc.StandardError.ReadToEnd(); + Debug.Print(standardOutput); + Debug.Print(standardError); + } + catch (Exception ex) + { + // Avoid fatal exceptions here + Debug.Print(ex.Message); + } + + static FileInfo Find(DirectoryInfo root, string name) + { + FileInfo fi = root.EnumerateFiles().FirstOrDefault(f => f.Name.ToLower() == name); + if (fi != null) + { + return fi; + } + + foreach (DirectoryInfo dir in root.EnumerateDirectories()) + { + fi = Find(dir, name); + if (fi != null) + { + return fi; + } + } + + return null; + } } ///