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

More tests for Marshal.Realloc{HGlobal|CoTaskMem} #41910

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Sep 5, 2020

The corner case behavior of Marshal.Realloc method is non-standard and differs between the two realloc methods. Capture it in tests.

@am11
Copy link
Member

am11 commented Sep 6, 2020

Mono arm64 debug call stack looks strange:

    System.Runtime.InteropServices.Tests.ReAllocCoTaskMemTests.ReAllocCoTaskMem_PositiveSize(size: 0) [FAIL]
      System.OutOfMemoryException : Out of memory
      Stack Trace:
        /_/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs(31,0): at System.Runtime.InteropServices.Marshal.AllocHGlobal(Int32 cb)
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AllocHGlobalTests.cs(39,0): at System.Runtime.InteropServices.Tests.AllocHGlobalTests.<>c.<AllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__1_0()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AllocHGlobalTests.cs(40,0): at System.Runtime.InteropServices.Tests.AllocHGlobalTests.<>c.<AllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__1_1()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocHGlobalTests.cs(55,0): at System.Runtime.InteropServices.Tests.ReAllocHGlobalTests.<>c__DisplayClass1_0.<ReAllocHGlobal_PositiveSize>b__0()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocHGlobalTests.cs(73,0): at System.Runtime.InteropServices.Tests.ReAllocHGlobalTests.<>c.<ReAllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__2_0()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocHGlobalTests.cs(74,0): at System.Runtime.InteropServices.Tests.ReAllocHGlobalTests.<>c.<ReAllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__2_1()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocHGlobalTests.cs(86,0): at System.Runtime.InteropServices.Tests.ReAllocHGlobalTests.<>c.<ReAllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__2_2()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocHGlobalTests.cs(89,0): at System.Runtime.InteropServices.Tests.ReAllocHGlobalTests.<>c__DisplayClass2_0.<ReAllocHGlobal_NegativeSize_ThrowsOutOfMemoryException>b__3()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocCoTaskMemTests.cs(52,0): at System.Runtime.InteropServices.Tests.ReAllocCoTaskMemTests.<>c__DisplayClass1_0.<ReAllocCoTaskMem_PositiveSize>b__0()
        /_/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ReAllocCoTaskMemTests.cs(64,0): at System.Runtime.InteropServices.Tests.ReAllocCoTaskMemTests.ReAllocCoTaskMem_PositiveSize(Int32 size)
        /_/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs(384,0): at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

ReAllocHGlobalTests and AllocHGlobalTests are different test classes and somehow callstacks are intertwined.
To workaround it, maybe we can try annotating these two classes with sequential execution attribute

[CollectionDefinition("NoParallelTests", DisableParallelization = true)]

- The corner case behavior of Marshal.Realloc method is non-standard and differs between the two realloc methods. Capture the current behavior in tests.
- Add temporary workarounds for Windows vs. Unix differences
- Disable the tests on Mono for now

More test tweaks
@jkotas
Copy link
Member Author

jkotas commented Sep 6, 2020

@AaronRobinsonMSFT Could you please take a look?

I would like to merge this PR and then update the tests in the other PR to document the change. My plan is to unify the corner cases that throw OOM on one platform and do not throw on other platform to not throw everywhere. It should minimize the breaking potential of the unification.

@AaronRobinsonMSFT
Copy link
Member

/cc @jkoritzinsky @elinor-fung

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit a3a7e0d into dotnet:master Sep 7, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT added the disabled-test The test is disabled in source code against the issue label Sep 7, 2020
@jkotas jkotas deleted the realloc-tests branch September 16, 2020 15:00
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices disabled-test The test is disabled in source code against the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants