Skip to content

Commit 3daf433

Browse files
committed
Tweak some tests to run with the unified runtime
1 parent a9b5e3b commit 3daf433

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public void BuildReleaseArm64 ([Values (false, true)] bool forms)
156156
proj.SetProperty ("LinkerDumpDependencies", "True");
157157
proj.SetProperty ("AndroidUseAssemblyStore", "False");
158158

159+
// Make sure that we never use native runtime linking mode in this test. It would generate false negatives in the apkdesc checks.
160+
proj.SetProperty ("_AndroidEnableNativeRuntimeLinking", "False");
161+
159162
var flavor = (forms ? "XForms" : "Simple") + "DotNet";
160163
var apkDescFilename = $"BuildReleaseArm64{flavor}.apkdesc";
161164
var apkDescReference = "reference.apkdesc";
@@ -319,7 +322,7 @@ public void XA1037PropertyDeprecatedWarning (string property, string value, bool
319322
XamarinAndroidProject proj = isBindingProject ? new XamarinAndroidBindingProject () : new XamarinAndroidApplicationProject ();
320323
proj.IsRelease = isRelease;
321324
proj.SetProperty (property, value);
322-
325+
323326
using (ProjectBuilder b = isBindingProject ? CreateDllBuilder (Path.Combine ("temp", TestName)) : CreateApkBuilder (Path.Combine ("temp", TestName))) {
324327
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
325328
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, $"The '{property}' MSBuild property is deprecated and will be removed"),

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class EnvironmentContentTests : BaseTest
1515
{
1616
[Test]
1717
[NonParallelizable]
18-
public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode)
18+
public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode, [Values(false, true)] bool useNativeRuntimeLinkingMode)
1919
{
2020
const string supportedAbis = "armeabi-v7a;x86";
2121

@@ -38,6 +38,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline
3838
string linkSkip = "FormsViewGroup";
3939
app.SetProperty ("AndroidLinkSkip", linkSkip);
4040
app.SetProperty ("_AndroidSequencePointsMode", sequencePointsMode);
41+
app.SetProperty ("_AndroidEnableNativeRuntimeLinking", useNativeRuntimeLinkingMode.ToString ());
4142
app.SetAndroidSupportedAbis (supportedAbis);
4243
using (var libb = CreateDllBuilder (Path.Combine ("temp", TestName, lib.ProjectName)))
4344
using (var appb = CreateApkBuilder (Path.Combine ("temp", TestName, app.ProjectName))) {
@@ -57,7 +58,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline
5758
if (!String.IsNullOrEmpty (sequencePointsMode))
5859
Assert.IsTrue (monoDebugVar.IndexOf ("gen-compact-seq-points", StringComparison.Ordinal) >= 0, "The values from Mono.env should have been merged into environment");
5960

60-
EnvironmentHelper.AssertValidEnvironmentSharedLibrary (intermediateOutputDir, AndroidSdkPath, AndroidNdkPath, supportedAbis);
61+
EnvironmentHelper.AssertValidEnvironmentSharedLibrary (intermediateOutputDir, AndroidSdkPath, AndroidNdkPath, supportedAbis, useNativeRuntimeLinkingMode);
6162

6263
var assemblyDir = Path.Combine (Root, appb.ProjectDirectory, app.IntermediateOutputPath, "android", "assets");
6364
var rp = new ReaderParameters { ReadSymbols = false };
@@ -75,7 +76,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline
7576
}
7677

7778
[Test]
78-
public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode)
79+
public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode, [Values(false, true)] bool useNativeRuntimeLinkingMode)
7980
{
8081
const string supportedAbis = "armeabi-v7a;x86";
8182

@@ -101,7 +102,7 @@ public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline"
101102
Assert.AreEqual ("gen-compact-seq-points", monoDebugVar, "environment should contain MONO_DEBUG=gen-compact-seq-points");
102103
}
103104

104-
EnvironmentHelper.AssertValidEnvironmentSharedLibrary (intermediateOutputDir, AndroidSdkPath, AndroidNdkPath, supportedAbis);
105+
EnvironmentHelper.AssertValidEnvironmentSharedLibrary (intermediateOutputDir, AndroidSdkPath, AndroidNdkPath, supportedAbis, useNativeRuntimeLinkingMode);
105106
}
106107
}
107108

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public static List<EnvironmentFile> GatherEnvironmentFiles (string outputDirecto
456456
return environmentFiles;
457457
}
458458

