Skip to content

Commit

Permalink
[Mono.Android-Test] Import Mono.Android tests from monodroid/9c5b3712 (
Browse files Browse the repository at this point in the history
…#32)

Import monodroid/tests/runtime from monodroid/9c5b3712.

Add a toplevel `make run-apk-tests` target to "full stack" tests, in
which a .apk is created, installed, and executed on an attached
Android device. `make run-apk-tests` requires that `adb` be in $PATH,
and uses GNU make(1) features, and...

Additionally, tools/scripts/xabuild *must* be used to execute the
`SignAndroidPackage` target, to ensure that the local/"in tree"
assemblies are used. There is no "within xbuild" facility to alter
where target framework assemblies are resolved from, i.e no MSBuild
properties currently control the resolution order, only environment
variables, and MSBuild can't *set* environment variables...

The $(ADB_TARGET) variable can be used to control on which target
Android device the tests will be installed and executed on:

	# Install & run tests on *only* connected USB device
	$ make run-apk-tests ADB_TARGET=-d

	# Install & run tests on *only* connected emulator
	$ make run-apk-tests ADB_TARGET=-e

	# Install & run tests on specified device, listed via `adb devices`.
	$ make run-apk-tests ADB_TARGET="-s 036533824381cfcb"

Sorry potential/future Windows developers. *Running* tests will
require manual testing or running on OS X or Linux for now...

Note: These tests DO NOT PASS. In fact, they *crash*:

	$ make run-apk-tests
	...
	 Target RunTests:
	 	Executing: "$HOME/android-toolchain/sdk/platform-tools/adb"   shell am instrument -w Mono.Android_Tests/xamarin.android.runtimetests.TestInstrumentation
	 	INSTRUMENTATION_RESULT: shortMsg=Process crashed.
	 	INSTRUMENTATION_CODE: 0

	$ adb logcat
	...
	E mono    : Unhandled Exception:
	E mono    : System.ObjectDisposedException: Cannot access a disposed object.
	E mono    : Object name: 'System.Net.Sockets.Socket'.
	E mono    :   at System.Net.Sockets.Socket.ThrowIfDisposedAndClosed () <0xa93923f0 + 0x00054> in <filename unknown>:0
	E mono    :   at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8f9680 + 0x0001b> in <filename unknown>:0
	E mono    :   at System.Net.EndPointListener.Accept (System.Net.Sockets.Socket socket, System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8f95d0 + 0x0003f> in <filename unknown>:0
	E mono    :   at System.Net.EndPointListener.ProcessAccept (System.Net.Sockets.SocketAsyncEventArgs args) <0x9b8e0340 + 0x0007f> in <filename unknown>:0
	E mono    :   at System.Net.EndPointListener.OnAccept (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8e0310 + 0x00017> in <filename unknown>:0
	E mono    :   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8e02c8 + 0x0003b> in <filename unknown>:0
	E mono    :   at System.Net.Sockets.SocketAsyncEventArgs.Complete () <0x9b8e02a0 + 0x0001f> in <filename unknown>:0
	E mono    :   at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) <0x9b8dfd40 + 0x002af> in <filename unknown>:0
	E mono    :   at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) <0xa892f720 + 0x0002b> in <filename unknown>:0
	E mono    :   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0xa938f6b8 + 0x0002f> in <filename unknown>:0
	E mono    :   at System.Threading.ThreadPoolWorkQueue.Dispatch () <0xa938e358 + 0x001bb> in <filename unknown>:0
	E mono    :   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0xa938e1a8 + 0x00007> in <filename unknown>:0

Looks like a Socket and/or ThreadPool bug in mono.
  • Loading branch information
jonpryor authored and dellis1972 committed May 16, 2016
1 parent 4c81668 commit 1b3a76c
Show file tree
Hide file tree
Showing 56 changed files with 4,355 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ prepare:
(cd external/Java.Interop && nuget restore)


run-all-tests: run-nunit-tests
run-all-tests: run-nunit-tests run-apk-tests

clean:
$(MSBUILD) /t:Clean


# $(call RUN_NUNIT_TEST,filename,log-lref?)
define RUN_NUNIT_TEST
MONO_TRACE_LISTENER=Console.Out \
Expand All @@ -43,3 +42,22 @@ endef

run-nunit-tests: $(NUNIT_TESTS)
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))

# Test .apk projects must satisfy the following requirements:
# 1. They must have a UnDeploy target
# 2. They must have a Deploy target
# 3. They must have a RunTests target
TEST_APK_PROJECTS = \
src/Mono.Android/Test/Mono.Android-Tests.csproj

# Syntax: $(call RUN_TEST_APK,path/to/project.csproj)
define RUN_TEST_APK
# Must use xabuild to ensure correct assemblies are resolved
tools/scripts/xabuild /t:SignAndroidPackage $(1) && \
$(MSBUILD) /t:UnDeploy $(1) && \
$(MSBUILD) /t:Deploy $(1) && \
$(MSBUILD) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",)
endef

