Skip to content

Commit faf1d16

Browse files
authored
[Xamarin.Android.Build.Tests] Import regression tests from job 1 (#5030)
Context: https://github.com/xamarin/QualityAssurance/pull/3639 This is an initial effort to migrate non duplicated and relevant tests from QualityAssurance into xamarin-android. The majority of test categories that ran in the first regression test job have been audited, and a few tests have been imported while the rest have been removed. The remaining regression test categories that were ran as part of the first and second regression test jobs have been merged, and the third job has been removed. Device tests that searched for `.__override__` directory content after a Release build have been updated to have a stricter assert. These tests will also now set `android:debuggable="true"` to allow usage of the run-as command, which is required when attempting to list the content of the potential `/data/data/*` location. The DeviceTest base class has been updated to ensure logcat output is captured on failure by escaping the destination path, and a duplicate `AddTestAttachment` call has been removed.
1 parent d94ebbd commit faf1d16

File tree

11 files changed

+213
-165
lines changed

11 files changed

+213
-165
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ stages:
11031103
condition: and(eq(dependencies.mac_build.result, 'Succeeded'), eq(variables['RunAllTests'], true))
11041104
jobs:
11051105

1106-
# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
1106+
# Check - "Xamarin.Android (Regression Tests Mac-1)"
11071107
- job: integrated_regression_mac_1
11081108
displayName: Mac-1
11091109
pool:
@@ -1119,7 +1119,7 @@ stages:
11191119
parameters:
11201120
node_id: 1
11211121

1122-
# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
1122+
# Check - "Xamarin.Android (Regression Tests Mac-2)"
11231123
- job: integrated_regression_mac_2
11241124
displayName: Mac-2
11251125
pool:
@@ -1135,23 +1135,7 @@ stages:
11351135
parameters:
11361136
node_id: 2
11371137

1138-
# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
1139-
- job: integrated_regression_mac_3
1140-
displayName: Mac-3
1141-
pool:
1142-
name: VSEng-Xamarin-Mac-Devices
1143-
demands:
1144-
- android
1145-
timeoutInMinutes: 240
1146-
cancelTimeoutInMinutes: 5
1147-
workspace:
1148-
clean: all
1149-
steps:
1150-
- template: yaml-templates/run-integrated-regression-tests.yaml
1151-
parameters:
1152-
node_id: 3
1153-
1154-
# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
1138+
# Check - "Xamarin.Android (Regression Tests Windows-1)"
11551139
- job: integrated_regression_Win_1
11561140
displayName: Windows-1
11571141
pool:
@@ -1173,7 +1157,7 @@ stages:
11731157

11741158
- template: remove-visualstudio.yml@yaml
11751159

1176-
# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
1160+
# Check - "Xamarin.Android (Regression Tests Windows-2)"
11771161
- job: integrated_regression_Win_2
11781162
displayName: Windows-2
11791163
pool:
@@ -1195,28 +1179,6 @@ stages:
11951179

11961180
- template: remove-visualstudio.yml@yaml
11971181

1198-
# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
1199-
- job: integrated_regression_Win_3
1200-
displayName: Windows-3
1201-
pool:
1202-
name: VSEng-Xamarin-Win-XMA
1203-
demands:
1204-
- android
1205-
timeoutInMinutes: 240
1206-
cancelTimeoutInMinutes: 5
1207-
workspace:
1208-
clean: all
1209-
variables:
1210-
XQA_VISUALSTUDIO_LOCATION: '%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise'
1211-
steps:
1212-
- template: remove-visualstudio.yml@yaml
1213-
1214-
- template: yaml-templates\run-integrated-regression-tests.yaml
1215-
parameters:
1216-
node_id: 3
1217-
1218-
- template: remove-visualstudio.yml@yaml
1219-
12201182
# TimeZoneInfo tests
12211183
- template: yaml-templates\run-timezoneinfo-tests.yaml
12221184
parameters:

build-tools/automation/yaml-templates/run-integrated-regression-tests.yaml

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -90,51 +90,6 @@ steps:
9090
testRunTitle: Smoke Tests on Device
9191
nunitConsoleExtraArgs: --where "cat == RegressionDeviceTests"
9292

93-
- template: run-nunit-tests.yaml
94-
parameters:
95-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
96-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
97-
testRunTitle: Smoke Tests
98-
nunitConsoleExtraArgs: --where "cat == RegressionTests"
99-
100-
- template: run-nunit-tests.yaml
101-
parameters:
102-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
103-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
104-
testRunTitle: Installer Tests
105-
nunitConsoleExtraArgs: --where "cat == InstallationTests"
106-
107-
- template: run-nunit-tests.yaml
108-
parameters:
109-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
110-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
111-
testRunTitle: Fast Deploy Tests
112-
nunitConsoleExtraArgs: --where "cat == FastDevTests"
113-
condition: and(succeeded(), eq(variables['XA.Commercial.Build'], 'true'))
114-
115-
- template: run-nunit-tests.yaml
116-
parameters:
117-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
118-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
119-
testRunTitle: Debug Tests
120-
nunitConsoleExtraArgs: --where "cat == DebuggerTests"
121-
condition: and(succeeded(), eq(variables['XA.Commercial.Build'], 'true'))
122-
123-
- template: run-nunit-tests.yaml
124-
parameters:
125-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
126-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
127-
testRunTitle: Linker Tests
128-
nunitConsoleExtraArgs: --where "cat == LinkerTests"
129-
130-
- template: run-nunit-tests.yaml
131-
parameters:
132-
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
133-
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
134-
testRunTitle: Wearable Tests
135-
nunitConsoleExtraArgs: --where "cat == Wearable"
136-
137-
- ${{ if eq(parameters.node_id, 2) }}:
13893
- template: run-nunit-tests.yaml
13994
parameters:
14095
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
@@ -149,7 +104,7 @@ steps:
149104
testRunTitle: AOT Tests
150105
nunitConsoleExtraArgs: --where "cat == AotSupport"
151106

152-
- ${{ if eq(parameters.node_id, 3) }}:
107+
- ${{ if eq(parameters.node_id, 2) }}:
153108
- template: run-nunit-tests.yaml
154109
parameters:
155110
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe

src/Mono.Android/Test/Mono.Android-Test.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<Compile Include="$(MSBuildThisFileDirectory)System.Net\SslTest.cs" />
4343
<Compile Include="$(MSBuildThisFileDirectory)System.Net\NetworkInterfaces.cs" />
4444
<Compile Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\DllImportTest.cs" />
45+
<Compile Include="$(MSBuildThisFileDirectory)System.Text\EncodingTests.cs" />
4546
<Compile Include="$(MSBuildThisFileDirectory)System.Threading\InterlockedTest.cs" />
4647
<Compile Include="$(MSBuildThisFileDirectory)Java.Interop\JavaObjectExtensionsTests.cs" />
4748
<Compile Include="$(MSBuildThisFileDirectory)Xamarin.Android.Net\AndroidClientHandlerTests.cs" />

src/Mono.Android/Test/Mono.Android-Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
1919
<AndroidSupportedAbis>armeabi-v7a;x86</AndroidSupportedAbis>
2020
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
21+
<MandroidI18n>All</MandroidI18n>
2122
<SignAssembly>true</SignAssembly>
2223
<AssemblyOriginatorKeyFile>..\..\..\product.snk</AssemblyOriginatorKeyFile>
2324
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Text;
3+
4+
using NUnit.Framework;
5+
6+
namespace Xamarin.Android.RuntimeTests
7+
{
8+
[TestFixture]
9+
public class EncodingTests
10+
{
11+
EncodingInfo[] EncodingTestData = Encoding.GetEncodings ();
12+
13+
[Test, TestCaseSource (nameof (EncodingTestData))]
14+
public void GetAllAvailableEncodings (EncodingInfo info)
15+
{
16+
// Requires <MandroidI18n>All</MandroidI18n> or can throw:
17+
// System.NotSupportedException : Encoding 37 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
18+
Encoding enc = info.GetEncoding ();
19+
Assert.IsNotNull (enc.EncodingName, $"Failed to get Encoding from '{info.DisplayName}'.");
20+
}
21+
}
22+
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
399399
proj.SetProperty (proj.ReleaseProperties, "AndroidSigningKeyPass", Uri.EscapeDataString (pass));
400400
proj.SetProperty (proj.ReleaseProperties, "AndroidSigningStorePass", Uri.EscapeDataString (pass));
401401
proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidCreatePackagePerAbi, perAbiApk);
402-
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
402+
if (perAbiApk) {
403+
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86", "arm64-v8a", "x86_64");
404+
} else {
405+
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
406+
}
403407
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
404408
var bin = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
405409
Assert.IsTrue (b.Build (proj), "First build failed");
@@ -417,6 +421,17 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
417421
}
418422
}
419423

