Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PropertyItem tests #46794

Merged
merged 5 commits into from
Mar 26, 2021
Merged

Add PropertyItem tests #46794

merged 5 commits into from
Mar 26, 2021

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Jan 10, 2021

No description provided.

@ghost
Copy link

ghost commented Jan 10, 2021

Tagging subscribers to this area: @safern, @tannergooding
See info in area-owners.md if you want to be subscribed.

Issue Details

Not committing the refactoring yet as I need to baseline the test failures on mac :)

Author: hughbe
Assignees: -
Labels:

area-System.Drawing

Milestone: -

@hughbe
Copy link
Contributor Author

hughbe commented Jan 11, 2021

Ok most of these tests fail on libgdiplus but will be fixed in mono/libgdiplus#683.

I'll disable them on mac soon

@hughbe hughbe force-pushed the propertyiteminternal branch 2 times, most recently from 80b7e2b to ec4a1b5 Compare January 12, 2021 10:36
@hughbe
Copy link
Contributor Author

hughbe commented Jan 12, 2021

Test failures unrelated - System.Speech problems

@hughbe hughbe changed the title Refactor PropertyItem image code Add PropertyItem tests Jan 13, 2021
@hughbe
Copy link
Contributor Author

hughbe commented Jan 13, 2021

@safern yeah looks like we're running into #34592 annoyingly, so my changes won't work.

I've backed out the refactoring changes until that bug in the mono runtime is fixed!

@hughbe
Copy link
Contributor Author

hughbe commented Jan 13, 2021

I may need to actually disable the tests - so tests will probably fail again then I will baseline the failures

@safern
Copy link
Member

safern commented Jan 14, 2021

Sounds good. Let me know when/if this is ready for review 😄

@hughbe
Copy link
Contributor Author

hughbe commented Jan 14, 2021

OK I've made the following changes that are actually quite positive.

Basically, I converted PropertyItemInternal into a blittable struct. Now, instead of marshalling lots of data we can just pin the PropertyItem.Value we simply pass the struct directly to the native code.

I also avoided an allocation of an array of one element in the code for GetPropertyItem.

I also took advantage of Span<byte>(ptr, len).ToArray() instead of doing Marshal.Copy which should also be better

This will have some perf wins and also shortens the code! Winning!

@hughbe
Copy link
Contributor Author

hughbe commented Jan 14, 2021

