Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tests] Import regression tests from job 1 (dot…
Browse files Browse the repository at this point in the history
…net#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.
  • Loading branch information
pjcollins authored Aug 21, 2020
1 parent d94ebbd commit faf1d16
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 165 deletions.
46 changes: 4 additions & 42 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ stages:
condition: and(eq(dependencies.mac_build.result, 'Succeeded'), eq(variables['RunAllTests'], true))
jobs:

# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
# Check - "Xamarin.Android (Regression Tests Mac-1)"
- job: integrated_regression_mac_1
displayName: Mac-1
pool:
Expand All @@ -1119,7 +1119,7 @@ stages:
parameters:
node_id: 1

# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
# Check - "Xamarin.Android (Regression Tests Mac-2)"
- job: integrated_regression_mac_2
displayName: Mac-2
pool:
Expand All @@ -1135,23 +1135,7 @@ stages:
parameters:
node_id: 2

# Check - "Xamarin.Android (Test Integrated Regression - macOS)"
- job: integrated_regression_mac_3
displayName: Mac-3
pool:
name: VSEng-Xamarin-Mac-Devices
demands:
- android
timeoutInMinutes: 240
cancelTimeoutInMinutes: 5
workspace:
clean: all
steps:
- template: yaml-templates/run-integrated-regression-tests.yaml
parameters:
node_id: 3

# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
# Check - "Xamarin.Android (Regression Tests Windows-1)"
- job: integrated_regression_Win_1
displayName: Windows-1
pool:
Expand All @@ -1173,7 +1157,7 @@ stages:

- template: remove-visualstudio.yml@yaml

# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
# Check - "Xamarin.Android (Regression Tests Windows-2)"
- job: integrated_regression_Win_2
displayName: Windows-2
pool:
Expand All @@ -1195,28 +1179,6 @@ stages:

- template: remove-visualstudio.yml@yaml

# Check - "Xamarin.Android (Test Integrated Regression - Windows)"
- job: integrated_regression_Win_3
displayName: Windows-3
pool:
name: VSEng-Xamarin-Win-XMA
demands:
- android
timeoutInMinutes: 240
cancelTimeoutInMinutes: 5
workspace:
clean: all
variables:
XQA_VISUALSTUDIO_LOCATION: '%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise'
steps:
- template: remove-visualstudio.yml@yaml

- template: yaml-templates\run-integrated-regression-tests.yaml
parameters:
node_id: 3

- template: remove-visualstudio.yml@yaml

# TimeZoneInfo tests
- template: yaml-templates\run-timezoneinfo-tests.yaml
parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,6 @@ steps:
testRunTitle: Smoke Tests on Device
nunitConsoleExtraArgs: --where "cat == RegressionDeviceTests"

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Smoke Tests
nunitConsoleExtraArgs: --where "cat == RegressionTests"

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Installer Tests
nunitConsoleExtraArgs: --where "cat == InstallationTests"

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Fast Deploy Tests
nunitConsoleExtraArgs: --where "cat == FastDevTests"
condition: and(succeeded(), eq(variables['XA.Commercial.Build'], 'true'))

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Debug Tests
nunitConsoleExtraArgs: --where "cat == DebuggerTests"
condition: and(succeeded(), eq(variables['XA.Commercial.Build'], 'true'))

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Linker Tests
nunitConsoleExtraArgs: --where "cat == LinkerTests"

- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
testAssembly: $(System.DefaultWorkingDirectory)/XQA.Android/XQA.Android.dll
testRunTitle: Wearable Tests
nunitConsoleExtraArgs: --where "cat == Wearable"

- ${{ if eq(parameters.node_id, 2) }}:
- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
Expand All @@ -149,7 +104,7 @@ steps:
testRunTitle: AOT Tests
nunitConsoleExtraArgs: --where "cat == AotSupport"

- ${{ if eq(parameters.node_id, 3) }}:
- ${{ if eq(parameters.node_id, 2) }}:
- template: run-nunit-tests.yaml
parameters:
nunitConsole: $(System.DefaultWorkingDirectory)/NUnit.ConsoleRunner/tools/nunit3-console.exe
Expand Down
1 change: 1 addition & 0 deletions src/Mono.Android/Test/Mono.Android-Test.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System.Net\SslTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System.Net\NetworkInterfaces.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\DllImportTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System.Text\EncodingTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System.Threading\InterlockedTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Java.Interop\JavaObjectExtensionsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Xamarin.Android.Net\AndroidClientHandlerTests.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Mono.Android/Test/Mono.Android-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidSupportedAbis>armeabi-v7a;x86</AndroidSupportedAbis>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<MandroidI18n>All</MandroidI18n>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\product.snk</AssemblyOriginatorKeyFile>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
Expand Down
22 changes: 22 additions & 0 deletions src/Mono.Android/Test/System.Text/EncodingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Text;

using NUnit.Framework;

namespace Xamarin.Android.RuntimeTests
{
[TestFixture]
public class EncodingTests
{
EncodingInfo[] EncodingTestData = Encoding.GetEncodings ();

[Test, TestCaseSource (nameof (EncodingTestData))]
public void GetAllAvailableEncodings (EncodingInfo info)
{
// Requires <MandroidI18n>All</MandroidI18n> or can throw:
// System.NotSupportedException : Encoding 37 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
Encoding enc = info.GetEncoding ();
Assert.IsNotNull (enc.EncodingName, $"Failed to get Encoding from '{info.DisplayName}'.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
proj.SetProperty (proj.ReleaseProperties, "AndroidSigningKeyPass", Uri.EscapeDataString (pass));
proj.SetProperty (proj.ReleaseProperties, "AndroidSigningStorePass", Uri.EscapeDataString (pass));
proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidCreatePackagePerAbi, perAbiApk);
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
if (perAbiApk) {
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86", "arm64-v8a", "x86_64");
} else {
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
}
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
var bin = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
Assert.IsTrue (b.Build (proj), "First build failed");
Expand All @@ -417,6 +421,17 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
}
}

// Make sure the APKs have unique version codes
if (perAbiApk) {
int armManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "armeabi-v7a", "AndroidManifest.xml"));
int x86ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "x86", "AndroidManifest.xml"));
int arm64ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "arm64-v8a", "AndroidManifest.xml"));
int x86_64ManifestCode = GetVersionCodeFromIntermediateManifest (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "x86_64", "AndroidManifest.xml"));
var versionList = new List<int> { armManifestCode, x86ManifestCode, arm64ManifestCode, x86_64ManifestCode };
Assert.True (versionList.Distinct ().Count () == versionList.Count,
$"APK version codes were not unique - armeabi-v7a: {armManifestCode}, x86: {x86ManifestCode}, arm64-v8a: {arm64ManifestCode}, x86_64: {x86_64ManifestCode}");
}

