Skip to content

Commit 1b3a76c

Browse files
jonpryordellis1972
authored andcommitted
[Mono.Android-Test] Import Mono.Android tests from monodroid/9c5b3712 (#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.
1 parent 4c81668 commit 1b3a76c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4355
-2
lines changed

Diff for: Makefile

+20-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ prepare:
2626
(cd external/Java.Interop && nuget restore)
2727

2828

29-
run-all-tests: run-nunit-tests
29+
run-all-tests: run-nunit-tests run-apk-tests
3030

3131
clean:
3232
$(MSBUILD) /t:Clean
3333

34-
3534
# $(call RUN_NUNIT_TEST,filename,log-lref?)
3635
define RUN_NUNIT_TEST
3736
MONO_TRACE_LISTENER=Console.Out \
@@ -43,3 +42,22 @@ endef
4342

4443
run-nunit-tests: $(NUNIT_TESTS)
4544
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))
45+
46+
# Test .apk projects must satisfy the following requirements:
47+
# 1. They must have a UnDeploy target
48+
# 2. They must have a Deploy target
49+
# 3. They must have a RunTests target
50+
TEST_APK_PROJECTS = \
51+
src/Mono.Android/Test/Mono.Android-Tests.csproj
52+
53+
# Syntax: $(call RUN_TEST_APK,path/to/project.csproj)
54+
define RUN_TEST_APK
55+
# Must use xabuild to ensure correct assemblies are resolved
56+
tools/scripts/xabuild /t:SignAndroidPackage $(1) && \
57+
$(MSBUILD) /t:UnDeploy $(1) && \
58+
$(MSBUILD) /t:Deploy $(1) && \
59+
$(MSBUILD) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",)
60+
endef
61+
62+
run-apk-tests:
63+
$(foreach p, $(TEST_APK_PROJECTS), $(call RUN_TEST_APK, $(p)))

Diff for: Xamarin.Android.sln

