Browse Source

when running tests in 32 bits, enforce 32bit execution of RemoteExecutor.exe

pull/1089/head
Anton Firszov 6 years ago
parent
commit
97396e6aa1
  1. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 4
      tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs
  3. 2
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  4. 65
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

2
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<TPixel>(TestImageProvider<TPixel> provider)

4
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

2
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 = @"

65
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
}
/// <summary>
/// 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.
/// </summary>
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;
}
}
/// <summary>

Loading…
Cancel
Save