Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ stages:
testResultsFiles: TestResult-*.xml
testRunTitle: Java Interop Tests - Windows Build Tree

- script: dotnet tool update apkdiff -g
displayName: install apkdiff dotnet tool
continueOnError: true

# Limit the amount of worker threads used to run these tests in parallel to half of what is currently available (8) on the Windows pool.
# Using all available cores seems to occasionally bog down our machines and cause parallel test execution to slow down dramatically.
# Only run a subset of the Xamarin.Android.Build.Tests against the local Windows build tree.
Expand Down Expand Up @@ -412,10 +416,8 @@ stages:
- script: mono $(System.DefaultWorkingDirectory)/build-tools/xaprepare/xaprepare/bin/$(ApkTestConfiguration)/xaprepare.exe --s=EmulatorTestDependencies --no-emoji --run-mode=CI
displayName: install emulator

- task: CmdLine@2
- script: 'dotnet tool update apkdiff -g'
displayName: install apkdiff dotnet tool
inputs:
script: 'dotnet tool update apkdiff -g'
continueOnError: true

- template: yaml-templates/apk-instrumentation.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ jobs:
artifactName: $(TestAssembliesArtifactName)
downloadPath: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)

- task: CmdLine@2
displayName: install apkdiff dotnet tool
inputs:
script: 'dotnet tool update apkdiff -g'
continueOnError: true

- template: run-nunit-tests.yaml
parameters:
useDotNet: $(UseDotNet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
artifactName: $(TestAssembliesArtifactName)
downloadPath: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)

- task: CmdLine@2
displayName: install apkdiff dotnet tool
inputs:
script: 'dotnet tool update apkdiff -g'
continueOnError: true

# Limit the amount of worker threads used to run these tests in parallel to half of what is currently available (8) on the Windows pool.
# Using all available cores seems to occasionally bog down our machines and cause parallel test execution to slow down dramatically.
- template: run-nunit-tests.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static string GetLinkedPath (ProjectBuilder builder, bool isRelease, stri
}

[Test]
[Category ("SmokeTests")]
public void BuildReleaseArm64 ([Values (false, true)] bool forms)
{
var proj = forms ?
Expand All @@ -81,6 +82,16 @@ public void BuildReleaseArm64 ([Values (false, true)] bool forms)
proj.AddDotNetCompatPackages ();
}

byte [] apkDescData;
var flavor = (forms ? "XForms" : "Simple") + (Builder.UseDotNet ? "DotNet" : "Legacy");
var apkDescFilename = $"BuildReleaseArm64{flavor}.apkdesc";
var apkDescReference = "reference.apkdesc";
using (var stream = typeof (XamarinAndroidApplicationProject).Assembly.GetManifestResourceStream ($"Xamarin.ProjectTools.Resources.Base.{apkDescFilename}")) {
apkDescData = new byte [stream.Length];
stream.Read (apkDescData, 0, (int) stream.Length);
}
proj.OtherBuildItems.Add (new BuildItem ("ApkDescFile", apkDescReference) { BinaryContent = () => apkDescData });

// use BuildHelper.CreateApkBuilder so that the test directory is not removed in tearup
using (var b = BuildHelper.CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Expand All @@ -90,6 +101,14 @@ public void BuildReleaseArm64 ([Values (false, true)] bool forms)
? GetLinkedPath (b, true, depsFilename)
: Path.Combine (proj.Root, b.ProjectDirectory, depsFilename);
FileAssert.Exists (depsFile);

const int ApkSizeThreshold = 50 * 1024;
const int AssemblySizeThreshold = 50 * 1024;
var apkFile = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, proj.PackageName + "-Signed.apk");
var apkDescPath = Path.Combine (Root, b.ProjectDirectory, apkDescFilename);
var apkDescReferencePath = Path.Combine (Root, b.ProjectDirectory, apkDescReference);
var (code, stdOut, stdErr) = RunApkDiffCommand ($"-s --save-description-2={apkDescPath} --test-apk-size-regression={ApkSizeThreshold} --test-assembly-size-regression={AssemblySizeThreshold} {apkDescReferencePath} {apkFile}");
Assert.IsTrue (code == 0, $"apkdiff regression test failed with exit code: {code}\nstdOut: {stdOut}\nstdErr: {stdErr}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,28 @@ protected static string RunAdbCommand (string command, bool ignoreErrors = true,
return RunProcess (adb, $"{adbTarget} {command}");
}

protected static (int code, string stdOutput, string stdError) RunApkDiffCommand (string args)
{
string ext = Environment.OSVersion.Platform != PlatformID.Unix ? ".exe" : "";

try {
return RunProcessWithExitCode ("apkdiff" + ext, args);
} catch (System.ComponentModel.Win32Exception) {
// apkdiff's location might not be in the $PATH, try known location
var profileDir = Environment.GetEnvironmentVariable ("USERPROFILE");

return RunProcessWithExitCode (Path.Combine (profileDir, ".dotnet", "tools", "apkdiff" + ext), args);
}
}

protected static string RunProcess (string exe, string args)
{
var (_, stdOutput, stdError) = RunProcessWithExitCode (exe, args);

return stdOutput + stdError;
}