run-apk-tests:
$(foreach p, $(TEST_APK_PROJECTS), $(call RUN_TEST_APK, $(p)))
15 changes: 15 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Build.Tests", "src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj", "{53E4ABF0-1085-45F9-B964-DCAE4B819998}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AnyCPU = Debug|AnyCPU
Expand Down Expand Up @@ -238,6 +240,18 @@ Global
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
Expand Down Expand Up @@ -266,6 +280,7 @@ Global
{4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{40EAD437-216B-4DF4-8258-3F47E1672C3A} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
Expand Down
1 change: 1 addition & 0 deletions src/Mono.Android/Test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs
89 changes: 89 additions & 0 deletions src/Mono.Android/Test/Android.App/ApplicationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;

using NUnit.Framework;

namespace Android.AppTests
{
[TestFixture]
public class ApplicationTest
{
[Test]
public void ApplicationContextIsApp ()
{
Assert.IsTrue (Application.Context is App);
Assert.IsTrue (App.Created);
}

[Test]
public void SynchronizationContext_Is_ThreadingSynchronizationContextCurrent ()
{
bool same = false;
Application.SynchronizationContext.Send (_ => {
var c = System.Threading.SynchronizationContext.Current;
same = object.ReferenceEquals (c, Application.SynchronizationContext);
}, null);
Assert.IsTrue (same);
}

[Test]
public void SynchronizationContext_Post_DoesNotBlock ()
{
// To ensure we're on the main thread:
bool sendFinishedBeforePost = false;
Application.SynchronizationContext.Send (_ => {
bool postWasExecuted = false;
Application.SynchronizationContext.Post (_2 => {
postWasExecuted = true;
}, null);
if (!postWasExecuted)
sendFinishedBeforePost = true;
}, null);
Assert.IsTrue (sendFinishedBeforePost);
}

[Test]
public void EnsureAndroidManifestIsUpdated ()
{
var klass = Java.Lang.Class.FromType (typeof (RenamedActivity));
var context = Application.Context;
using (var n = new ComponentName (context, klass)) {
var activityInfo = context.PackageManager.GetActivityInfo (n, 0);
var configChanges = activityInfo.ConfigChanges;
Assert.AreEqual (ConfigChanges.KeyboardHidden, configChanges);
}
}
}

public class App : Application {

public static bool Created;

public App (IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
Created = true;
}

public override void OnCreate ()
{
base.OnCreate ();
}
}

[Activity]
public class RenamedActivity : Activity {

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

Finish ();
}
}
}
21 changes: 21 additions & 0 deletions src/Mono.Android/Test/Android.Content/IntentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

using Android.Content;

using NUnit.Framework;

namespace Android.ContentTests
{
[TestFixture]
public class IntentTest
{
[Test]
public void PutCharSequenceArrayListExtra_NullValue ()
{
using (var intent = new Intent ()) {
intent.PutCharSequenceArrayListExtra ("null", null);
Assert.AreEqual (null, intent.GetCharSequenceArrayListExtra ("null"));
}
}
}
}
32 changes: 32 additions & 0 deletions src/Mono.Android/Test/Android.OS/HandlerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Threading;
using Android.OS;

using NUnit.Framework;

namespace Xamarin.Android.RuntimeTests {

[TestFixture]
public class HandlerTest {

[Test]
public void RemoveDisposedInstance ()
{
using (var t = new HandlerThread ("RemoveDisposedInstance")) {
t.Start ();
using (var h = new Handler (t.Looper)) {
var e = new ManualResetEvent (false);
Java.Lang.Runnable r = null;
r = new Java.Lang.Runnable (() => {
e.Set ();
r.Dispose ();
});
h.Post (r.Run);
e.WaitOne ();
}

t.QuitSafely ();
}
}
}
}
21 changes: 21 additions & 0 deletions src/Mono.Android/Test/Android.Runtime/CharSequenceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

using Android.Runtime;

using NUnit.Framework;

namespace Android.RuntimeTests {

[TestFixture]
public class CharSequenceTest {

[Test]
public void ToLocalJniHandle ()
{
using (var s = new Java.Lang.String ("s")) {
var p = CharSequence.ToLocalJniHandle (s);
JNIEnv.DeleteLocalRef (p);
}
}
}
}
37 changes: 37 additions & 0 deletions src/Mono.Android/Test/Android.Runtime/JavaCollectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Android.Runtime;

using NUnit.Framework;

namespace Android.RuntimeTests
{
[TestFixture]
public class JavaCollectionTest
{
[Test]
public void CopyTo ()
{
using (var al = new Java.Util.ArrayList ()) {
al.Add (1);
al.Add (2);
al.Add (3);

using (var c = new JavaCollection (al.Handle, JniHandleOwnership.DoNotTransfer)) {
var to = new int[3];
c.CopyTo (to, 0);
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
}

using (var c = new JavaCollection<int> (al.Handle, JniHandleOwnership.DoNotTransfer)) {
var to = new int[3];
c.CopyTo (to, 0);
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
}
}
}
}
}

Loading

0 comments on commit 1b3a76c

Please sign in to comment.