From 62108cd158f8adfb8982d7bf74a816bb6451b419 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 27 Jun 2019 07:55:59 +0200 Subject: [PATCH 1/2] handle missing libgdiplus --- .../corefx/System.Drawing/Perf_Image_Load.cs | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs b/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs index 4479aaa7c9b..55a54d81906 100644 --- a/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs +++ b/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs @@ -5,8 +5,8 @@ using System.Collections.Generic; using System.Drawing.Imaging; using System.IO; +using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Extensions; using MicroBenchmarks; namespace System.Drawing.Tests @@ -14,14 +14,10 @@ namespace System.Drawing.Tests [BenchmarkCategory(Categories.CoreFX)] public class Perf_Image_Load { - private static readonly ImageTestData[] TestCases = { - new ImageTestData(ImageFormat.Bmp), - new ImageTestData(ImageFormat.Jpeg), - new ImageTestData(ImageFormat.Png), - new ImageTestData(ImageFormat.Gif) - }; + // this field is lazy to avoid the exception during static ctor initialization of this type (harder to catch and handle properly) + private static readonly Lazy LazyTestCases = new Lazy(CreateTestCases); - public IEnumerable ImageFormats() => TestCases; + public IEnumerable ImageFormats() => LazyTestCases.Value; [Benchmark] [ArgumentsSource(nameof(ImageFormats))] @@ -50,6 +46,28 @@ public void Image_FromStream_NoValidation(ImageTestData format) } } + private static ImageTestData[] CreateTestCases() + { + try + { + return new [] + { + new ImageTestData(ImageFormat.Bmp), + new ImageTestData(ImageFormat.Jpeg), + new ImageTestData(ImageFormat.Png), + new ImageTestData(ImageFormat.Gif) + }; + } + catch (Exception) when (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("libgdiplus is missing, you can install it by running 'apt-get install libgdiplus'"); + Console.ResetColor(); + + return Array.Empty(); + } + } + public class ImageTestData { public Stream Stream { get; } From b0db9b7d6a529e8bf78424d5f5bd343d79cbb093 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 27 Jun 2019 08:09:59 +0200 Subject: [PATCH 2/2] rethrow the exception --- src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs b/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs index 55a54d81906..42484171f2a 100644 --- a/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs +++ b/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs @@ -64,7 +64,7 @@ private static ImageTestData[] CreateTestCases() Console.WriteLine("libgdiplus is missing, you can install it by running 'apt-get install libgdiplus'"); Console.ResetColor(); - return Array.Empty(); + throw; } }