Have run the tests on macOS with my locally built libgdiplus (enabling the property item tests that fail but are fixed in mono/libgdiplus#683).

So this should be now ready for review!

hugh@Hughs-MacBook-Air tests % /Users/hugh/Documents/GitHub/runtime/.dotnet/dotnet build /T:Test /P:XUnitOptions="-class System.Drawing.Imaging.Tests.PropertyItemTests"
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  System.Security.Principal.Windows -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal.Windows/ref/netstandard2.0-Debug/System.Security.Principal.Windows.dll
  System.Security.AccessControl -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.AccessControl/ref/netstandard2.0-Debug/System.Security.AccessControl.dll
  Microsoft.Win32.Registry -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.Registry/ref/netstandard2.0-Debug/Microsoft.Win32.Registry.dll
  System.Runtime -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime/ref/net6.0-Debug/System.Runtime.dll
  System.ComponentModel -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ComponentModel/ref/net6.0-Debug/System.ComponentModel.dll
  Microsoft.Win32.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.Primitives/ref/net6.0-Debug/Microsoft.Win32.Primitives.dll
  System.Security.Principal -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal/ref/net6.0-Debug/System.Security.Principal.dll
  System.Collections -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections/ref/net6.0-Debug/System.Collections.dll
  System.Runtime.Extensions -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime.Extensions/ref/net6.0-Debug/System.Runtime.Extensions.dll
  System.Runtime.InteropServices -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime.InteropServices/ref/net6.0-Debug/System.Runtime.InteropServices.dll
  System.Collections.NonGeneric -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections.NonGeneric/ref/net6.0-Debug/System.Collections.NonGeneric.dll
  System.ObjectModel -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ObjectModel/ref/net6.0-Debug/System.ObjectModel.dll
  System.Memory -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Memory/ref/net6.0-Debug/System.Memory.dll
  System.ComponentModel.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ComponentModel.Primitives/ref/net6.0-Debug/System.ComponentModel.Primitives.dll
  System.Net.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Net.Primitives/ref/net6.0-Debug/System.Net.Primitives.dll
  System.Collections.Specialized -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections.Specialized/ref/net6.0-Debug/System.Collections.Specialized.dll
  System.Net.WebSockets -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Net.WebSockets/ref/net6.0-Debug/System.Net.WebSockets.dll
  System.Security.Claims -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Claims/ref/net6.0-Debug/System.Security.Claims.dll
  System.Security.Principal.Windows -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal.Windows/ref/net6.0-Debug/System.Security.Principal.Windows.dll
  System.Security.AccessControl -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.AccessControl/ref/net6.0-Debug/System.Security.AccessControl.dll
  TestUtilities -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/TestUtilities/net6.0-Debug/TestUtilities.dll
  Microsoft.Win32.SystemEvents -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.SystemEvents/netstandard2.0-Debug/Microsoft.Win32.SystemEvents.dll
  System.Drawing.Common -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common/net6.0-Unix-Debug/System.Drawing.Common.dll
  System.Drawing.Common.Tests -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug/System.Drawing.Common.Tests.dll
  ----- start Thu Jan 14 12:58:29 GMT 2021 =============== To repro directly: =====================================================
  pushd /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug
  /Users/hugh/Documents/GitHub/runtime/artifacts/bin/testhost/net6.0-OSX-Debug-x64/dotnet exec --runtimeconfig System.Drawing.Common.Tests.runtimeconfig.json --depsfile System.Drawing.Common.Tests.deps.json xunit.console.dll System.Drawing.Common.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -class System.Drawing.Imaging.Tests.PropertyItemTests 
  popd
  ===========================================================================================================
  ~/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug ~/Documents/GitHub/runtime/src/libraries/System.Drawing.Common/tests
    Discovering: System.Drawing.Common.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Drawing.Common.Tests (found 5 of 2033 test cases)
    Starting:    System.Drawing.Common.Tests (parallel test collections = on, max threads = 4)
    Finished:    System.Drawing.Common.Tests
  === TEST EXECUTION SUMMARY ===
     System.Drawing.Common.Tests  Total: 15, Errors: 0, Failed: 0, Skipped: 0, Time: 8.400s
  ~/Documents/GitHub/runtime/src/libraries/System.Drawing.Common/tests
  ----- end Thu Jan 14 12:59:23 GMT 2021 ----- exit code 0 ----------------------------------------------------------
  exit code 0 means Exited Successfully

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:01:19.55
hugh@Hughs-MacBook-Air tests % /Users/hugh/Documents/GitHub/runtime/.dotnet/dotnet build /T:Test /P:XUnitOptions="-class System.Drawing.Tests.ImageTests"
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  System.Security.Principal.Windows -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal.Windows/ref/netstandard2.0-Debug/System.Security.Principal.Windows.dll
  System.Security.AccessControl -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.AccessControl/ref/netstandard2.0-Debug/System.Security.AccessControl.dll
  Microsoft.Win32.Registry -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.Registry/ref/netstandard2.0-Debug/Microsoft.Win32.Registry.dll
  System.Runtime -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime/ref/net6.0-Debug/System.Runtime.dll
  System.ComponentModel -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ComponentModel/ref/net6.0-Debug/System.ComponentModel.dll
  Microsoft.Win32.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.Primitives/ref/net6.0-Debug/Microsoft.Win32.Primitives.dll
  System.Collections -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections/ref/net6.0-Debug/System.Collections.dll
  System.Runtime.Extensions -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime.Extensions/ref/net6.0-Debug/System.Runtime.Extensions.dll
  System.Security.Principal -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal/ref/net6.0-Debug/System.Security.Principal.dll
  System.ObjectModel -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ObjectModel/ref/net6.0-Debug/System.ObjectModel.dll
  System.Collections.NonGeneric -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections.NonGeneric/ref/net6.0-Debug/System.Collections.NonGeneric.dll
  System.Runtime.InteropServices -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Runtime.InteropServices/ref/net6.0-Debug/System.Runtime.InteropServices.dll
  System.Memory -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Memory/ref/net6.0-Debug/System.Memory.dll
  System.ComponentModel.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.ComponentModel.Primitives/ref/net6.0-Debug/System.ComponentModel.Primitives.dll
  System.Net.Primitives -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Net.Primitives/ref/net6.0-Debug/System.Net.Primitives.dll
  System.Collections.Specialized -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Collections.Specialized/ref/net6.0-Debug/System.Collections.Specialized.dll
  System.Net.WebSockets -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Net.WebSockets/ref/net6.0-Debug/System.Net.WebSockets.dll
  System.Security.Claims -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Claims/ref/net6.0-Debug/System.Security.Claims.dll
  System.Security.Principal.Windows -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.Principal.Windows/ref/net6.0-Debug/System.Security.Principal.Windows.dll
  System.Security.AccessControl -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Security.AccessControl/ref/net6.0-Debug/System.Security.AccessControl.dll
  TestUtilities -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/TestUtilities/net6.0-Debug/TestUtilities.dll
  Microsoft.Win32.SystemEvents -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/Microsoft.Win32.SystemEvents/netstandard2.0-Debug/Microsoft.Win32.SystemEvents.dll
  System.Drawing.Common -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common/net6.0-Unix-Debug/System.Drawing.Common.dll
  System.Drawing.Common.Tests -> /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug/System.Drawing.Common.Tests.dll
  ----- start Thu Jan 14 12:56:16 GMT 2021 =============== To repro directly: =====================================================
  pushd /Users/hugh/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug
  /Users/hugh/Documents/GitHub/runtime/artifacts/bin/testhost/net6.0-OSX-Debug-x64/dotnet exec --runtimeconfig System.Drawing.Common.Tests.runtimeconfig.json --depsfile System.Drawing.Common.Tests.deps.json xunit.console.dll System.Drawing.Common.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -class System.Drawing.Tests.ImageTests 
  popd
  ===========================================================================================================
  ~/Documents/GitHub/runtime/artifacts/bin/System.Drawing.Common.Tests/net6.0-Unix-Debug ~/Documents/GitHub/runtime/src/libraries/System.Drawing.Common/tests
    Discovering: System.Drawing.Common.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Drawing.Common.Tests (found 26 of 2033 test cases)
    Starting:    System.Drawing.Common.Tests (parallel test collections = on, max threads = 4)
    Finished:    System.Drawing.Common.Tests
  === TEST EXECUTION SUMMARY ===
     System.Drawing.Common.Tests  Total: 71, Errors: 0, Failed: 0, Skipped: 0, Time: 9.533s  ~/Documents/GitHub/runtime/src/libraries/System.Drawing.Common/tests
  ----- end Thu Jan 14 12:57:18 GMT 2021 ----- exit code 0 ----------------------------------------------------------
  exit code 0 means Exited Successfully

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:01:18.67

// sdkinc\imaging.h
[StructLayout(LayoutKind.Sequential)]
internal sealed class PropertyItemInternal : IDisposable
#pragma warning disable CS0649
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just put it around the uninitialized field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

item.Value = value;
Assert.Same(value, item.Value);

// Set same.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this exercising? I mean double setting to the same value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its something we do in winforms where we test setting a property to the same value to make sure things are idempotent.

Removed

@hughbe
Copy link
Contributor Author

hughbe commented Feb 12, 2021

@JeremyKuhne also may be worth taking a look as you've done something similar here recently

if (size == 0 || count == 0)
return Array.Empty<PropertyItem>();

PropertyItemInternal* propdata = (PropertyItemInternal*)Marshal.AllocHGlobal((int)size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to rent a byte array from the ArrayPool and pin that for the buffer please? It would be good to get rid of the AllocHGlobal. :)

if (size == 0)
return null;

PropertyItemInternal* propdata = (PropertyItemInternal*)Marshal.AllocHGlobal((int)size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rent a byte buffer from the ArrayPool here too.

Base automatically changed from master to main March 1, 2021 09:07
Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@safern
Copy link
Member

safern commented Mar 26, 2021

I'll close and re-open as the build is 3 weeks old already.

@safern safern merged commit ec2fedc into dotnet:main Mar 26, 2021
@safern
Copy link
Member

safern commented Mar 26, 2021

I hit the wrong button 😄 (twice). I'll keep an eye on the build

@hughbe hughbe deleted the propertyiteminternal branch March 26, 2021 08:51
@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants