-
Notifications
You must be signed in to change notification settings - Fork 54
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
[Java.Interop-Tests] Initial dotnet test
support
#801
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
748d156
to
0f81620
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
0f81620
to
827c627
Compare
Context: dotnet/android#5592 With introductory support for `Java.Interop.dll` on .NET Core via commit 2a299eb, what about running the unit tests within `Java.Interop-Tests.dll` on .NET Core? Update `src/java-interop` so that the `java-interop` native library is copied to `$(OutputPath)` of referencing projects. This allows e.g. `libjava-interop.dylib` to be implicitly copied into the appropriate output dir, e.g. `bin/TestDebug-netcoreapp3.1`. Further update `src/java-interop` so that `$(IntermediateOutputPath)` correctly differs between net472 and netcoreapp3.1 builds, and generate `jni.c` into `$(IntermediateOutputPath)`. This ensures that e.g. `bin/Debug/libjava-interop.dylib` reliably uses Mono on net472, instead of occasionally/accidentally being the netstandard version. Update `tests/Java.Interop-Tests` and `tests/TestJVM/TestJVM.csproj` to multitarget between net472 and netcoreapp3.1. Update `Java.Runtime.Environment.csproj` to reference `java-interop.csproj`, which causes all projects which reference `Java.Runtime.Environment.csproj` to get the `java-interop` native library copied to the appropriate `$(OutputPath)`. Update `JreRuntime` to use "dummy" `JniRuntime.JniValueManager` and `JniRuntime.JniObjectReferenceManager` subclasses when *not* running under Mono. This avoids an `ArgumentException` when creating the `Java.InteropTests.JavaVMFixture` instance used by the unit tests. Update `tests/TestJVM` to reference `Xamarin.Android.Tools.AndroidSdk.csproj`, allowing the `TestJVM` type to use `JdkInfo` to find a JVM to use. This allows us to avoid a requirement to set the `JI_JVM_PATH` environment variable in order to create `TestJVM` instances. Update `src/Java.Interop` so that generic delegate types are not marshaled via P/Invoke. .NET Core doesn't support this. Update `JniEnvironment.Types.FindClass()` to call `info.Runtime.GetExceptionForThrowable()` as soon as possible after calling `JNIEnv::ExceptionClear()`, instead of potentially after calling `ClassLoader.loadClass()`. The problem is Java-side stack- frames: if `info.Runtime.GetExceptionForThrowable()` is delayed, then the exception created by `info.Runtime.GetExceptionForThrowable()` only contains the Java message text, but no stack trace, and no "cause" information. This meant that when generic delegate types were still being used, `dotnet test` failures would show: java.lang.NoClassDefFoundError: Could not initialize class com.xamarin.interop.CallVirtualFromConstructorDerive with *no* additional information about *why* it failed. (It failed because P/Invoke was trying to marshal a generic delegate, so the `ManagedPeer` static constructor threw an exception, which was "within" a `static{ManagedPeer.registerNativeMembers(…)}` Java block, and thus the Java type initializer failed, so nothing worked.) Update `**/*.java` to remove Version, Culture, and PublicKeyToken information from the assembly qualified name, for two reasons: 1. The default Version value appears to differ between net472 (0.0.0.0) and netcoreapp3.1 (1.0.0.0). 2. Wrt dotnet/android#5592, certain "security products" believe that the Version number is an *IP address*, and emit a warning about "IP Address disclosure". Since we don't strong-name any of these assemblies (unit tests!) *or* the expected execution environment is a "self-contained app" in which you can't have multiple versions of the same assembly (Xamarin.Android), remove the Version, Culture, and PublicKeyToken information from these Java Callable Wrappers.
827c627
to
4b8b232
Compare
dotnet test
support
Note that this is initial; it is not "complete":
16 tests pass, mostly because the |
jpobst
approved these changes
Feb 17, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: dotnet/android#5592
With introductory support for
Java.Interop.dll
on .NET Core viacommit 2a299eb, what about running the unit tests within
Java.Interop-Tests.dll
on .NET Core?Update
src/java-interop
so that thejava-interop
native libraryis copied to
$(OutputPath)
of referencing projects. This allowse.g.
libjava-interop.dylib
to be implicitly copied into theappropriate output dir, e.g.
bin/TestDebug-netcoreapp3.1
.Further update
src/java-interop
so that$(IntermediateOutputPath)
correctly differs between net472 and netcoreapp3.1 builds, and
generate
jni.c
into$(IntermediateOutputPath)
. This ensures thate.g.
bin/Debug/libjava-interop.dylib
reliably uses Mono on net472,instead of occasionally/accidentally being the netstandard version.
Update
tests/Java.Interop-Tests
andtests/TestJVM/TestJVM.csproj
to multitarget between net472 and netcoreapp3.1.
Update
Java.Runtime.Environment.csproj
to referencejava-interop.csproj
, which causes all projects which referenceJava.Runtime.Environment.csproj
to get thejava-interop
nativelibrary copied to the appropriate
$(OutputPath)
.Update
JreRuntime
to use "dummy"JniRuntime.JniValueManager
andJniRuntime.JniObjectReferenceManager
subclasses when not runningunder Mono. This avoids an
ArgumentException
when creating theJava.InteropTests.JavaVMFixture
instance used by the unit tests.Update
tests/TestJVM
to referenceXamarin.Android.Tools.AndroidSdk.csproj
, allowing theTestJVM
typeto use
JdkInfo
to find a JVM to use. This allows us to avoid arequirement to set the
JI_JVM_PATH
environment variable in order tocreate
TestJVM
instances.Update
src/Java.Interop
so that generic delegate types are notmarshaled via P/Invoke. .NET Core doesn't support this.
Update
JniEnvironment.Types.FindClass()
to callinfo.Runtime.GetExceptionForThrowable()
as soon as possible aftercalling
JNIEnv::ExceptionClear()
, instead of potentially aftercalling
ClassLoader.loadClass()
. The problem is Java-side stack-frames: if
info.Runtime.GetExceptionForThrowable()
is delayed, thenthe exception created by
info.Runtime.GetExceptionForThrowable()
only contains the Java message text, but no stack trace, and no
"cause" information. This meant that when generic delegate types
were still being used,
dotnet test
failures would show:with no additional information about why it failed.
(It failed because P/Invoke was trying to marshal a generic delegate,
so the
ManagedPeer
static constructor threw an exception, whichwas "within" a
static{ManagedPeer.registerNativeMembers(…)}
Javablock, and thus the Java type initializer failed, so nothing worked.)
Update
**/*.java
to remove Version, Culture, and PublicKeyTokeninformation from the assembly qualified name, for two reasons:
The default Version value appears to differ between
net472 (0.0.0.0) and netcoreapp3.1 (1.0.0.0).
Wrt MobSf Scan Security issue android#5592, certain "security products"
believe that the Version number is an IP address, and emit a
warning about "IP Address disclosure".
Since we don't strong-name any of these assemblies (unit tests!)
or the expected execution environment is a "self-contained app"
in which you can't have multiple versions of the same assembly
(Xamarin.Android), remove the Version, Culture, and PublicKeyToken
information from these Java Callable Wrappers.