Skip to content

Commit 5f78f19

Browse files
Add tests
1 parent 69cd2f3 commit 5f78f19

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
// ReSharper disable InconsistentNaming
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
7-
8+
#if SUPPORTS_RUNTIME_INTRINSICS
9+
using System.Runtime.Intrinsics.X86;
10+
#endif
11+
using Microsoft.DotNet.RemoteExecutor;
812
using SixLabors.ImageSharp.Formats;
913
using SixLabors.ImageSharp.Formats.Png;
1014
using SixLabors.ImageSharp.Metadata;
1115
using SixLabors.ImageSharp.PixelFormats;
1216
using SixLabors.ImageSharp.Processing.Processors.Quantization;
17+
using SixLabors.ImageSharp.Tests.TestUtilities;
1318
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
1419

1520
using Xunit;
@@ -529,6 +534,47 @@ public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixe
529534
}
530535
}
531536

537+
[Theory]
538+
[WithTestPatternImages(100, 100, PixelTypes.Rgba32)]
539+
public void EncodeWorksWithoutSsse3Intrinsics<TPixel>(TestImageProvider<TPixel> provider)
540+
where TPixel : unmanaged, IPixel<TPixel>
541+
{
542+
static void RunTest(string providerDump)
543+
{
544+
TestImageProvider<TPixel> provider =
545+
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
546+
#if SUPPORTS_RUNTIME_INTRINSICS
547+
Assert.False(Ssse3.IsSupported);
548+
#endif
549+
550+
foreach (PngInterlaceMode interlaceMode in InterlaceMode)
551+
{
552+
TestPngEncoderCore(
553+
provider,
554+
PngColorType.Rgb,
555+
PngFilterMethod.Adaptive,
556+
PngBitDepth.Bit8,
557+
interlaceMode,
558+
appendPixelType: true,
559+
appendPngColorType: true);
560+
}
561+
}
562+
563+
string providerDump = BasicSerializer.Serialize(provider);
564+
565+
var processStartInfo = new ProcessStartInfo();
566+
processStartInfo.Environment[TestEnvironment.Features.EnableSSE3] = TestEnvironment.Features.Off;
567+
568+
RemoteExecutor.Invoke(
569+
RunTest,
570+
providerDump,
571+
new RemoteInvokeOptions
572+
{
573+
StartInfo = processStartInfo
574+
})
575+
.Dispose();
576+
}
577+
532578
private static void TestPngEncoderCore<TPixel>(
533579
TestImageProvider<TPixel> provider,
534580
PngColorType pngColorType,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
namespace SixLabors.ImageSharp.Tests
5+
{
6+
public static partial class TestEnvironment
7+
{
8+
internal static class Features
9+
{
10+
public const string On = "1";
11+
public const string Off = "0";
12+
13+
public const string EnableAES = "COMPlus_EnableAES";
14+
public const string EnableAVX = "COMPlus_EnableAVX";
15+
public const string EnableAVX2 = "COMPlus_EnableAVX2";
16+
public const string EnableBMI1 = "COMPlus_EnableBMI1";
17+
public const string EnableBMI2 = "COMPlus_EnableBMI2";
18+
public const string EnableFMA = "COMPlus_EnableFMA";
19+
public const string EnableHWIntrinsic = "COMPlus_EnableHWIntrinsic";
20+
public const string EnableIncompleteISAClass = "COMPlus_EnableIncompleteISAClass";
21+
public const string EnableLZCNT = "COMPlus_EnableLZCNT";
22+
public const string EnablePCLMULQDQ = "COMPlus_EnablePCLMULQDQ";
23+
public const string EnablePOPCNT = "COMPlus_EnablePOPCNT";
24+
public const string EnableSSE = "COMPlus_EnableSSE";
25+
public const string EnableSSE2 = "COMPlus_EnableSSE2";
26+
public const string EnableSSE3 = "COMPlus_EnableSSE3";
27+
public const string EnableSSE3_4 = "COMPlus_EnableSSE3_4";
28+
public const string EnableSSE41 = "COMPlus_EnableSSE41";
29+
public const string EnableSSE42 = "COMPlus_EnableSSE42";
30+
public const string EnableSSSE3 = "COMPlus_EnableSSSE3";
31+
public const string FeatureSIMD = "COMPlus_FeatureSIMD";
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)