424+
// Make sure the APKs have unique version codes
425+
if (perAbiApk) {
426+
int armManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "armeabi-v7a", "AndroidManifest.xml"));
427+
int x86ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "x86", "AndroidManifest.xml"));
428+
int arm64ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "arm64-v8a", "AndroidManifest.xml"));
429+
int x86_64ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "x86_64", "AndroidManifest.xml"));
430+
var versionList = new List<int> { armManifestCode, x86ManifestCode, arm64ManifestCode, x86_64ManifestCode };
431+
Assert.True (versionList.Distinct ().Count () == versionList.Count,
432+
$"APK version codes were not unique - armeabi-v7a: {armManifestCode}, x86: {x86ManifestCode}, arm64-v8a: {arm64ManifestCode}, x86_64: {x86_64ManifestCode}");
433+
}
434+
420435
var item = proj.AndroidResources.First (x => x.Include () == "Resources\\values\\Strings.xml");
421436
item.TextContent = () => proj.StringsXml.Replace ("${PROJECT_NAME}", "Foo");
422437
item.Timestamp = null;
@@ -435,6 +450,18 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
435450
}
436451
}
437452
}
453+
454+
int GetVersionCodeFromIntermediateManifest (string manifestFilePath)
455+
{
456+
var doc = XDocument.Load (manifestFilePath);
457+
var versionCode = doc.Descendants ()
458+
.Where (e => e.Name == "manifest")
459+
.Select (m => m.Attribute ("{http://schemas.android.com/apk/res/android}versionCode")).FirstOrDefault ();
460+
461+
if (!int.TryParse (versionCode?.Value, out int parsedCode))
462+
Assert.Fail ($"Unable to parse 'versionCode' value from manifest content: {File.ReadAllText (manifestFilePath)}.");
463+
return parsedCode;
464+
}
438465
}
439466