+15
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "src
6161
EndProject
6262
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}"
6363
EndProject
64+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
65+
EndProject
6466
Global
6567
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6668
Debug|AnyCPU = Debug|AnyCPU
@@ -238,6 +240,18 @@ Global
238240
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
239241
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
240242
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
243+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
244+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
245+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
246+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU
247+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
248+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
249+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
250+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
251+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
252+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
253+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
254+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
241255
EndGlobalSection
242256
GlobalSection(NestedProjects) = preSolution
243257
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
@@ -266,6 +280,7 @@ Global
266280
{4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
267281
{2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
268282
{53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
283+
{40EAD437-216B-4DF4-8258-3F47E1672C3A} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
269284
EndGlobalSection
270285
GlobalSection(MonoDevelopProperties) = preSolution
271286
Policies = $0

Diff for: src/Mono.Android/Test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libs

Diff for: src/Mono.Android/Test/Android.App/ApplicationTest.cs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content;
5+
using Android.Content.PM;
6+
using Android.OS;
7+
using Android.Runtime;
8+
9+
using NUnit.Framework;
10+
11+
namespace Android.AppTests
12+
{
13+
[TestFixture]
14+
public class ApplicationTest
15+
{
16+
[Test]
17+
public void ApplicationContextIsApp ()
18+
{
19+
Assert.IsTrue (Application.Context is App);
20+
Assert.IsTrue (App.Created);
21+
}
22+
23+
[Test]
24+
public void SynchronizationContext_Is_ThreadingSynchronizationContextCurrent ()
25+
{
26+
bool same = false;
27+
Application.SynchronizationContext.Send (_ => {
28+
var c = System.Threading.SynchronizationContext.Current;
29+
same = object.ReferenceEquals (c, Application.SynchronizationContext);
30+
}, null);
31+
Assert.IsTrue (same);
32+
}
33+
34+
[Test]
35+
public void SynchronizationContext_Post_DoesNotBlock ()
36+
{
37+
// To ensure we're on the main thread:
38+
bool sendFinishedBeforePost = false;
39+
Application.SynchronizationContext.Send (_ => {
40+
bool postWasExecuted = false;
41+
Application.SynchronizationContext.Post (_2 => {
42+
postWasExecuted = true;
43+
}, null);
44+
if (!postWasExecuted)
45+
sendFinishedBeforePost = true;
46+
}, null);
47+
Assert.IsTrue (sendFinishedBeforePost);
48+
}
49+
50+
[Test]
51+
public void EnsureAndroidManifestIsUpdated ()
52+
{
53+
var klass = Java.Lang.Class.FromType (typeof (RenamedActivity));
54+
var context = Application.Context;
55+
using (var n = new ComponentName (context, klass)) {
56+
var activityInfo = context.PackageManager.GetActivityInfo (n, 0);
57+
var configChanges = activityInfo.ConfigChanges;
58+
Assert.AreEqual (ConfigChanges.KeyboardHidden, configChanges);
59+
}
60+
}
61+
}
62+
63+
public class App : Application {
64+
65+
public static bool Created;
66+
67+
public App (IntPtr handle, JniHandleOwnership transfer)
68+
: base (handle, transfer)
69+
{
70+
Created = true;
71+
}
72+
73+
public override void OnCreate ()
74+
{
75+
base.OnCreate ();
76+
}
77+
}
78+
79+
[Activity]
80+
public class RenamedActivity : Activity {
81+
82+
protected override void OnCreate (Bundle bundle)
83+
{
84+
base.OnCreate (bundle);
85+
86+
Finish ();
87+
}
88+
}
89+
}

Diff for: src/Mono.Android/Test/Android.Content/IntentTest.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
using Android.Content;
4+
5+
using NUnit.Framework;
6+
7+
namespace Android.ContentTests
8+
{
9+
[TestFixture]
10+
public class IntentTest
11+
{
12+
[Test]
13+
public void PutCharSequenceArrayListExtra_NullValue ()
14+
{
15+
using (var intent = new Intent ()) {
16+
intent.PutCharSequenceArrayListExtra ("null", null);
17+
Assert.AreEqual (null, intent.GetCharSequenceArrayListExtra ("null"));
18+
}
19+
}
20+
}
21+
}

Diff for: src/Mono.Android/Test/Android.OS/HandlerTest.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Threading;
3+
using Android.OS;
4+
5+
using NUnit.Framework;
6+
7+
namespace Xamarin.Android.RuntimeTests {
8+
9+
[TestFixture]
10+
public class HandlerTest {
11+
12+
[Test]
13+
public void RemoveDisposedInstance ()
14+
{
15+
using (var t = new HandlerThread ("RemoveDisposedInstance")) {
16+
t.Start ();
17+
using (var h = new Handler (t.Looper)) {
18+
var e = new ManualResetEvent (false);
19+
Java.Lang.Runnable r = null;
20+
r = new Java.Lang.Runnable (() => {
21+
e.Set ();
22+
r.Dispose ();
23+
});
24+
h.Post (r.Run);
25+
e.WaitOne ();
26+
}
27+
28+
t.QuitSafely ();
29+
}
30+
}
31+
}
32+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
using Android.Runtime;
4+
5+
using NUnit.Framework;
6+
7+
namespace Android.RuntimeTests {
8+
9+
[TestFixture]
10+
public class CharSequenceTest {
11+
12+
[Test]
13+
public void ToLocalJniHandle ()
14+
{
15+
using (var s = new Java.Lang.String ("s")) {
16+
var p = CharSequence.ToLocalJniHandle (s);
17+
JNIEnv.DeleteLocalRef (p);
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
using Android.Runtime;
6+
7+
using NUnit.Framework;
8+
9+
namespace Android.RuntimeTests
10+
{
11+
[TestFixture]
12+
public class JavaCollectionTest
13+
{
14+
[Test]
15+
public void CopyTo ()
16+
{
17+
using (var al = new Java.Util.ArrayList ()) {
18+
al.Add (1);
19+
al.Add (2);
20+
al.Add (3);
21+
22+
using (var c = new JavaCollection (al.Handle, JniHandleOwnership.DoNotTransfer)) {
23+
var to = new int[3];
24+
c.CopyTo (to, 0);
25+
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
26+
}
27+
28+
using (var c = new JavaCollection<int> (al.Handle, JniHandleOwnership.DoNotTransfer)) {
29+
var to = new int[3];
30+
c.CopyTo (to, 0);
31+
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
32+
}
33+
}
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)