var item = proj.AndroidResources.First (x => x.Include () == "Resources\\values\\Strings.xml");
item.TextContent = () => proj.StringsXml.Replace ("${PROJECT_NAME}", "Foo");
item.Timestamp = null;
Expand All @@ -435,6 +450,18 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
}
}
}

int GetVersionCodeFromIntermediateManifest (string manifestFilePath)
{
var doc = XDocument.Load (manifestFilePath);
var versionCode = doc.Descendants ()
.Where (e => e.Name == "manifest")
.Select (m => m.Attribute ("{http://schemas.android.com/apk/res/android}versionCode")).FirstOrDefault ();

if (!int.TryParse (versionCode?.Value, out int parsedCode))
Assert.Fail ($"Unable to parse 'versionCode' value from manifest content: {File.ReadAllText (manifestFilePath)}.");
return parsedCode;
}
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,52 @@ public void LinkDescription ()
}
}
}

[Test]
public void LinkWithNullAttribute ()
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
OtherBuildItems = {
new BuildItem ("Compile", "NullAttribute.cs") { TextContent = () => @"
using System;
using Android.Content;
using Android.Widget;
namespace UnnamedProject {
public class MyAttribute : Attribute
{
Type[] types;
public Type[] Types {
get { return types; }
}
public MyAttribute (Type[] ta)
{
types = ta;
}
}
[MyAttribute (null)]
public class AttributedButtonStub : Button
{
public AttributedButtonStub (Context context) : base (context)
{
}
}
}"
},
}
};

proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}",
$@" var myButton = new AttributedButtonStub (this);
myButton.Text = ""Bug #35710"";
");

using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Building a project with a null attribute value should have succeded.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ protected override void CleanupTest ()
string deviceLog = Path.Combine (outputDir, "logcat-failed.log");
string remote = "/data/local/tmp/screenshot.png";
RunAdbCommand ($"shell screencap {remote}");
RunAdbCommand ($"logcat -d > \"{deviceLog}\"");
RunAdbCommand ($"pull {remote} \"{local}\"");
RunAdbCommand ($"shell rm {remote}");
RunAdbCommand ($"logcat -d > {deviceLog}");
if (File.Exists (local)) {
TestContext.AddTestAttachment (local);
} else {
TestContext.WriteLine ($"{local} did not exist!");
}
if (File.Exists (deviceLog)) {
TestContext.AddTestAttachment (deviceLog);
} else {
TestContext.WriteLine ($"{deviceLog} did not exist!");
}
}

base.CleanupTest ();
Expand Down
Loading

0 comments on commit faf1d16

Please sign in to comment.