-
Notifications
You must be signed in to change notification settings - Fork 577
[tests] Verbose apkdiff output for BuildReleaseArm64 regressions #11759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
| using System.Xml; | ||
| using System.Xml.Linq; | ||
|
|
@@ -313,8 +314,78 @@ public void BuildReleaseArm64 ([Values] bool forms, [Values (AndroidRuntime.Core | |
| 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}", Path.Combine (Root, b.ProjectDirectory, "apkdiff.log")); | ||
| Assert.IsTrue (code == 0, $"apkdiff regression test failed with exit code: {code}. See test attachments."); | ||
| if (code != 0) { | ||
| if (File.Exists (apkDescPath)) { | ||
| TestContext.AddTestAttachment (apkDescPath, apkDescFilename); | ||
| } | ||
|
|
||
| var message = new StringBuilder (); | ||
| message.AppendLine ($"apkdiff regression test failed with exit code: {code}."); | ||
| message.AppendLine (); | ||
| message.AppendLine ("== apkdiff output =="); | ||
| if (!stdOut.IsNullOrEmpty ()) { | ||
| message.AppendLine (stdOut); | ||
| } | ||
| if (!stdErr.IsNullOrEmpty ()) { | ||
| message.AppendLine (stdErr); | ||
| } | ||
| message.AppendLine (); | ||
| message.AppendLine ("== .apkdesc diff (reference -> current) =="); | ||
| message.AppendLine (GetApkDescDiff (apkDescReferencePath, apkDescPath)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Rule: Diagnostics must degrade gracefully, not throw |
||
| message.AppendLine (); | ||
| message.AppendLine ($"If this change is intended, update the reference '{apkDescFilename}' with the current '.apkdesc' attached to this test (or run build-tools/scripts/UpdateApkSizeReference.sh)."); | ||
| Assert.Fail (message.ToString ()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static string GetApkDescDiff (string referencePath, string currentPath) | ||
| { | ||
| if (!File.Exists (referencePath)) { | ||
| return $"(reference apkdesc not found: {referencePath})"; | ||
| } | ||
| if (!File.Exists (currentPath)) { | ||
| return $"(current apkdesc not found: {currentPath})"; | ||
| } | ||
|
|
||
| var reference = ReadApkDescEntries (referencePath); | ||
| var current = ReadApkDescEntries (currentPath); | ||
|
|
||
| var sb = new StringBuilder (); | ||
| foreach (var key in reference.Keys.Union (current.Keys).OrderBy (k => k, StringComparer.Ordinal)) { | ||
| bool inReference = reference.TryGetValue (key, out long oldSize); | ||
| bool inCurrent = current.TryGetValue (key, out long newSize); | ||
| if (inReference && inCurrent) { | ||
| if (oldSize != newSize) { | ||
| sb.AppendLine ($" {key}"); | ||
| sb.AppendLine ($"- \"Size\": {oldSize}"); | ||
| sb.AppendLine ($"+ \"Size\": {newSize} ({(newSize - oldSize):+#,0;-#,0;0} bytes)"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 💡 Testing — The byte-delta format Rule: Deterministic, locale-independent test output |
||
| } | ||
| } else if (inReference) { | ||
| sb.AppendLine ($"- {key} (\"Size\": {oldSize}) [removed]"); | ||
| } else { | ||
| sb.AppendLine ($"+ {key} (\"Size\": {newSize}) [added]"); | ||
| } | ||
| } | ||
|
|
||
| if (sb.Length == 0) { | ||
| return "(no per-entry size differences)"; | ||
| } | ||
| return sb.ToString (); | ||
| } | ||
|
|
||
| static Dictionary<string, long> ReadApkDescEntries (string path) | ||
| { | ||
| var result = new Dictionary<string, long> (StringComparer.Ordinal); | ||
| using var doc = JsonDocument.Parse (File.ReadAllText (path)); | ||
| if (doc.RootElement.TryGetProperty ("Entries", out var entries)) { | ||
| foreach (var entry in entries.EnumerateObject ()) { | ||
| if (entry.Value.TryGetProperty ("Size", out var size)) { | ||
| result [entry.Name] = size.GetInt64 (); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| static IEnumerable<object[]> Get_BuildHasNoWarningsData () | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.