Skip to content

Commit ac6b6a9

Browse files
Merge pull request #1134 from SixLabors/af/corflags-tweaks
Try to fix corflags.exe failures on CI
2 parents c91c206 + e3787fa commit ac6b6a9

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public partial class JpegDecoderTests
2727

2828
private const float ProgressiveTolerance = 0.2F / 100;
2929

30-
static JpegDecoderTests()
31-
{
32-
TestEnvironment.PrepareRemoteExecutor();
33-
}
34-
3530
private static ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider)
3631
where TPixel : unmanaged, IPixel<TPixel>
3732
{

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class ArrayPoolMemoryAllocatorTests
2828
/// </summary>
2929
private static MemoryAllocatorFixture StaticFixture { get; } = new MemoryAllocatorFixture();
3030

31-
static ArrayPoolMemoryAllocatorTests()
32-
{
33-
TestEnvironment.PrepareRemoteExecutor();
34-
}
35-
3631
public class BufferTests : BufferTestSuite
3732
{
3833
public BufferTests()

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
1919
{
2020
public class BokehBlurTest
2121
{
22-
static BokehBlurTest()
23-
{
24-
TestEnvironment.PrepareRemoteExecutor();
25-
}
26-
2722
private static readonly string Components10x2 = @"
2823
[[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
2924
-0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public abstract class ImageDataAttributeBase : DataAttribute
1818

1919
protected readonly PixelTypes PixelTypes;
2020

21+
static ImageDataAttributeBase()
22+
{
23+
// ImageDataAttributes are used in almost all tests, thus a good place to enforce the execution of
24+
// TestEnvironment static constructor before anything else is done.
25+
TestEnvironment.EnsureSharedInitializersDone();
26+
}
27+
2128
/// <summary>
2229
/// Initializes a new instance of the <see cref="ImageDataAttributeBase"/> class.
2330
/// </summary>

tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public static partial class TestEnvironment
3434

3535
private static readonly Lazy<string> NetCoreVersionLazy = new Lazy<string>(GetNetCoreVersion);
3636

37+
static TestEnvironment()
38+
{
39+
PrepareRemoteExecutor();
40+
}
41+
3742
/// <summary>
3843
/// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.
3944
/// </summary>
@@ -111,6 +116,13 @@ internal static string GetReferenceOutputFileName(string actualOutputFileName) =
111116

112117
internal static bool IsFramework => string.IsNullOrEmpty(NetCoreVersion);
113118

119+
/// <summary>
120+
/// A dummy operation to enforce the execution of the static constructor.
121+
/// </summary>
122+
internal static void EnsureSharedInitializersDone()
123+
{
124+
}
125+
114126
/// <summary>
115127
/// Creates the image output directory.
116128
/// </summary>
@@ -141,7 +153,7 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa
141153
/// When running in 32 bits, enforces 32 bit execution of Microsoft.DotNet.RemoteExecutor.exe
142154
/// with the help of CorFlags.exe found in Windows SDK.
143155
/// </summary>
144-
internal static void PrepareRemoteExecutor()
156+
private static void PrepareRemoteExecutor()
145157
{
146158
if (!IsFramework)
147159
{
@@ -153,12 +165,11 @@ internal static void PrepareRemoteExecutor()
153165

154166
if (File.Exists(remoteExecutorConfigPath))
155167
{
156-
// already prepared
168+
// Already initialized
157169
return;
158170
}
159171

160172
string testProjectConfigPath = TestAssemblyFile.FullName + ".config";
161-
162173
File.Copy(testProjectConfigPath, remoteExecutorConfigPath);
163174

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

185196
string remoteExecutorPath = Path.Combine(TestAssemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe");
186197

187-
string args = $"{remoteExecutorPath} /32Bit+ /Force";
198+
string remoteExecutorTmpPath = $"{remoteExecutorPath}._tmp";
199+
200+
if (File.Exists(remoteExecutorTmpPath))
201+
{
202+
// Already initialized
203+
return;
204+
}
205+
206+
File.Copy(remoteExecutorPath, remoteExecutorTmpPath);
207+
208+
string args = $"{remoteExecutorTmpPath} /32Bit+ /Force";
188209

189210
var si = new ProcessStartInfo()
190211
{
@@ -206,6 +227,9 @@ private static void EnsureRemoteExecutorIs32Bit()
206227
$@"Failed to run {si.FileName} {si.Arguments}:\n STDOUT: {standardOutput}\n STDERR: {standardError}");
207228
}
208229

230+
File.Delete(remoteExecutorPath);
231+
File.Copy(remoteExecutorTmpPath, remoteExecutorPath);
232+
209233
static FileInfo Find(DirectoryInfo root, string name)
210234
{
211235
FileInfo fi = root.EnumerateFiles(name).FirstOrDefault();

0 commit comments

Comments
 (0)