Skip to content

Commit

Permalink
[tests] Add apkdiff output to test attachment file (#9560)
Browse files Browse the repository at this point in the history
We've been seeing some strange output in the Azure Pipelines test output
pane when apkdiff fails. This change should hopefully clean that up and
instead upload an apkdiff.log file with the tools output when a related
test fails.

An issue with Mono.Android.NET_Tests Debug apk uploading has also been
fixed.
  • Loading branch information
pjcollins authored Nov 27, 2024
1 parent 406e43b commit b870836
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ extends:
testName: Mono.Android.NET_Tests-Debug
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
testResultsFiles: TestResult-Mono.Android.NET_Tests-Debug.xml
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.apk
artifactSource: bin/TestDebug/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.apk
artifactFolder: $(DotNetTargetFramework)-Debug

- template: /build-tools/automation/yaml-templates/apk-instrumentation.yaml@self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public void BuildReleaseArm64 ([Values (false, true)] bool forms)
var apkFile = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, proj.PackageName + "-Signed.apk");
var apkDescPath = Path.Combine (Root, apkDescFilename);
var apkDescReferencePath = Path.Combine (Root, b.ProjectDirectory, apkDescReference);
var (code, stdOut, stdErr) = RunApkDiffCommand ($"-s --save-description-2={apkDescPath} --descrease-is-regression {regressionCheckArgs} {apkDescReferencePath} {apkFile}");
Assert.IsTrue (code == 0, $"apkdiff regression test failed with exit code: {code}\ncontext: https://github.com/xamarin/xamarin-android/blob/main/Documentation/project-docs/ApkSizeRegressionChecks.md\nstdOut: {stdOut}\nstdErr: {stdErr}");
var (code, stdOut, stdErr) = RunApkDiffCommand ($"-s --save-description-2={apkDescPath} --descrease-is-regression {regressionCheckArgs} {apkDescReferencePath} {apkFile}", Path.Combine (Root, b.ProjectDirectory, "apkdiff.log"));
Assert.IsTrue (code == 0, $"apkdiff regression test failed with exit code: {code}. See test attachments.");
}
}

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

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

try {
return RunProcessWithExitCode ("apkdiff" + ext, args);
result = RunProcessWithExitCode ("apkdiff" + ext, args);
} catch (System.ComponentModel.Win32Exception) {
// apkdiff's location might not be in the $PATH, try known locations
var profileDir = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
Expand All @@ -117,8 +118,13 @@ protected static (int code, string stdOutput, string stdError) RunApkDiffCommand
apkdiffPath = Path.Combine (agentToolsDir, "apkdiff" + ext);
}
}
return RunProcessWithExitCode (apkdiffPath, args);
result = RunProcessWithExitCode (apkdiffPath, args);
}
var logContent = $"apkdiff exited with code: {result.code}" +
$"\ncontext: https://github.com/xamarin/xamarin-android/blob/main/Documentation/project-docs/ApkSizeRegressionChecks.md" +
$"\nstdOut:\n{result.stdOutput}\nstdErr:\n{result.stdError}";
File.WriteAllText (logFilePath, logContent);
return result;
}

protected static string RunProcess (string exe, string args, int timeoutInSeconds = 30)
Expand Down

0 comments on commit b870836

Please sign in to comment.