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

[Mono Interp] CoreCLR tests failed with Mono interpreter: Interop/NativeLibrary/API/NativeLibraryTests #38826

Closed
fanyang-mono opened this issue Jul 6, 2020 · 11 comments · Fixed by #41098 or mono/mono#20274

Comments

@fanyang-mono
Copy link
Member

fanyang-mono commented Jul 6, 2020

Repro:

  1. cd src/mono/netcore
  2. export MONO_ENV_OPTIONS=--interpreter
  3. make run-tests-coreclr CoreClrTest="bash ../../artifacts/tests/coreclr/OSX.x64.Debug/Interop/NativeLibrary/API/NativeLibraryTests/NativeLibraryTests.sh"

Log:

  BEGIN EXECUTION
  /Users/fanyang/Documents/work/dotnet_test/runtime/artifacts/tests/coreclr/OSX.x64.Debug/Tests/Core_Root/corerun NativeLibraryTests.dll ''
  Unhandled exception System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_test/runtime/artifacts/tests/coreclr/OSX.x64.Debug/Interop/NativeLibrary/API/NativeLibraryTests/notfound
     at System.String.Format(String format, Object arg0, Object arg1) in /Users/fanyang/Documents/work/dotnet_test/runtime/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs:line 475
     at NativeLibraryTest.EXPECT(TestResult actualValue, TestResult expectedValue) in /Users/fanyang/Documents/work/dotnet_test/runtime/src/coreclr/tests/src/Interop/NativeLibrary/API/NativeLibraryTests.cs:line 206
     at NativeLibraryTest.Main() in /Users/fanyang/Documents/work/dotnet_test/runtime/src/coreclr/tests/src/Interop/NativeLibrary/API/NativeLibraryTests.cs:line 78
  Expected: 100
  Actual: 156
  END EXECUTION - FAILED

/cc @CoffeeFlux

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jul 6, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Jul 6, 2020

Tagging subscribers to this area: @CoffeeFlux
Notify danmosemsft if you want to be subscribed.

@SamMonoRT
Copy link
Member

@fanyang-mono Just confirming, this is failing only on the Interpreter and not JIT runs?
/cc @BrzVlad @CoffeeFlux

@fanyang-mono
Copy link
Member Author

@fanyang-mono Just confirming, this is failing only on the Interpreter and not JIT runs?
/cc @BrzVlad @CoffeeFlux

That is correct.

@CoffeeFlux
Copy link
Contributor

This failure is somewhat interesting, and likely a true interpreter bug. I tried last week to come up with a standalone repro and failed, but for a summary of what's happening:

On the line in question (below), we call LoadLibraryAdvanced. In that, we call NativeLibrary.Load from inside another function Run that is intended to catch a variety of exceptions, including DllNotFoundException (the one thrown here). For some reason, it isn't being caught and bubbles up to the top of the stack, where we throw an exception. This does not happen on JIT, and throwing a DllNotFoundException here is the intended behavior, but I'm not familiar enough with interpreter internals to easily identify what's going on there.

success &= EXPECT(LoadLibraryAdvanced(libName, assembly, null), TestResult.DllNotFound);

The bug doesn't seem urgent, since I found it difficult to trigger isolated from the testing setup, but it would be nice to know why this is failing. Exceptions mysteriously not getting caught is less than ideal.

@ghost
Copy link

ghost commented Jul 20, 2020

Tagging subscribers to this area: @BrzVlad, @lewurm
Notify danmosemsft if you want to be subscribed.

@CoffeeFlux
Copy link
Contributor

@danmosemsft can you turn off notifications for Bernhard? See mono/mono#19895

@CoffeeFlux CoffeeFlux removed the untriaged New issue has not been triaged by the area owner label Jul 20, 2020
@danmoseley
Copy link
Member

@CoffeeFlux done

@fanyang-mono
Copy link
Member Author

fanyang-mono commented Aug 20, 2020

Simplified repro:

using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
	    Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
	    string assemblyDir = Path.GetDirectoryName(assembly.Location);
	    string libName = Path.Combine(assemblyDir, "notfound");
	    IntPtr handle = IntPtr.Zero;
	    try
	    {
		    handle = NativeLibrary.Load(libName, assembly, null);
	    }
	    catch (Exception e)
	    {
		    Console.WriteLine("{0} Exception caught.", e);
	    }
	    NativeLibrary.Free(handle);
        }
    }
}

@fanyang-mono
Copy link
Member Author

fanyang-mono commented Aug 20, 2020

Follow-up to my previous comment:
Expected:

 System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
    at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs:line 13
    at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 94
    at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 18 Exception caught.

Interpreter mode without fix:

Unhandled Exception:
System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
   at System.Runtime.InteropServices.NativeLibrary.Free(IntPtr handle) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 148
   at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 24
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/bin/notfound
   at System.Runtime.InteropServices.NativeLibrary.Free(IntPtr handle) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs:line 148
   at HelloWorld.Program.Main(String[] args) in /Users/fanyang/Documents/work/dotnet_latest/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 24

@fanyang-mono
Copy link
Member Author

Basically, the problem is that when calling System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName, a pending exception was created but wasn't thrown.

monojenkins pushed a commit to monojenkins/mono that referenced this issue Aug 20, 2020
akoeplinger pushed a commit to mono/mono that referenced this issue Aug 21, 2020
@fanyang-mono fanyang-mono changed the title CoreCLR tests failed with Mono interpreter: Interop/NativeLibrary/API/NativeLibraryTests [Mono Interp] CoreCLR tests failed with Mono interpreter: Interop/NativeLibrary/API/NativeLibraryTests Nov 16, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants