Skip to content

Commit 8cd4e9f

Browse files
committed
[WIP] Another set of test fixes
1 parent 57fac3b commit 8cd4e9f

File tree

4 files changed

+108
-22
lines changed

4 files changed

+108
-22
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,23 @@ public void WarnAboutAppDomains ([Values (true, false)] bool isRelease)
193193
}
194194

195195
[Test]
196-
public void RemoveDesigner ()
196+
public void RemoveDesigner ([Values (true, false)] bool usesAssemblyBlobs)
197197
{
198198
var proj = new XamarinAndroidApplicationProject {
199199
IsRelease = true,
200200
};
201201
proj.SetProperty ("AndroidEnableAssemblyCompression", "False");
202202
proj.SetProperty ("AndroidLinkResources", "True");
203+
proj.SetProperty ("AndroidUseAssembliesBlob", usesAssemblyBlobs.ToString ());
203204
string assemblyName = proj.ProjectName;
204205
using (var b = CreateApkBuilder ()) {
205206
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
206207
var apk = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk");
207208
FileAssert.Exists (apk);
209+
var helper = new ArchiveAssemblyHelper (apk, usesAssemblyBlobs);
210+
Assert.IsTrue (helper.Exists ($"assemblies/{assemblyName}.dll"), $"{assemblyName}.dll should exist in apk!");
211+
// TODO: helper must be able to extract assembly from the blob
208212
using (var zip = ZipHelper.OpenZip (apk)) {
209-
Assert.IsTrue (zip.ContainsEntry ($"assemblies/{assemblyName}.dll"), $"{assemblyName}.dll should exist in apk!");
210213
var entry = zip.ReadEntry ($"assemblies/{assemblyName}.dll");
211214
using (var stream = new MemoryStream ()) {
212215
entry.Extract (stream);

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Xamarin.Android.Build.Tests
1111
{
12-
class ArchiveAssemblyHelper
12+
public class ArchiveAssemblyHelper
1313
{
1414
public const string DefaultBlobEntryPrefix = "{blob}";
1515

@@ -20,11 +20,20 @@ class ArchiveAssemblyHelper
2020
".mdb",
2121
};
2222

23+
static readonly Dictionary<string, string> ArchToAbi = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase) {
24+
{"x86", "x86"},
25+
{"x86_64", "x86_64"},
26+
{"armeabi_v7a", "armeabi-v7a"},
27+
{"arm64_v8a", "arm64-v8a"},
28+
};
29+
2330
readonly string archivePath;
2431
readonly string assembliesRootDir;
2532
bool useAssemblyBlobs;
2633
List<string> archiveContents;
2734

35+
public string ArchivePath => archivePath;
36+
2837
public ArchiveAssemblyHelper (string archivePath, bool useAssemblyBlobs)
2938
{
3039
if (String.IsNullOrEmpty (archivePath)) {
@@ -70,26 +79,35 @@ public List<string> ListArchiveContents (string blobEntryPrefix = DefaultBlobEnt
7079
}
7180

7281
var explorer = new BlobExplorer (archivePath);
73-
foreach (var kvp in explorer.AssembliesByName) {
74-
string name = kvp.Key;
75-
BlobAssembly asm = kvp.Value;
82+
foreach (var asm in explorer.Assemblies) {
83+
string prefix = blobEntryPrefix;
7684

77-
entries.Add ($"{blobEntryPrefix}{name}.dll");
85+
if (!String.IsNullOrEmpty (asm.Blob.Arch)) {
86+
string arch = ArchToAbi[asm.Blob.Arch];
87+
prefix = $"{prefix}{arch}/";
88+
}
89+
90+
entries.Add ($"{prefix}{asm.Name}.dll");
7891
if (asm.DebugDataOffset > 0) {
79-
entries.Add ($"{blobEntryPrefix}{name}.pdb");
92+
entries.Add ($"{prefix}{asm.Name}.pdb");
8093
}
8194

8295
if (asm.ConfigDataOffset > 0) {
83-
entries.Add ($"{blobEntryPrefix}{name}.dll.config");
96+
entries.Add ($"{prefix}{asm.Name}.dll.config");
8497
}
8598
}
8699

100+
Console.WriteLine ("Archive entries with synthetised assembly blob entries:");
101+
foreach (string e in entries) {
102+
Console.WriteLine ($" {e}");
103+
}
104+
87105
return entries;
88106
}
89107

90-
public bool Exists (string entryPath)
108+
public bool Exists (string entryPath, bool forceRefresh = false)
91109
{
92-
List<string> contents = ListArchiveContents (assembliesRootDir);
110+
List<string> contents = ListArchiveContents (assembliesRootDir, forceRefresh);
93111
if (contents.Count == 0) {
94112
return false;
95113
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,24 @@ public static void AssertContainsEntry (this ZipArchive zip, string zipPath, str
6060
Assert.IsTrue (zip.ContainsEntry (archivePath), $"{zipPath} should contain {archivePath}");
6161
}
6262

63+
[DebuggerHidden]
64+
public static void AssertContainsEntry (this ArchiveAssemblyHelper helper, string archivePath)
65+
{
66+
Assert.IsTrue (helper.Exists (archivePath), $"{helper.ArchivePath} should contain {archivePath}");
67+
}
68+
6369
[DebuggerHidden]
6470
public static void AssertDoesNotContainEntry (this ZipArchive zip, string zipPath, string archivePath)
6571
{
6672
Assert.IsFalse (zip.ContainsEntry (archivePath), $"{zipPath} should *not* contain {archivePath}");
6773
}
6874

75+
[DebuggerHidden]
76+
public static void AssertDoesNotContainEntry (this ArchiveAssemblyHelper helper, string archivePath)
77+
{
78+
Assert.IsFalse (helper.Exists (archivePath), $"{helper.ArchivePath} should *not* contain {archivePath}");
79+
}
80+
6981
[DebuggerHidden]
7082
public static void AssertContainsEntry (this ZipArchive zip, string zipPath, string archivePath, bool shouldContainEntry)
7183
{
@@ -76,6 +88,16 @@ public static void AssertContainsEntry (this ZipArchive zip, string zipPath, str
7688
}
7789
}
7890

91+
[DebuggerHidden]
92+
public static void AssertContainsEntry (this ArchiveAssemblyHelper helper, string archivePath, bool shouldContainEntry)
93+
{
94+
if (shouldContainEntry) {
95+
helper.AssertContainsEntry (archivePath);
96+
} else {
97+
helper.AssertDoesNotContainEntry (archivePath);
98+
}
99+
}
100+
79101
[DebuggerHidden]
80102
public static void AssertEntryContents (this ZipArchive zip, string zipPath, string archivePath, string contents)
81103
{

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,63 +398,104 @@ public void DotNetBuildBinding ()
398398
/* runtimeIdentifiers */ "android-arm",
399399
/* isRelease */ false,
400400
/* aot */ false,
401+
/* usesAssemblyBlobs */ false,
402+
},
403+
new object [] {
404+
/* runtimeIdentifiers */ "android-arm",
405+
/* isRelease */ false,
406+
/* aot */ false,
407+
/* usesAssemblyBlobs */ true,
401408
},
402409
new object [] {
403410
/* runtimeIdentifiers */ "android-arm64",
404411
/* isRelease */ false,
405412
/* aot */ false,
413+
/* usesAssemblyBlobs */ false,
406414
},
407415
new object [] {
408416
/* runtimeIdentifiers */ "android-x86",
409417
/* isRelease */ false,
410418
/* aot */ false,
419+
/* usesAssemblyBlobs */ false,
411420
},
412421
new object [] {
413422
/* runtimeIdentifiers */ "android-x64",
414423
/* isRelease */ false,
415424
/* aot */ false,
425+
/* usesAssemblyBlobs */ false,
426+
},
427+
new object [] {
428+
/* runtimeIdentifiers */ "android-arm",
429+
/* isRelease */ true,
430+
/* aot */ false,
431+
/* usesAssemblyBlobs */ false,
416432
},
417433
new object [] {
418434
/* runtimeIdentifiers */ "android-arm",
419435
/* isRelease */ true,
420436
/* aot */ false,
437+
/* usesAssemblyBlobs */ true,
421438
},
422439
new object [] {
423440
/* runtimeIdentifiers */ "android-arm",
424441
/* isRelease */ true,
425442
/* aot */ true,
443+
/* usesAssemblyBlobs */ false,
444+
},
445+
new object [] {
446+
/* runtimeIdentifiers */ "android-arm",
447+
/* isRelease */ true,
448+
/* aot */ true,
449+
/* usesAssemblyBlobs */ true,
426450
},
427451
new object [] {
428452
/* runtimeIdentifiers */ "android-arm64",
429453
/* isRelease */ true,
430454
/* aot */ false,
455+
/* usesAssemblyBlobs */ false,
431456
},
432457
new object [] {
433458
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
434459
/* isRelease */ false,
435460
/* aot */ false,
461+
/* usesAssemblyBlobs */ false,
462+
},
463+
new object [] {
464+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
465+
/* isRelease */ false,
466+
/* aot */ false,
467+
/* usesAssemblyBlobs */ true,
436468
},
437469
new object [] {
438470
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86",
439471
/* isRelease */ true,
440472
/* aot */ false,
473+
/* usesAssemblyBlobs */ false,
441474
},
442475
new object [] {
443476
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
444477
/* isRelease */ true,
445478
/* aot */ false,
479+
/* usesAssemblyBlobs */ false,
480+
},
481+
new object [] {
482+
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
483+
/* isRelease */ true,
484+
/* aot */ false,
485+
/* usesAssemblyBlobs */ true,
446486
},
447487
new object [] {
448488
/* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64",
449489
/* isRelease */ true,
450490
/* aot */ true,
491+
/* usesAssemblyBlobs */ false,
451492
},
452493
};
453494

454495
[Test]
455496
[Category ("SmokeTests")]
456497
[TestCaseSource (nameof (DotNetBuildSource))]
457-
public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
498+
public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot, bool usesAssemblyBlobs)
458499
{
459500
var proj = new XASdkProject {
460501
IsRelease = isRelease,
@@ -489,6 +530,7 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
489530
}
490531
};
491532
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": AndroidX.AppCompat.App.AppCompatActivity");
533+
proj.SetProperty ("AndroidUseAssembliesBlob", usesAssemblyBlobs.ToString ());
492534
if (aot) {
493535
proj.SetProperty ("RunAOTCompilation", "true");
494536
}
@@ -577,21 +619,22 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
577619
bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease);
578620
var apkPath = Path.Combine (outputPath, $"{proj.PackageName}-Signed.apk");
579621
FileAssert.Exists (apkPath);
580-
using (var apk = ZipHelper.OpenZip (apkPath)) {
581-
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies);
582-
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease);
583-
apk.AssertContainsEntry (apkPath, $"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies);
584-
apk.AssertContainsEntry (apkPath, $"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies);
622+
var helper = new ArchiveAssemblyHelper (apkPath, usesAssemblyBlobs);
623+
helper.AssertContainsEntry ($"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies);
624+
helper.AssertContainsEntry ($"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease);
625+
helper.AssertContainsEntry ($"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies);
626+
helper.AssertContainsEntry ($"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies);
627+
// using (var apk = ZipHelper.OpenZip (apkPath)) {
585628
foreach (var abi in rids.Select (AndroidRidAbiHelper.RuntimeIdentifierToAbi)) {
586-
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonodroid.so");
587-
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonosgen-2.0.so");
629+
helper.AssertContainsEntry ($"lib/{abi}/libmonodroid.so");
630+
helper.AssertContainsEntry ($"lib/{abi}/libmonosgen-2.0.so");
588631
if (rids.Length > 1) {
589-
apk.AssertContainsEntry (apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
632+
helper.AssertContainsEntry ($"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
590633
} else {
591-
apk.AssertContainsEntry (apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
634+
helper.AssertContainsEntry ("assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
592635
}
593636
}
594-
}
637+
// }
595638
}
596639

597640

0 commit comments

Comments
 (0)