440467
[Test]

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/LinkerTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,52 @@ public void LinkDescription ()
241241
}
242242
}
243243
}
244+
245+
[Test]
246+
public void LinkWithNullAttribute ()
247+
{
248+
var proj = new XamarinAndroidApplicationProject {
249+
IsRelease = true,
250+
OtherBuildItems = {
251+
new BuildItem ("Compile", "NullAttribute.cs") { TextContent = () => @"
252+
using System;
253+
using Android.Content;
254+
using Android.Widget;
255+
namespace UnnamedProject {
256+
public class MyAttribute : Attribute
257+
{
258+
Type[] types;
259+
260+
public Type[] Types {
261+
get { return types; }
262+
}
263+
264+
public MyAttribute (Type[] ta)
265+
{
266+
types = ta;
267+
}
268+
}
269+
270+
[MyAttribute (null)]
271+
public class AttributedButtonStub : Button
272+
{
273+
public AttributedButtonStub (Context context) : base (context)
274+
{
275+
}
276+
}
277+
}"
278+
},
279+
}
280+
};
281+
282+
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}",
283+
$@" var myButton = new AttributedButtonStub (this);
284+
myButton.Text = ""Bug #35710"";
285+
");
286+
287+
using (var b = CreateApkBuilder ()) {
288+
Assert.IsTrue (b.Build (proj), "Building a project with a null attribute value should have succeded.");
289+
}
290+
}
244291
}
245292
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ protected override void CleanupTest ()
2929
string deviceLog = Path.Combine (outputDir, "logcat-failed.log");
3030
string remote = "/data/local/tmp/screenshot.png";
3131
RunAdbCommand ($"shell screencap {remote}");
32+
RunAdbCommand ($"logcat -d > \"{deviceLog}\"");
3233
RunAdbCommand ($"pull {remote} \"{local}\"");
3334
RunAdbCommand ($"shell rm {remote}");
34-
RunAdbCommand ($"logcat -d > {deviceLog}");
3535
if (File.Exists (local)) {
3636
TestContext.AddTestAttachment (local);
3737
} else {
3838
TestContext.WriteLine ($"{local} did not exist!");
3939
}
40-
if (File.Exists (deviceLog)) {
41-
TestContext.AddTestAttachment (deviceLog);
42-
} else {
43-
TestContext.WriteLine ($"{deviceLog} did not exist!");
44-
}
4540
}
4641

4742
base.CleanupTest ();

0 commit comments

Comments
 (0)