protected static (int code, string stdOutput, string stdError) RunProcessWithExitCode (string exe, string args)
{
TestContext.Out.WriteLine ($"{nameof(RunProcess)}: {exe} {args}");
var info = new ProcessStartInfo (exe, args) {
Expand Down Expand Up @@ -266,12 +287,12 @@ protected static string RunProcess (string exe, string args)
if (!proc.WaitForExit ((int)TimeSpan.FromSeconds (30).TotalMilliseconds)) {
proc.Kill ();
TestContext.Out.WriteLine ($"{nameof (RunProcess)} timed out: {exe} {args}");
return null; //Don't try to read stdout/stderr
return (-1, null, null); //Don't try to read stdout/stderr
}

proc.WaitForExit ();

return standardOutput.ToString ().Trim () + errorOutput.ToString ().Trim ();
return (proc.ExitCode, standardOutput.ToString ().Trim (), errorOutput.ToString ().Trim ());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"Comment": null,
"Entries": {
"AndroidManifest.xml": {
"Size": 2584
},
"res/drawable-mdpi-v4/icon.png": {
"Size": 2199
},
"res/drawable-hdpi-v4/icon.png": {
"Size": 4791
},
"res/drawable-xhdpi-v4/icon.png": {
"Size": 7462
},
"res/drawable-xxhdpi-v4/icon.png": {
"Size": 13092
},
"res/drawable-xxxhdpi-v4/icon.png": {
"Size": 20118
},
"res/layout/main.xml": {
"Size": 544
},
"resources.arsc": {
"Size": 1724
},
"classes.dex": {
"Size": 316988
},
"assemblies/UnnamedProject.dll": {
"Size": 2955
},
"assemblies/System.Collections.Concurrent.dll": {
"Size": 9341
},
"assemblies/System.Collections.dll": {
"Size": 4490
},
"assemblies/System.Console.dll": {
"Size": 6209
},
"assemblies/System.Linq.Expressions.dll": {
"Size": 115171
},
"assemblies/System.Linq.dll": {
"Size": 16987
},
"assemblies/System.ObjectModel.dll": {
"Size": 3372
},
"assemblies/System.Private.CoreLib.dll": {
"Size": 527251
},
"assemblies/Java.Interop.dll": {
"Size": 67979
},
"assemblies/Mono.Android.dll": {
"Size": 108095
},
"lib/arm64-v8a/libxamarin-app.so": {
"Size": 11904
},
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
"Size": 776216
},
"lib/arm64-v8a/libSystem.Native.so": {
"Size": 75872
},
"lib/arm64-v8a/libSystem.Security.Cryptography.Native.OpenSsl.so": {
"Size": 100464
},
"lib/arm64-v8a/libmonosgen-2.0.so": {
"Size": 18570656
},
"lib/arm64-v8a/libmonodroid.so": {
"Size": 254616
},
"lib/arm64-v8a/libxa-internal-api.so": {
"Size": 66544
},
"lib/arm64-v8a/libxamarin-debug-app-helper.so": {
"Size": 191408
},
"META-INF/ANDROIDD.SF": {
"Size": 2948
},
"META-INF/ANDROIDD.RSA": {
"Size": 1213
},
"META-INF/MANIFEST.MF": {
"Size": 2821
}
},
"PackageSize": 8050955
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Comment": null,
"Entries": {
"AndroidManifest.xml": {
"Size": 2584
},
"res/drawable-mdpi-v4/icon.png": {
"Size": 2199
},
"res/drawable-hdpi-v4/icon.png": {
"Size": 4762
},
"res/drawable-xhdpi-v4/icon.png": {
"Size": 7462
},
"res/drawable-xxhdpi-v4/icon.png": {
"Size": 13092
},
"res/drawable-xxxhdpi-v4/icon.png": {
"Size": 20118
},
"res/layout/main.xml": {
"Size": 544
},
"resources.arsc": {
"Size": 1724
},
"classes.dex": {
"Size": 316956
},
"assemblies/UnnamedProject.dll": {
"Size": 2861
},
"assemblies/Java.Interop.dll": {
"Size": 75724
},
"assemblies/Mono.Android.dll": {
"Size": 264062
},
"assemblies/mscorlib.dll": {
"Size": 779345
},
"assemblies/System.Core.dll": {
"Size": 149498
},
"assemblies/System.dll": {
"Size": 12986
},
"lib/arm64-v8a/libxamarin-app.so": {
"Size": 19824
},
"lib/arm64-v8a/libmonodroid.so": {
"Size": 254616
},
"lib/arm64-v8a/libxa-internal-api.so": {
"Size": 66544
},
"lib/arm64-v8a/libmono-btls-shared.so": {
"Size": 2160056
},
"lib/arm64-v8a/libmonosgen-2.0.so": {
"Size": 6823104
},
"lib/arm64-v8a/libmono-native.so": {
"Size": 1150064
},
"META-INF/ANDROIDD.SF": {
"Size": 2225
},
"META-INF/ANDROIDD.RSA": {
"Size": 1213
},
"META-INF/MANIFEST.MF": {
"Size": 2098
}
},
"PackageSize": 5142228
}
Loading