459-
public static void AssertValidEnvironmentSharedLibrary (string outputDirectoryRoot, string sdkDirectory, string ndkDirectory, string supportedAbis)
459+
public static void AssertValidEnvironmentSharedLibrary (string outputDirectoryRoot, string sdkDirectory, string ndkDirectory, string supportedAbis, bool nativeRuntimeLinkingModeEnabled)
460460
{
461461
NdkTools ndk = NdkTools.Create (ndkDirectory);
462462
MonoAndroidHelper.AndroidSdk = new AndroidSdkInfo ((arg1, arg2) => {}, sdkDirectory, ndkDirectory, AndroidSdkResolver.GetJavaSdkPath ());
@@ -487,15 +487,25 @@ public static void AssertValidEnvironmentSharedLibrary (string outputDirectoryRo
487487
throw new Exception ("Unsupported Android target architecture ABI: " + abi);
488488
}
489489

490-
string envSharedLibrary = Path.Combine (outputDirectoryRoot, "app_shared_libraries", abi, "libxamarin-app.so");
491-
Assert.IsTrue (File.Exists (envSharedLibrary), $"Application environment SharedLibrary '{envSharedLibrary}' must exist");
490+
if (!nativeRuntimeLinkingModeEnabled) {
491+
string envSharedLibrary = Path.Combine (outputDirectoryRoot, "app_shared_libraries", abi, "libxamarin-app.so");
492+
Assert.IsTrue (File.Exists (envSharedLibrary), $"Application environment SharedLibrary '{envSharedLibrary}' must exist");
492493

493-
// API level doesn't matter in this case
494-
var readelf = ndk.GetToolPath ("readelf", arch, 0);
495-
if (!File.Exists (readelf)) {
496-
readelf = ndk.GetToolPath ("llvm-readelf", arch, 0);
494+
// API level doesn't matter in this case
495+
var readelf = ndk.GetToolPath ("readelf", arch, 0);
496+
if (!File.Exists (readelf)) {
497+
readelf = ndk.GetToolPath ("llvm-readelf", arch, 0);
498+
}
499+
AssertSharedLibraryHasRequiredSymbols (envSharedLibrary, readelf);
500+
} else {
501+
string runtimeLibrary = Path.Combine (outputDirectoryRoot, "app_shared_libraries", abi, "libmonodroid-unified.so");
502+
Assert.IsTrue (File.Exists (runtimeLibrary), $"Application dynamically linked (unified) runtime library '{runtimeLibrary}' must exist");
503+
504+
runtimeLibrary = Path.Combine (outputDirectoryRoot, "app_shared_libraries", abi, "libmonodroid-unified.dbg.so");
505+
Assert.IsTrue (File.Exists (runtimeLibrary), $"Application dynamically linked (unified) runtime library '{runtimeLibrary}' debug symbols must exist");
506+
507+
// We can't verify fields in this mode, the symbols aren't exported.
497508
}
498-
AssertSharedLibraryHasRequiredSymbols (envSharedLibrary, readelf);
499509
}
500510
}
501511

tests/MSBuildDeviceIntegration/Tests/BundleToolTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ string [] ListArchiveContents (string archive, bool usesAssembliesBlob)
136136
}
137137

138138
[Test]
139-
public void BaseZip ()
139+
public void BaseZip ([Values(false, true)] bool useNativeRuntimeLinkingMode)
140140
{
141141
var baseZip = Path.Combine (intermediate, "android", "bin", "base.zip");
142142
var contents = ListArchiveContents (baseZip, usesAssemblyBlobs);
@@ -177,23 +177,27 @@ public void BaseZip ()
177177
}
178178

179179
expectedFiles.Add ($"lib/{abi}/libmonodroid.so");
180-
expectedFiles.Add ($"lib/{abi}/libmonosgen-2.0.so");
181-
expectedFiles.Add ($"lib/{abi}/libxamarin-app.so");
180+
if (!useNativeRuntimeLinkingMode) {
181+
// None of these exist if dynamic native runtime linking is enabled
182+
expectedFiles.Add ($"lib/{abi}/libmonosgen-2.0.so");
183+
expectedFiles.Add ($"lib/{abi}/libxamarin-app.so");
184+
expectedFiles.Add ($"lib/{abi}/libSystem.IO.Compression.Native.so");
185+
expectedFiles.Add ($"lib/{abi}/libSystem.Native.so");
186+
}
187+
182188
if (usesAssemblyBlobs) {
183189
expectedFiles.Add ($"{blobEntryPrefix}{abi}/lib_System.Private.CoreLib.dll.so");
184190
} else {
185191
expectedFiles.Add ($"lib/{abi}/lib_System.Private.CoreLib.dll.so");
186192
}
187-
expectedFiles.Add ($"lib/{abi}/libSystem.IO.Compression.Native.so");
188-
expectedFiles.Add ($"lib/{abi}/libSystem.Native.so");
189193
}
190194
foreach (var expected in expectedFiles) {
191195
CollectionAssert.Contains (contents, expected, $"`{baseZip}` did not contain `{expected}`");
192196
}
193197
}
194198

195199
[Test]
196-
public void AppBundle ()
200+
public void AppBundle ([Values(false, true)] bool useNativeRuntimeLinkingMode)
197201
{
198202
var aab = Path.Combine (intermediate, "android", "bin", $"{app.PackageName}.aab");
199203
FileAssert.Exists (aab);
@@ -237,15 +241,20 @@ public void AppBundle ()
237241
}
238242

239243
expectedFiles.Add ($"base/lib/{abi}/libmonodroid.so");
240-
expectedFiles.Add ($"base/lib/{abi}/libmonosgen-2.0.so");
241-
expectedFiles.Add ($"base/lib/{abi}/libxamarin-app.so");
244+
245+
if (!useNativeRuntimeLinkingMode) {
246+
// None of these exist if dynamic native runtime linking is enabled
247+
expectedFiles.Add ($"base/lib/{abi}/libmonosgen-2.0.so");
248+
expectedFiles.Add ($"base/lib/{abi}/libxamarin-app.so");
249+
expectedFiles.Add ($"base/lib/{abi}/libSystem.IO.Compression.Native.so");
250+
expectedFiles.Add ($"base/lib/{abi}/libSystem.Native.so");
251+
}
252+
242253
if (usesAssemblyBlobs) {
243254
expectedFiles.Add ($"{blobEntryPrefix}{abi}/lib_System.Private.CoreLib.dll.so");
244255
} else {
245256
expectedFiles.Add ($"base/lib/{abi}/lib_System.Private.CoreLib.dll.so");
246257
}
247-
expectedFiles.Add ($"base/lib/{abi}/libSystem.IO.Compression.Native.so");
248-
expectedFiles.Add ($"base/lib/{abi}/libSystem.Native.so");
249258
}
250259
foreach (var expected in expectedFiles) {
251260
CollectionAssert.Contains (contents, expected, $"`{aab}` did not contain `{expected}`");

0 commit comments

Comments
 (0)