-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android-Tests] Run Java.Interop tests as well. (#3393)
Context: xamarin/monodroid@e318861 Context: 7d32ef3 Context: 1a2eb95 When use of Java.Interop.dll was originally added in xamarin/monodroid@e318861, it didn't implement the "full" Java.Interop.JniRuntime abstraction, which meant that until commit 1a2eb95, trying to instantiate a JavaInt32Array instance would result in a NotImplementedException, because of Android.Runtime.AndroidValueManager.AddPeer(). Commit 1a2eb95 removed the exception but didn't implement JniRuntime.JniValueManager.AddPeer(), meaning even though a JavaInt32Array could be instantiated, it wouldn't work "properly", e.g. JniRuntime.JniValueManager.PeekPeer() wouldn't find the JavaInt32Array instance when given the same handle. This in turn "happened" because Mono.Android-Tests.dll never executed the unit tests for Java.Interop.dll, which it couldn't do, because it didn't fully support the semantics. Add the Java.Interop.dll unit tests to Mono.Android-Tests.dll, and fix Mono.Android.dll and company so that they can actually pass: Add a new Java.Interop-Tests.csproj project to "host" the Java.Interop unit tests in a MonoAndroid-profile project. Add java-interop.jar to the javac command line generated by Jar.targets, so that e.g. com.xamarin.java_interop.ManagedPeer can be used. Update Mono.Android.dll so that the Java.Interop unit tests work. This includes "migrating" the (jobject => instance) mapping previously accessible via Java.Lang.Object.GetObject<T>() into Android.Runtime.AndroidValueManager. AndroidRuntime.GetExceptionForThrowable() will now "unwrap" a Java.Interop.JavaProxyThrowable instance. AndroidTypeManager.GetSimpleReferences() can't use JNIEnv.GetJniName() on-device because that always returns java/lang/Object, even if a type can't be found, which breaks several Java.Interop unit tests. Use JNIEnv.monodroid_typemap_managed_to_java() instead. AndroidTypeManager.RegisterNativeMembers() will now invoke JniRuntime.JniTypeManager.RegisterNativeMembers() when methods is empty, so that classes can handle their own registration. This was needed so that Java.InteropTests.CallVirtualFromConstructorDerived could actually be properly instantiated and participate in tests. Java.Interop.TypeManager.CreateProxy() now supports Java.Interop-style (ref JniObjectReference, JniObjectReferenceOptions) constructors. Java.Interop.JavaObject and Java.Interop.JavaException are now bridgeable types, and can participate in GC's. This means that e.g. JavaInt32Array instances won't be prematurely collected. src/monodroid will also verify that bridgeable types contain the fields required for use, and provide a better error message when any fields are missing. The Java.Lang.Object and Java.Lang.Throwable finalizers must check Environment.HasShutdownStarted before using JniEnvironment.Runtime, as finalization order is unspecified, so the JniRuntime instance may have been finalized first. With the new changes, the size of Xamarin.Forms_Performance_Integration-Signed.apk increases by ~4kb. I consider this negligible. App startup time isn't significantly impacted either: the average of five Xamarin.Forms_Performance_Integration app launches is 706.2ms with these changes, vs. 706.8ms without these changes. Other Build System Changes: Set $(AndroidLinkMode)=r8 in various projects for consistency with 4bb4b2e. Make Mono.Android-Tests debuggable in Release config, so that GREF logs/etc. can be easily extracted from device, if necessary. Split up external/Java.Interop checkout & preparation logic so that it is usable within unit test environments, which don't contain a full build tree. Add some build-time test-related artifacts to @(_BuildStatusFiles) so that build-time log files are kept. TODO: Java.Lang.Object should be updated to inherit from Java.Interop.JavaObject Java.Lang.Throwable should be updated to inherit from Java.Interop.JavaException generator needs to be updated to begin avoiding the JNIEnv methods, so that non-Java.Lang.*-inheriting types can be used.
- Loading branch information
1 parent
7ff7cb8
commit 130905e
Showing
51 changed files
with
894 additions
and
346 deletions.
There are no files selected for viewing
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
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
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
18 changes: 18 additions & 0 deletions
18
build-tools/xaprepare/xaprepare/Scenarios/Scenario_PrepareExternal.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace Xamarin.Android.Prepare | ||
{ | ||
[Scenario (isDefault: false)] | ||
partial class Scenario_PrepareExternal : ScenarioNoStandardEndSteps | ||
{ | ||
public Scenario_PrepareExternal () | ||
: base ("PrepareExternal", "Prepare external submodules", Context.Instance) | ||
{} | ||
|
||
protected override void AddSteps (Context context) | ||
{ | ||
Steps.Add (new Step_PrepareExternal ()); | ||
Steps.Add (new Step_PrepareExternalJavaInterop ()); | ||
} | ||
} | ||
} |
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
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
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
42 changes: 42 additions & 0 deletions
42
build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Xamarin.Android.Prepare | ||
{ | ||
partial class Step_PrepareExternalJavaInterop | ||
{ | ||
async Task<bool> ExecuteOSSpecific (Context context) | ||
{ | ||
string javaInteropDir = context.Properties.GetRequiredValue (KnownProperties.JavaInteropFullPath); | ||
Log.StatusLine (); | ||
var make = new MakeRunner (context) { | ||
NoParallelJobs = true | ||
}; | ||
var result = await make.Run ( | ||
logTag: "java-interop-prepare", | ||
workingDirectory: javaInteropDir, | ||
arguments: new List <string> { | ||
"prepare", | ||
$"CONFIGURATION={context.Configuration}", | ||
$"JAVA_HOME={context.OS.JavaHome}", | ||
$"JI_MAX_JDK={Configurables.Defaults.MaxJDKVersion}", | ||
} | ||
); | ||
if (!result) | ||
return false; | ||
|
||
Log.StatusLine (); | ||
result = await make.Run ( | ||
logTag: "java-interop-props", | ||
workingDirectory: javaInteropDir, | ||
arguments: new List <string> { | ||
$"bin/Build{context.Configuration}/JdkInfo.props", | ||
$"CONFIGURATION={context.Configuration}", | ||
$"JI_MAX_JDK={Configurables.Defaults.MaxJDKVersion}", | ||
} | ||
); | ||
return result; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Windows.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Xamarin.Android.Prepare | ||
{ | ||
partial class Step_PrepareExternalJavaInterop | ||
{ | ||
async Task<bool> ExecuteOSSpecific (Context context) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Xamarin.Android.Prepare | ||
{ | ||
partial class Step_PrepareExternalJavaInterop : Step | ||
{ | ||
public Step_PrepareExternalJavaInterop () | ||
: base ("Preparing external/Java.Interop") | ||
{} | ||
|
||
protected override async Task<bool> Execute (Context context) | ||
{ | ||
return await ExecuteOSSpecific (context); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.